l.b.a.t.LookupTree : class documentation

Part of lp.bugs.adapters.treelookup View In Hierarchy

Known subclasses: lp.bugs.externalbugtracker.__init__.LookupTree

A searchable tree.
Method __init__ Construct a new LookupTree.
Method find Search this tree.
Method flatten Generate a flat representation of this tree.
Method min_depth The minimum distance to a leaf.
Method max_depth The maximum distance to a leaf.
Method describe A representation of this tree, formatted for human consumption.
Method __repr__ A machine-readable representation of this tree.
Method _verify Check the validity of the tree.
def __init__(self, *args):
Construct a new `LookupTree`.

Flatten or promote the given arguments into `LookupBranch`s.

As an extra step, the branch is verified by calling `_verify`.

:param args: `LookupBranch`s, `LookupTree`s, or iterables to
    be attached to this tree. Iterable arguments will be
    promoted to `LookupBranch` by calling `_branch_factory`
    with all the values from the iterator as positional
    arguments.
def _verify(self):
Check the validity of the tree.

Every branch in the tree must be an instance of LookupBranch. In addition, only one default branch can exist, and it must be the last branch.

RaisesTypeErrorIf the tree is invalid.
def find(self, key, *more):
Search this tree.

Searches in the tree for key. If the result is another tree, it searches down that tree, using the first value of more as key. Once it gets to a leaf, whether or not all the keys (i.e. key + more) have been consumed, the result is returned.

RaisesKeyErrorIf a result is not found.
def flatten(self):
Generate a flat representation of this tree.

Generates tuples. The last element in the tuple is the result. The previous elements are the branches followed to reach the result.

This can be useful for generating documentation, because it is a compact, flat representation of the tree.

@property
def min_depth(self):
The minimum distance to a leaf.
@property
def max_depth(self):
The maximum distance to a leaf.
def describe(self, level=1):
A representation of this tree, formatted for human consumption.

The representation of each branch in this tree is indented corresponding to level, which indicates the position we are at within the tree that is being represented.

When asking each branch for a representation, the next level is passed to describe, so that sub-trees will be indented more.

This is mainly intended as an aid to development.

def __repr__(self):
A machine-readable representation of this tree.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.