
    i                     :    S SK Jr   " S S5      r " S S\5      rg)   )
ASSERTIONSc                   8    \ rS rSrSr\S 5       r\S 5       rSrg)Walker   zWalk from one node to another.c                 v   U R                   nUR                   nU R                  UR                  La  U < SU< S3n[        U5      e[        R	                  X#5      n[
        (       a  US   U R                  L d   e[        U5      nXS   L a  SnO[        [        X&S 5      5      nXS   L a  SnOX6S nXuS   U4$ )a  
Walk from `start` node to `end` node.

Returns:
    (upwards, common, downwards): `upwards` is a list of nodes to go upward to.
    `common` top node. `downwards` is a list of nodes to go downward to.

Raises:
    WalkError: on no common root node.

Example:

>>> from anytree import Node, RenderTree, AsciiStyle
>>> f = Node("f")
>>> b = Node("b", parent=f)
>>> a = Node("a", parent=b)
>>> d = Node("d", parent=b)
>>> c = Node("c", parent=d)
>>> e = Node("e", parent=d)
>>> g = Node("g", parent=f)
>>> i = Node("i", parent=g)
>>> h = Node("h", parent=i)
>>> print(RenderTree(f, style=AsciiStyle()))
Node('/f')
|-- Node('/f/b')
|   |-- Node('/f/b/a')
|   +-- Node('/f/b/d')
|       |-- Node('/f/b/d/c')
|       +-- Node('/f/b/d/e')
+-- Node('/f/g')
    +-- Node('/f/g/i')
        +-- Node('/f/g/i/h')

Create a walker:

>>> w = Walker()

This class is made for walking:

>>> w.walk(f, f)
((), Node('/f'), ())
>>> w.walk(f, b)
((), Node('/f'), (Node('/f/b'),))
>>> w.walk(b, f)
((Node('/f/b'),), Node('/f'), ())
>>> w.walk(h, e)
((Node('/f/g/i/h'), Node('/f/g/i'), Node('/f/g')), Node('/f'), (Node('/f/b'), Node('/f/b/d'), Node('/f/b/d/e')))
>>> w.walk(d, e)
((), Node('/f/b/d'), (Node('/f/b/d/e'),))

For a proper walking the nodes need to be part of the same tree:

>>> w.walk(Node("a"), Node("b"))
Traceback (most recent call last):
  ...
anytree.walker.WalkError: Node('/a') and Node('/b') are not part of the same tree.
z and z are not part of the same tree.     N)	pathroot	WalkErrorr   _Walker__calc_commonr   lentuplereversed)	startend	startpathendpathmsgcommon
len_commonupwardsdowns	            ;/app/mltbenv/lib/python3.13/site-packages/anytree/walker.pywalkWalker.walk   s    v JJ	((::SXX%IU3')HICC. %%i9:!9

***[
2JGHY{%;<=G*D;'Dr
D((    c                 8    [        S [        X5       5       5      $ )Nc              3   6   #    U  H  u  pXL d  M  Uv   M     g 7f)Nr
   ).0sieis      r   	<genexpr>'Walker.__calc_common.<locals>.<genexpr>Z   s     BoFBRRos   
	)r   zip)r   r   s     r   __calc_commonWalker.__calc_commonX   s    Bc%oBBBr   r
   N)	__name__
__module____qualname____firstlineno____doc__staticmethodr   r   __static_attributes__r
   r   r   r   r      s0    (N) N)` C Cr   r   c                       \ rS rSrSrSrg)r   ]   zWalk Error.r
   N)r)   r*   r+   r,   r-   r/   r
   r   r   r   r   ]   s    r   r   N)configr   r   RuntimeErrorr   r
   r   r   <module>r4      s#    VC VCr r   