692
692
self.prefix_len = len(prefix)
693
693
self.add_nodes_callback = add_nodes_callback
695
def add_nodes(self, nodes):
696
"""Add nodes to the index.
698
:param nodes: An iterable of (key, node_refs, value) entries to add.
700
# save nodes in case its an iterator
702
translated_nodes = []
704
for (key, value, node_refs) in nodes:
705
adjusted_references = (
706
tuple(tuple(self.prefix_key + ref_node for ref_node in ref_list)
707
for ref_list in node_refs))
708
translated_nodes.append((self.prefix_key + key, value,
709
adjusted_references))
711
# XXX: TODO add an explicit interface for getting the reference list
712
# status, to handle this bit of user-friendliness in the API more
714
for (key, value) in nodes:
715
translated_nodes.append((self.prefix_key + key, value))
716
self.add_nodes_callback(translated_nodes)
718
def add_node(self, key, value, references=()):
719
"""Add a node to the index.
721
:param key: The key. keys are non-empty tuples containing
722
as many whitespace-free utf8 bytestrings as the key length
723
defined for this index.
724
:param references: An iterable of iterables of keys. Each is a
725
reference to another key.
726
:param value: The value to associate with the key. It may be any
727
bytes as long as it does not contain \0 or \n.
729
self.add_nodes(((key, value, references), ))
695
731
def _strip_prefix(self, an_iter):
696
732
"""Strip prefix data from nodes and return it."""
697
733
for node in an_iter: