moostree.Node

moosetree.Node

moosetree.Node(parent, name, **kwargs)

Base class for tree nodes that accepts arbitrary attributes.

Create a new node in the tree that is a child of parent with the given name. The supplied parent must be another Node object. All keyword arguments are stored as "attributes" and may be of any type.

warningwarning:Speed is Important!

The need for this object comes from the MooseDocs package, which uses tree objects extensively. Originally, MooseDocs used the anytree package for these structures. As the MooseDocs system evolved as well as the amount of documentation, in particular the amount of generated HTML output, the speed in creating the tree nodes became critical. The anytree package is robust and well designed, but the construction of the nodes was not fast enough.

attributes

Return the a 'attributes' (key, value pairs supplied in construction) for this node.

children

Return a list of children.

commentnote

The list is a copy but the Node objects in the list are not.

count

Return the number of all descendants

descendants

Return a list of all descendants, children's children etc.

get(key, default=None)

Return the value of an attribute key or default if it does not exist.

insert(idx, child)

Insert a nod child before the supplied idx in the list of children.

is_root

Return True if the Node is a root, i.e., is the parent node object set to None.

items()

Return the dict() iterator to the attributes, i.e., k, v in node.items().

name

Return the name of the Node.

next

Return the next sibling, if it exists.

parent

Return the parent Node object, which is None for a root node.

path

Return the nodes that lead to the root node of the tree from this node.

previous

Return the previous sibling, if it exists.

root

Return the root node of the tree.

siblings

Return a list of sibling nodes.