本文整理汇总了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())
示例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()))
示例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()