<s> from couchbase . _libcouchbase import ( <EOL> Result , <EOL> ValueResult , <EOL> OperationResult , <EOL> HttpResult , <EOL> MultiResult , <EOL> ObserveInfo , <EOL> AsyncResult ) <EOL> from couchbase . _pyport import long , xrange <EOL> import couchbase . _libcouchbase as C <EOL> import couchbase . exceptions as E <EOL> class SubdocResult ( C . _SDResult ) : <EOL> """<STR_LIT>""" <EOL> def _pycbc_repr_extra ( self ) : <EOL> ret = [ "<STR_LIT>" . format ( repr ( self . _specs ) ) ] <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> ret . append ( '<STR_LIT>' . format ( repr ( self . _results ) ) ) <EOL> return ret <EOL> def __path2index ( self , path ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . __path_cache = { } <EOL> for x in xrange ( len ( self . _specs ) ) : <EOL> spec = self . _specs [ x ] <EOL> self . __path_cache [ spec [ <NUM_LIT:1> ] ] = x <EOL> return self . __path_cache [ path ] <EOL> def _resolve ( self , item ) : <EOL> if isinstance ( item , ( int , long ) ) : <EOL> return self . _results [ item ] <EOL> else : <EOL> return self . _results [ self . __path2index ( item ) ] <EOL> def __getitem__ ( self , item ) : <EOL> rv = self . _resolve ( item ) <EOL> if rv [ <NUM_LIT:0> ] : <EOL> raise E . exc_from_rc ( rv [ <NUM_LIT:0> ] , obj = item ) <EOL> else : <EOL> return rv [ <NUM_LIT:1> ] <EOL> def __iter__ ( self ) : <EOL> for resinfo , specinfo in izip ( self . _results , self . _specs ) : <EOL> err , value , path = resinfo [ <NUM_LIT:0> ] , resinfo [ <NUM_LIT:1> ] , specinfo [ <NUM_LIT:1> ] <EOL> if err : <EOL> raise E . exc_from_rc ( err , obj = path ) <EOL> yield value <EOL> @ property <EOL> def command_count ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . _specs ) <EOL> @ property <EOL> def result_count ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return len ( self . _results ) <EOL> except AttributeError : <EOL> return <NUM_LIT:0> <EOL> def get ( self , path_or_index , default = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _resolve ( path_or_index ) <EOL> except ( KeyError , IndexError ) : <EOL> return <NUM_LIT:0> , default <EOL> def exists ( self , path_or_index ) : <EOL> """<STR_LIT>""" <EOL> result = self . _resolve ( path_or_index ) <EOL> if not result [ <NUM_LIT:0> ] : <EOL> return True <EOL> elif E . SubdocPathNotFoundError . _can_derive ( result [ <NUM_LIT:0> ] ) : <EOL> return False <EOL> else : <EOL> raise E . exc_from_rc ( result [ <NUM_LIT:0> ] ) <EOL> @ property <EOL> def access_ok ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . rc == <NUM_LIT:0> or self . rc == C . LCB_SUBDOC_MULTI_FAILRUE <EOL> @ property <EOL> def value ( self ) : <EOL> raise AttributeError ( "<STR_LIT>" ) </s>
