當前位置: 首頁>>代碼示例>>Python>>正文


Python BTree.iterkeys方法代碼示例

本文整理匯總了Python中durus.btree.BTree.iterkeys方法的典型用法代碼示例。如果您正苦於以下問題:Python BTree.iterkeys方法的具體用法?Python BTree.iterkeys怎麽用?Python BTree.iterkeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在durus.btree.BTree的用法示例。


在下文中一共展示了BTree.iterkeys方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: iter

# 需要導入模塊: from durus.btree import BTree [as 別名]
# 或者: from durus.btree.BTree import iterkeys [as 別名]
 def iter(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(bt) == list(bt.iterkeys())
     assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
     assert list(bt.iterkeys()) == list(bt.keys())
     assert list(bt.itervalues()) == list(bt.values())
     assert list(bt.iteritems()) == list(bt.items())
開發者ID:Schevo,項目名稱:durus,代碼行數:11,代碼來源:utest_btree.py

示例2: test_iter

# 需要導入模塊: from durus.btree import BTree [as 別名]
# 或者: from durus.btree.BTree import iterkeys [as 別名]
 def test_iter(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     if hasattr(bt, 'iterkeys'):
         assert list(bt) == list(bt.iterkeys())
         assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
         assert list(bt.iterkeys()) == list(bt.keys())
         assert list(bt.itervalues()) == list(bt.values())
         assert list(bt.iteritems()) == list(bt.items())
     else:
         assert list(bt) == list(bt.keys())
         assert list(bt.items()) == list(zip(bt, bt.values()))
開發者ID:ctismer,項目名稱:durus,代碼行數:15,代碼來源:test_btree.py

示例3: Document

# 需要導入模塊: from durus.btree import BTree [as 別名]
# 或者: from durus.btree.BTree import iterkeys [as 別名]
class Document(Persistent):
    @property
    def handler(self):
        return _handler_index[id(self)]

    def __init__(self):
        self.notes = BTree()
        self.subscribers = PersistentList()
        self.notes[0] = Note(self, 0, {'desc': 'ROOT'})

    def create_note(self, props={}, cls=Note, parent_id=0, id=None):
        if id is None:
            if self.notes:
                id = max(self.list_note_ids()) + 1
            else:
                id = 0
        if id in self.notes:
            raise ValueError('Note id "%s" already in use' % id)
        note = cls(self, id, props)
        self.notes[id] = note
        self.notes[parent_id]._children.append(note.id)
        return note

    def get_note(self, note_id):
        return self.notes[note_id]

    def list_note_ids(self):
        return self.notes.iterkeys()

    def list_notes(self):
        return self.notes.itervalues()

    def del_note(self, note_id):
        for child_note_id in self.get_note(note_id)._children:
            self.del_note(child_note_id)
        self._cleanup_child_links(note_id)
        del self.notes[note_id]

    def subscribe(self, subscriber):
        self.subscribers.append(subscriber)

    def _cleanup_child_links(self, note_id):
        for note in self.list_notes():
            if note_id in note._children:
                note._children.remove(note_id)

    def dump_notes(self):
        def generate():
            for note in self.list_notes():
                note_data = {
                    'props': dict(note._props),
                    'children': list(note._children),
                }
                yield note.id, note_data
        return json.dumps(dict(generate()))

    # TODO: deprecate these methods
    def abort(self): self.handler.abort()
    def commit(self): self.handler.commit()
    def close(self): self.handler.close()
開發者ID:mgax,項目名稱:notespace,代碼行數:62,代碼來源:document.py


注:本文中的durus.btree.BTree.iterkeys方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。