File size: 1,589 Bytes
ab4488b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from .symlinknodemixin import SymlinkNodeMixin
from .util import _repr


class SymlinkNode(SymlinkNodeMixin):
    """
    Tree node which references to another tree node.

    Args:
        target: Symbolic Link Target. Another tree node, which is refered to.

    Keyword Args:
        parent: Reference to parent node.
        children: Iterable with child nodes.
        *: Any other given attribute is just stored as attribute **in** `target`.

    The :any:`SymlinkNode` has its own parent and its own child nodes.
    All other attribute accesses are just forwarded to the target node.

    >>> from anytree import SymlinkNode, Node, RenderTree
    >>> root = Node("root")
    >>> s1 = Node("sub1", parent=root, bar=17)
    >>> l = SymlinkNode(s1, parent=root, baz=18)
    >>> l0 = Node("l0", parent=l)
    >>> print(RenderTree(root))
    Node('/root')
    β”œβ”€β”€ Node('/root/sub1', bar=17, baz=18)
    └── SymlinkNode(Node('/root/sub1', bar=17, baz=18))
        └── Node('/root/sub1/l0')

    Any modifications on the target node are also available on the linked node and vice-versa:

    >>> s1.foo = 4
    >>> s1.foo
    4
    >>> l.foo
    4
    >>> l.foo = 9
    >>> s1.foo
    9
    >>> l.foo
    9
    """

    def __init__(self, target, parent=None, children=None, **kwargs):
        self.target = target
        self.target.__dict__.update(kwargs)
        self.parent = parent
        if children:
            self.children = children

    def __repr__(self):
        return _repr(self, [repr(self.target)], nameblacklist=("target",))