Ë
    Ñwìi^A  ã                   óT   — d dl Z d dlmZ d dlmZ ddlmZmZ ddlm	Z	  G d„ d«      Z
y)	é    N)Ú
ASSERTIONS)ÚPreOrderIteré   )Ú	LoopErrorÚ	TreeError)ÚLightNodeMixinc                   óØ  — e Zd ZdZdZed„ «       Zej                  d„ «       Zd„ Zd„ Z	d„ Z
ed„ «       Zed	„ «       Zed
„ «       Zej                  d„ «       Zej                  d„ «       Zd„ Zd„ Zd„ Zd„ Zed„ «       Zd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z ed„ «       Z!d„ Z"d „ Z#d!„ Z$d"„ Z%y#)$Ú	NodeMixinu¥  
    The :any:`NodeMixin` class extends any Python class to a tree node.

    The only tree relevant information is the `parent` attribute.
    If `None` the :any:`NodeMixin` is root node.
    If set to another node, the :any:`NodeMixin` becomes the child of it.

    The `children` attribute can be used likewise.
    If `None` the :any:`NodeMixin` has no children.
    The `children` attribute can be set to any iterable of :any:`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
    Ú/c                 ó4   — t        | d«      r| j                  S y)uD  
        Parent Node.

        On set, the node is detached from any previous parent node and attached
        to the new node.

        >>> from anytree import Node, RenderTree
        >>> udo = Node("Udo")
        >>> marc = Node("Marc")
        >>> lian = Node("Lian", parent=marc)
        >>> print(RenderTree(udo))
        Node('/Udo')
        >>> print(RenderTree(marc))
        Node('/Marc')
        â””â”€â”€ Node('/Marc/Lian')

        **Attach**

        >>> marc.parent = udo
        >>> print(RenderTree(udo))
        Node('/Udo')
        â””â”€â”€ Node('/Udo/Marc')
            â””â”€â”€ Node('/Udo/Marc/Lian')

        **Detach**

        To make a node to a root node, just set this attribute to `None`.

        >>> marc.is_root
        False
        >>> marc.parent = None
        >>> marc.is_root
        True
        Ú_NodeMixin__parentN)Úhasattrr   ©Úselfs    úg/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/anytree/node/nodemixin.pyÚparentzNodeMixin.parentP   s   € ôH �4Ð-Ô.Ø—=‘=Ð Øó    c                 óü   — |�'t        |t        t        f«      sd|›d�}t        |«      ‚t	        | d«      r| j
                  }nd }||ur4| j                  |«       | j                  |«       | j                  |«       y y )NzParent node z is not of type 'NodeMixin'.r   )	Ú
isinstancer
   r   r   r   r   Ú_NodeMixin__check_loopÚ_NodeMixin__detachÚ_NodeMixin__attach)r   ÚvalueÚmsgr   s       r   r   zNodeMixin.parentx   s{   € àÐ¤Z°¼	Ä>Ð7RÔ%SØ   	Ð)EÐFˆCÜ˜C“.Ð Ü�4Ð-Ô.Ø—]‘]‰FàˆFØ˜ÑØ×Ñ˜eÔ$Ø�M‰M˜&Ô!Ø�M‰M˜%Õ ð r   c                 óž   ‡ — |�J|‰ u rd}t        |‰ fz  «      ‚t        ˆ fd„|j                  «       D «       «      rd}t        |‰ |fz  «      ‚y y )Nz1Cannot set parent. %r cannot be parent of itself.c              3   ó&   •K  — | ]  }|‰u –— Œ
 y ­w©N© ©Ú.0Úchildr   s     €r   Ú	<genexpr>z)NodeMixin.__check_loop.<locals>.<genexpr>‹   s   øè ø€ ÐGÑ.F U�5˜D”=Ñ.Fùó   ƒz&Cannot set parent. %r is parent of %r.)r   ÚanyÚiter_path_reverse)r   Únoder   s   `  r   Ú__check_loopzNodeMixin.__check_loop†   sa   ø€ ØÐØ�t‰|ØI�Ü  t g¡Ó.Ð.ÜÓG¨d×.DÑ.DÔ.FÓGÔGØ>�Ü  t¨T lÑ 2Ó3Ð3ð Hð	 r   c                 óö   ‡ — |�q‰ j                  |«       |j                  }t        rt        ˆ fd„|D «       «      sJ d«       ‚|D �cg c]	  }|‰ usŒ|‘Œ c}|_        d ‰ _        ‰ j                  |«       y y c c}w )Nc              3   ó&   •K  — | ]  }|‰u –— Œ
 y ­wr   r   r   s     €r   r"   z%NodeMixin.__detach.<locals>.<genexpr>•   s   øè ø€ ÐE±n¨U˜5 Dœ=±nùr#   úTree is corrupt.)Ú_pre_detachÚ_NodeMixin__children_or_emptyr   r$   Ú_NodeMixin__childrenr   Ú_post_detach)r   r   Úparentchildrenr!   s   `   r   Ú__detachzNodeMixin.__detach�   s~   ø€ àÐØ×Ñ˜VÔ$Ø#×7Ñ7ˆNÝÜÓE±nÓEÔEÐYÐGYÓYÐEá4BÓ X±N¨5ÀeÐSWÒFW¢°NÑ XˆFÔØ ˆDŒMà×Ñ˜fÕ%ð ùò !Ys   Á	A6ÁA6c                 óÚ   ‡ — |�h‰ j                  |«       |j                  }t        rt        ˆ fd„|D «       «      rJ d«       ‚|j	                  ‰ «       |‰ _        ‰ j                  |«       y y )Nc              3   ó&   •K  — | ]  }|‰u –— Œ
 y ­wr   r   r   s     €r   r"   z%NodeMixin.__attach.<locals>.<genexpr>¢   s   øè ø€ ÐI¹.°˜u¨œ}¹.ùr#   r*   )Ú_pre_attachr,   r   r$   Úappendr   Ú_post_attach)r   r   r/   s   `  r   Ú__attachzNodeMixin.__attachœ   sg   ø€ àÐØ×Ñ˜VÔ$Ø#×7Ñ7ˆNÝÜÓI¹.ÓIÔIÐ]ÐK]Ó]ÐIà×!Ñ! $Ô'Ø"ˆDŒMà×Ñ˜fÕ%ð r   c                 ó@   — t        | d«      sg | _        | j                  S )Nr-   )r   r-   r   s    r   Ú__children_or_emptyzNodeMixin.__children_or_empty©   s   € ä�tÐ3Ô4Ø ˆDŒOØ�‰Ðr   c                 ó,   — t        | j                  «      S )aÔ  
        All child nodes.

        >>> from anytree import Node
        >>> n = Node("n")
        >>> a = Node("a", parent=n)
        >>> b = Node("b", parent=n)
        >>> c = Node("c", parent=n)
        >>> n.children
        (Node('/n/a'), Node('/n/b'), Node('/n/c'))

        Modifying the children attribute modifies the tree.

        **Detach**

        The children attribute can be updated by setting to an iterable.

        >>> n.children = [a, b]
        >>> n.children
        (Node('/n/a'), Node('/n/b'))

        Node `c` is removed from the tree.
        In case of an existing reference, the node `c` does not vanish and is the root of its own tree.

        >>> c
        Node('/c')

        **Attach**

        >>> d = Node("d")
        >>> d
        Node('/d')
        >>> n.children = [a, b, d]
        >>> n.children
        (Node('/n/a'), Node('/n/b'), Node('/n/d'))
        >>> d
        Node('/n/d')

        **Duplicate**

        A node can just be the children once. Duplicates cause a :any:`TreeError`:

        >>> n.children = [a, b, d, a]
        Traceback (most recent call last):
            ...
        anytree.node.exceptions.TreeError: Cannot add node Node('/n/a') multiple times as child.
        )Útupler,   r   s    r   ÚchildrenzNodeMixin.children¯   s   € ôb �T×-Ñ-Ó.Ð.r   c                 óÖ   — t        «       }| D ]Z  }t        |t        t        f«      sd|›d�}t	        |«      ‚t        |«      }||vr|j                  |«       ŒKd|›d�}t	        |«      ‚ y )NzCannot add non-node object z&. It is not a subclass of 'NodeMixin'.zCannot add node z multiple times as child.)Úsetr   r
   r   r   ÚidÚadd)r;   Úseenr!   r   Úchildids        r   Ú__check_childrenzNodeMixin.__check_childrenâ   sq   € ä‹uˆÛˆEÜ˜e¤i´Ð%@ÔAØ3°E°9Ð<bÐc�Ü “nÐ$Ü˜“iˆGØ˜dÑ"Ø—‘˜Õ!à(¨¨	Ð1JÐK�Ü “nÐ$ñ r   c                 ó@  — t        |«      }t        j                  |«       | j                  }| `	 | j	                  |«       |D ]	  }| |_        Œ | j                  |«       t        r$t        | j                  «      t        |«      k(  sJ ‚y y # t        $ r	 || _        ‚ w xY wr   )
r:   r
   Ú_NodeMixin__check_childrenr;   Ú_pre_attach_childrenr   Ú_post_attach_childrenr   ÚlenÚ	Exception)r   r;   Úold_childrenr!   s       r   r;   zNodeMixin.childrenð   s—   € ô ˜“?ˆÜ×"Ñ" 8Ô,à—}‘}ˆØˆMð		Ø×%Ñ% hÔ/Û!�Ø#�•ð "à×&Ñ& xÔ0ÝÜ˜4Ÿ=™=Ó)¬S°«]Ò:Ð:Ñ:ð øäò 	Ø(ˆDŒMØð	ús   °AB ÂBc                 óÐ   — | j                   }| j                  |«       | j                   D ]	  }d |_        Œ t        rt	        | j                   «      dk(  sJ ‚| j                  |«       y )Nr   )r;   Ú_pre_detach_childrenr   r   rG   Ú_post_detach_children)r   r;   r!   s      r   r;   zNodeMixin.children  sV   € à—=‘=ˆØ×!Ñ! (Ô+Ø—]”]ˆEØˆE�Lð #åÜ�t—}‘}Ó%¨Ò*Ð*Ð*Ø×"Ñ" 8Õ,r   c                  ó   — y)z(Method call before detaching `children`.Nr   ©r   r;   s     r   rK   zNodeMixin._pre_detach_children  ó   � r   c                  ó   — y)z'Method call after detaching `children`.Nr   rN   s     r   rL   zNodeMixin._post_detach_children  rO   r   c                  ó   — y)z(Method call before attaching `children`.Nr   rN   s     r   rE   zNodeMixin._pre_attach_children  rO   r   c                  ó   — y)z'Method call after attaching `children`.Nr   rN   s     r   rF   zNodeMixin._post_attach_children  rO   r   c                 ó   — | j                   S )aœ  
        Path from root node down to this `Node`.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.path
        (Node('/Udo'),)
        >>> marc.path
        (Node('/Udo'), Node('/Udo/Marc'))
        >>> lian.path
        (Node('/Udo'), Node('/Udo/Marc'), Node('/Udo/Marc/Lian'))
        )Ú_pathr   s    r   ÚpathzNodeMixin.path  s   € ð  �z‰zÐr   c              #   ó<   K  — | }|�|–— |j                   }|�Œyy­w)ae  
        Iterate up the tree from the current node to the root 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')
        N©r   ©r   r&   s     r   r%   zNodeMixin.iter_path_reverse,  s)   è ø€ ð* ˆØÐØŠJØ—;‘;ˆDð Óùs   ‚šc                 óX   — t        t        t        | j                  «       «      «      «      S r   )r:   ÚreversedÚlistr%   r   s    r   rT   zNodeMixin._pathF  s    € ä”Xœd 4×#9Ñ#9Ó#;Ó<Ó=Ó>Ð>r   c                 óH   — | j                   €y| j                   j                  S )at  
        All parent nodes and their parent nodes.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.ancestors
        ()
        >>> marc.ancestors
        (Node('/Udo'),)
        >>> lian.ancestors
        (Node('/Udo'), Node('/Udo/Marc'))
        r   )r   rU   r   s    r   Ú	ancestorszNodeMixin.ancestorsJ  s!   € ð  �;‰;ÐØØ�{‰{×ÑÐr   c                 óR   — t        j                  dt        d¬«       | j                  S )zé
        All parent nodes and their parent nodes - see :any:`ancestors`.

        The attribute `anchestors` is just a typo of `ancestors`. Please use `ancestors`.
        This attribute will be removed in the 3.0.0 release.
        z;.anchestors was a typo and will be removed in version 3.0.0é   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarningr]   r   s    r   Ú
anchestorszNodeMixin.anchestors^  s!   € ô 	�‰ÐSÔUgÐtuÕvØ�~‰~Ðr   c                 ó0   — t        t        | «      «      dd S )aj  
        All child nodes and all their child nodes.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> loui = Node("Loui", parent=marc)
        >>> soe = Node("Soe", parent=lian)
        >>> udo.descendants
        (Node('/Udo/Marc'), Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lian/Soe'), Node('/Udo/Marc/Loui'))
        >>> marc.descendants
        (Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lian/Soe'), Node('/Udo/Marc/Loui'))
        >>> lian.descendants
        (Node('/Udo/Marc/Lian/Soe'),)
        r   N©r:   r   r   s    r   ÚdescendantszNodeMixin.descendantsi  s   € ô$ ”\ $Ó'Ó(¨¨Ð,Ð,r   c                 óT   — | }|j                   �|j                   }|j                   �Œ|S )a>  
        Tree Root Node.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.root
        Node('/Udo')
        >>> marc.root
        Node('/Udo')
        >>> lian.root
        Node('/Udo')
        rW   rX   s     r   ÚrootzNodeMixin.root}  s-   € ð  ˆØ�k‰kÐ%Ø—;‘;ˆDð �k‰kÑ%àˆr   c                 ó^   ‡ — ‰ j                   }|€yt        ˆ fd„|j                  D «       «      S )a  
        Tuple of nodes with the same parent.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> loui = Node("Loui", parent=marc)
        >>> lazy = Node("Lazy", parent=marc)
        >>> udo.siblings
        ()
        >>> marc.siblings
        ()
        >>> lian.siblings
        (Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
        >>> loui.siblings
        (Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Lazy'))
        r   c              3   ó,   •K  — | ]  }|‰usŒ|–— Œ y ­wr   r   )r    r&   r   s     €r   r"   z%NodeMixin.siblings.<locals>.<genexpr>©  s   øè ø€ ÐJ¡o˜d¸ÀTÒ9I”T¡oùs   ƒ	�)r   r:   r;   ©r   r   s   ` r   ÚsiblingszNodeMixin.siblings’  s+   ø€ ð( —‘ˆØˆ>ØÜÓJ f§o¢oÓJÓJÐJr   c                 ó0   — t        t        | d„ ¬«      «      S )aò  
        Tuple of all leaf nodes.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> loui = Node("Loui", parent=marc)
        >>> lazy = Node("Lazy", parent=marc)
        >>> udo.leaves
        (Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
        >>> marc.leaves
        (Node('/Udo/Marc/Lian'), Node('/Udo/Marc/Loui'), Node('/Udo/Marc/Lazy'))
        c                 ó   — | j                   S r   )Úis_leaf)r&   s    r   Ú<lambda>z"NodeMixin.leaves.<locals>.<lambda>»  s   € ¸T¿\º\r   )Úfilter_rf   r   s    r   ÚleaveszNodeMixin.leaves«  s   € ô  ”\ $Ñ0IÔJÓKÐKr   c                 ó2   — t        | j                  «      dk(  S )aI  
        `Node` has no children (External Node).

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.is_leaf
        False
        >>> marc.is_leaf
        False
        >>> lian.is_leaf
        True
        r   )rG   r,   r   s    r   rp   zNodeMixin.is_leaf½  s   € ô  �4×+Ñ+Ó,°Ñ1Ð1r   c                 ó   — | j                   du S )a6  
        `Node` is tree root.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.is_root
        True
        >>> marc.is_root
        False
        >>> lian.is_root
        False
        NrW   r   s    r   Úis_rootzNodeMixin.is_rootÏ  s   € ð  �{‰{˜dÐ"Ð"r   c                 óJ   — | j                   }|rt        d„ |D «       «      dz   S y)aI  
        Number of edges on the longest path to a leaf `Node`.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.height
        2
        >>> marc.height
        1
        >>> lian.height
        0
        c              3   ó4   K  — | ]  }|j                   –— Œ y ­wr   )Úheight)r    r!   s     r   r"   z#NodeMixin.height.<locals>.<genexpr>ó  s   è ø€ Ð:±¨�u—|•|±ùs   ‚r   r   )r,   ÚmaxrN   s     r   ry   zNodeMixin.heightá  s+   € ð  ×+Ñ+ˆÙÜÑ:±Ó:Ó:¸QÑ>Ð>Ør   c                 óH   — t        | j                  «       «      D ]  \  }}Œ S )a4  
        Number of edges to the root `Node`.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> udo.depth
        0
        >>> marc.depth
        1
        >>> lian.depth
        2
        )Ú	enumerater%   )r   ÚdepthÚ_s      r   r}   zNodeMixin.depthö  s(   € ô$ " $×"8Ñ"8Ó":Ö;‰HˆE�1Øð <àˆr   c                 ó@   — t        t        | «      d«      D ]  \  }}Œ S )aÆ  
        Tree size --- the number of nodes in tree starting at this node.

        >>> from anytree import Node
        >>> udo = Node("Udo")
        >>> marc = Node("Marc", parent=udo)
        >>> lian = Node("Lian", parent=marc)
        >>> loui = Node("Loui", parent=marc)
        >>> soe = Node("Soe", parent=lian)
        >>> udo.size
        5
        >>> marc.size
        4
        >>> lian.size
        2
        >>> loui.size
        1
        r   )r|   r   )r   Úsizer~   s      r   r€   zNodeMixin.size  s&   € ô, !¤¨dÓ!3°QÖ7‰GˆD�!Øð 8àˆr   c                  ó   — y)z+Method call before detaching from `parent`.Nr   rl   s     r   r+   zNodeMixin._pre_detach&  rO   r   c                  ó   — y)z*Method call after detaching from `parent`.Nr   rl   s     r   r.   zNodeMixin._post_detach)  rO   r   c                  ó   — y)z)Method call before attaching to `parent`.Nr   rl   s     r   r3   zNodeMixin._pre_attach,  rO   r   c                  ó   — y)z(Method call after attaching to `parent`.Nr   rl   s     r   r5   zNodeMixin._post_attach/  rO   r   N)&Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	separatorÚpropertyr   Úsetterr   r   r   r,   r;   ÚstaticmethodrD   ÚdeleterrK   rL   rE   rF   rU   r%   rT   r]   rd   rg   ri   rm   rs   rp   rv   ry   r}   r€   r+   r.   r3   r5   r   r   r   r
   r
   
   sî  „ ñAðF €Iàñ%ó ð%ðN ‡]�]ñ!ó ð!ò4ò&ò&ð ñó ðð
 ñ0/ó ð0/ðd ñ%ó ð%ð ‡_�_ñó ðð& ×Ññ-ó ð-ò7ò6ò7ò6ð ñó ðò"ð4 ñ?ó ð?ð ñ ó ð ð& ñó ðð ñ-ó ð-ð& ñó ðð( ñKó ðKð0 ñLó ðLð" ñ2ó ð2ð" ñ#ó ð#ð" ñó ðð( ñó ðð* ñó ðò2:ò9ò8ó7r   r
   )ra   Úanytree.configr   Úanytree.iteratorsr   Ú
exceptionsr   r   Úlightnodemixinr   r
   r   r   r   Ú<module>r’      s    ðÛ å %Ý *ç ,Ý *÷f7ò f7r   