コード例 #1
0
ファイル: memory.py プロジェクト: AnthonyNystrom/YoGoMee
 def get((index, value)):
     
     if Entity.providedBy(value):
         value = value.id
     
     if self.index_map.has_key(index):
         if self.index_map[index].has_key(value):
             return defer.succeed(self.index_map[index][value].keys())
     return []
コード例 #2
0
ファイル: sabsddb.py プロジェクト: AnthonyNystrom/YoGoMee
 def get((index, value)):
     
     if Entity.providedBy(value):
         value = value.id
     
     if self.idb.has_key(index):
         
         def get_cursor(_):
             return self.idb[index].cursor()
         
         def fetch(cursor):
             
             ids = []
             
             def set_key(_):
                 
                 def complete(result):
                     
                     if result is None:
                         return defer.succeed(False)
                     
                     if result[0] == pickle.dumps(value):
                         ids.append(result[1])
                         return defer.succeed(True)
                     
                     return defer.succeed(False)
             
                 d = cursor.pget_(pickle.dumps(value), db.DB_SET_RANGE)
                 d.addCallback(complete)
                 return d
             
             def fetch_next(result):
                 
                 if not result:
                     return defer.succeed(True)
                 
                 def complete(result):
                     if result is not None:
                         ids.append(result[1])
                         return fetch_next(True)
                     return defer.succeed(True)
                 
                 d = cursor.pget_(pickle.dumps(value), db.DB_NEXT_DUP)
                 d.addCallback(complete)
                 return d
             
             def complete(_):
                 return defer.succeed((cursor, ids))
             
             d = defer.Deferred()
             
             d.addCallback(set_key)
             d.addCallback(fetch_next)
             d.addCallback(complete)
             
             reactor.callLater(0, d.callback, None)
             return d
         
         def close_cursor((cursor, identities)):
             
             def complete(_):
                 return defer.succeed(identities)
             
             d = cursor.close()
             d.addCallback(complete)
             return d
         
         d = defer.Deferred()
         
         d.addCallback(get_cursor)
         d.addCallback(fetch)
         d.addCallback(close_cursor)
         
         reactor.callLater(0, d.callback, None)
         return d
         
     return defer.succeed([])