DocumentHandleNode

class docushare.DocumentHandleNode(handle_number)

Bases: HandleNode

This class represents a DocuShare Document handle in a tree structure.

Document handle is always a leaf node in the tree structure. It cannot have a child.

Parameters

handle_number (int) – Handle number.

Attributes Summary

ancestors

All parent Collection handles and their parent Collection handles.

anchestors

All parent Collection handles and their parent Collection handles.

children

All child handles.

depth

Number of handles to the root CollectionHandleNode.

descendants

All child handles and their child handles.

height

Number of handles on the longest path to a leaf HandleNode.

identifier

String representation of this handle like "Document-20202".

is_leaf

Indicates if this handle node has no children.

is_root

Indicates if this handle node is tree root.

leaves

Tuple of all leaf handles excluding Collection handles.

number

Handle number.

parent

Parent Collection handle.

path

Path of this handle.

root

Root Collection handle.

separator

siblings

Tuple of handles with the same parent Collection handle.

type

Handle type.

Methods Summary

from_str(handle_str)

Parse the given string as a DocuShare handle and return Handle instance.

iter_path_reverse()

Iterate up the tree from the current node.

Attributes Documentation

ancestors

All parent Collection handles and their parent Collection handles.

anchestors

All parent Collection handles and their parent Collection handles.

children

All child handles. It is always an empty list.

depth

Number of handles to the root CollectionHandleNode.

Notes

The root is not necessarily a root Collection of the DocuShare site.

descendants

All child handles and their child handles.

It is always an empty tuple.

height

Number of handles on the longest path to a leaf HandleNode.

It is always zero.

identifier

String representation of this handle like “Document-20202”.

Type

str

is_leaf

Indicates if this handle node has no children.

It is always True.

is_root

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.

leaves

Tuple of all leaf handles excluding Collection handles.

It is always a tuple that includes this instance itself only.

number

Handle number.

Type

int

parent

Parent Collection handle.

path

Path of this handle.

root

Root Collection handle.

Notes

It is not necessarily a root Collection of the DocuShare site.

separator

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, the NodeMixin 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 of NodeMixin 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
siblings

Tuple of handles with the same parent Collection handle.

type

Handle type.

Type

HandleType

Methods Documentation

classmethod from_str(handle_str)

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

Handle

Raises

InvalidHandleError – If the given string is not a valid DocuShare handle.

iter_path_reverse()

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')