CollectionHandleNode
Bases:
HandleNode
This class represents a DocuShare Collection handle in a tree structure.
- Parameters
handle_number (int) – Handle number.
children (list) –
list
ofCollectionHandleNode
andDocumentHandleNode
. Children of this collection.
Attributes Summary
All parent Collection handles and their parent Collection handles.
All parent Collection handles and their parent Collection handles.
All child handles.
Number of handles to the root
CollectionHandleNode
.All child handles and their child handles.
Number of handles on the longest path to a leaf
HandleNode
.String representation of this handle like "Document-20202".
Indicates if this handle node has no children.
Indicates if this handle node is tree root.
Tuple of all leaf handles excluding Collection handles.
Handle number.
Parent Collection handle.
Path of this handle.
Root Collection handle.
Tuple of handles with the same parent Collection handle.
Handle type.
Methods Summary
from_str
(handle_str)Parse the given string as a DocuShare handle and return Handle instance.
Iterate up the tree from the current node.
Attributes Documentation
All parent Collection handles and their parent Collection handles.
All parent Collection handles and their parent Collection handles.
All child handles.
Number of handles to the root
CollectionHandleNode
.Notes
The root is not necessarily a root Collection of the DocuShare site.
All child handles and their child handles.
Number of handles on the longest path to a leaf
HandleNode
.
String representation of this handle like “Document-20202”.
- Type
Indicates if this handle node has no children.
Indicates if this handle node is tree root.
Notes
This handle does not necessarily represent a root Collection/Document in the DocuShare site even if this property is True.
Tuple of all leaf handles excluding Collection handles.
Handle number.
- Type
Parent Collection handle.
Path of this handle.
Root Collection handle.
Notes
It is not necessarily a root Collection of the DocuShare site.
The
NodeMixin
class extends any Python class to a tree node.The only tree relevant information is the parent attribute. If None the
NodeMixin
is root node. If set to another node, theNodeMixin
becomes the child of it.The children attribute can be used likewise. If None the
NodeMixin
has no children. The children attribute can be set to any iterable ofNodeMixin
instances. These instances become children of the node.>>> from anytree import NodeMixin, RenderTree >>> class MyBaseClass(object): # Just an example of a base class ... foo = 4 >>> class MyClass(MyBaseClass, NodeMixin): # Add Node feature ... def __init__(self, name, length, width, parent=None, children=None): ... super(MyClass, self).__init__() ... self.name = name ... self.length = length ... self.width = width ... self.parent = parent ... if children: ... self.children = children
Construction via parent:
>>> my0 = MyClass('my0', 0, 0) >>> my1 = MyClass('my1', 1, 0, parent=my0) >>> my2 = MyClass('my2', 0, 2, parent=my0)
>>> for pre, _, node in RenderTree(my0): ... treestr = u"%s%s" % (pre, node.name) ... print(treestr.ljust(8), node.length, node.width) my0 0 0 ├── my1 1 0 └── my2 0 2
Construction via children:
>>> my0 = MyClass('my0', 0, 0, children=[ ... MyClass('my1', 1, 0), ... MyClass('my2', 0, 2), ... ]
>>> for pre, _, node in RenderTree(my0): ... treestr = u"%s%s" % (pre, node.name) ... print(treestr.ljust(8), node.length, node.width) my0 0 0 ├── my1 1 0 └── my2 0 2
Both approaches can be mixed:
>>> my0 = MyClass('my0', 0, 0, children=[ ... MyClass('my1', 1, 0), ... ] >>> my2 = MyClass('my2', 0, 2, parent=my0)
>>> for pre, _, node in RenderTree(my0): ... treestr = u"%s%s" % (pre, node.name) ... print(treestr.ljust(8), node.length, node.width) my0 0 0 ├── my1 1 0 └── my2 0 2
Tuple of handles with the same parent Collection handle.
Handle type.
- Type
Methods Documentation
Parse the given string as a DocuShare handle and return Handle instance.
- Parameters
handle_str (str or bytes-like object) – A string that represents a DocuShare handle like ‘Document-20202’.
- Returns
A canonical instance that represents the given handle.
- Return type
- Raises
InvalidHandleError – If the given string is not a valid DocuShare handle.
Iterate up the tree from the current node.
>>> from anytree import Node >>> udo = Node("Udo") >>> marc = Node("Marc", parent=udo) >>> lian = Node("Lian", parent=marc) >>> for node in udo.iter_path_reverse(): ... print(node) Node('/Udo') >>> for node in marc.iter_path_reverse(): ... print(node) Node('/Udo/Marc') Node('/Udo') >>> for node in lian.iter_path_reverse(): ... print(node) Node('/Udo/Marc/Lian') Node('/Udo/Marc') Node('/Udo')