
    ^j'                         d Z ddlZddlmZ  ej                  dd      Z G d d      Z G d	 d
e      Z G d de      Z e       Z	 G d de      Z
 G d de      Z G d d      Zd Zd Zy)z
Tree Rendering.

* :any:`RenderTree` using the following styles:
    * :any:`AsciiStyle`
    * :any:`ContStyle`
    * :any:`ContRoundStyle`
    * :any:`DoubleStyle`
    N   )
ASSERTIONSRow)prefillnodec                   8     e Zd ZdZ fdZed        Zd Z xZS )AbstractStylez
    Tree Render Style.

    Args:

        vertical: Sign for vertical line.

        cont: Chars for a continued branch.

        end: Chars for the last branch.
    c                     t         |           || _        || _        || _        t
        r:t        |      t        |      cxk(  rt        |      k(  sn J d| d| d| d       y y )N'z', 'z' and 'z' need to have equal length)super__init__verticalcontendr   len)selfr   r   r   	__class__s       G/opt/ringagent/.cad-venv/lib/python3.12/site-packages/anytree/render.pyr   zAbstractStyle.__init__   sj     	t9H9S9 H:T$wse3NO9     c                 2    dt        | j                        z  S )zEmpty string as placeholder. )r   r   r   s    r   emptyzAbstractStyle.empty)   s     S]""r   c                 8    | j                   j                  }| dS )Nz())r   __name__)r   	classnames     r   __repr__zAbstractStyle.__repr__.   s    NN++	Br   )	r   
__module____qualname____doc__r   propertyr   r   __classcell__r   s   @r   r
   r
      s&    
 # # r   r
   c                   "     e Zd ZdZ fdZ xZS )
AsciiStylea  
    Ascii style.

    >>> from anytree import Node, RenderTree
    >>> root = Node("root")
    >>> s0 = Node("sub0", parent=root)
    >>> s0b = Node("sub0B", parent=s0)
    >>> s0a = Node("sub0A", parent=s0)
    >>> s1 = Node("sub1", parent=root)

    >>> print(RenderTree(root, style=AsciiStyle()))
    Node('/root')
    |-- Node('/root/sub0')
    |   |-- Node('/root/sub0/sub0B')
    |   +-- Node('/root/sub0/sub0A')
    +-- Node('/root/sub1')
    c                 (    t         |   ddd       y )Nz|   z|-- z+-- r   r   r   r   s    r   r   zAsciiStyle.__init__F   s    0r   r   r   r    r!   r   r#   r$   s   @r   r&   r&   3   s    $1 1r   r&   c                   "     e Zd ZdZ fdZ xZS )	ContStyleu  
    Continued style, without gaps.

    >>> from anytree import Node, RenderTree
    >>> root = Node("root")
    >>> s0 = Node("sub0", parent=root)
    >>> s0b = Node("sub0B", parent=s0)
    >>> s0a = Node("sub0A", parent=s0)
    >>> s1 = Node("sub1", parent=root)

    >>> print(RenderTree(root, style=ContStyle()))
    Node('/root')
    ├── Node('/root/sub0')
    │   ├── Node('/root/sub0/sub0B')
    │   └── Node('/root/sub0/sub0A')
    └── Node('/root/sub1')
    c                 (    t         |   ddd       y )N   │   
   ├── u
   └── r(   r)   s    r   r   zContStyle.__init__]       &;=RSr   r*   r$   s   @r   r,   r,   J       $T Tr   r,   c                   "     e Zd ZdZ fdZ xZS )ContRoundStyleu  
    Continued style, without gaps, round edges.

    >>> from anytree import Node, RenderTree
    >>> root = Node("root")
    >>> s0 = Node("sub0", parent=root)
    >>> s0b = Node("sub0B", parent=s0)
    >>> s0a = Node("sub0A", parent=s0)
    >>> s1 = Node("sub1", parent=root)

    >>> print(RenderTree(root, style=ContRoundStyle()))
    Node('/root')
    ├── Node('/root/sub0')
    │   ├── Node('/root/sub0/sub0B')
    │   ╰── Node('/root/sub0/sub0A')
    ╰── Node('/root/sub1')
    c                 (    t         |   ddd       y )Nr.   r/   u
   ╰── r(   r)   s    r   r   zContRoundStyle.__init__w   r0   r   r*   r$   s   @r   r3   r3   d   r1   r   r3   c                   "     e Zd ZdZ fdZ xZS )DoubleStyleu  
    Double line style, without gaps.

    >>> from anytree import Node, RenderTree
    >>> root = Node("root")
    >>> s0 = Node("sub0", parent=root)
    >>> s0b = Node("sub0B", parent=s0)
    >>> s0a = Node("sub0A", parent=s0)
    >>> s1 = Node("sub1", parent=root)

    >>> print(RenderTree(root, style=DoubleStyle))
    Node('/root')
    ╠══ Node('/root/sub0')
    ║   ╠══ Node('/root/sub0/sub0B')
    ║   ╚══ Node('/root/sub0/sub0A')
    ╚══ Node('/root/sub1')

    c                 (    t         |   ddd       y )Nu   ║   u
   ╠══ u
   ╚══ r(   r)   s    r   r   zDoubleStyle.__init__   r0   r   r*   r$   s   @r   r6   r6   {   s    &T Tr   r6   c                   P    e Zd ZdZeedfdZd Zd
dZe	d        Z
d Zd Zdd	Zy)
RenderTreeuN  
    Render tree starting at `node`.

    Keyword Args:
        style (AbstractStyle): Render Style.
        childiter: Child iterator.
        maxlevel: Limit rendering to this depth.

    :any:`RenderTree` is an iterator, returning a tuple with 3 items:

    `pre`
        tree prefix.

    `fill`
        filling for multiline entries.

    `node`
        :any:`NodeMixin` object.

    It is up to the user to assemble these parts to a whole.

    >>> from anytree import Node, RenderTree
    >>> root = Node("root", lines=["c0fe", "c0de"])
    >>> s0 = Node("sub0", parent=root, lines=["ha", "ba"])
    >>> s0b = Node("sub0B", parent=s0, lines=["1", "2", "3"])
    >>> s0a = Node("sub0A", parent=s0, lines=["a", "b"])
    >>> s1 = Node("sub1", parent=root, lines=["Z"])

    Simple one line:

    >>> for pre, _, node in RenderTree(root):
    ...     print("%s%s" % (pre, node.name))
    root
    ├── sub0
    │   ├── sub0B
    │   └── sub0A
    └── sub1

    Multiline:

    >>> for pre, fill, node in RenderTree(root):
    ...     print("%s%s" % (pre, node.lines[0]))
    ...     for line in node.lines[1:]:
    ...         print("%s%s" % (fill, line))
    c0fe
    c0de
    ├── ha
    │   ba
    │   ├── 1
    │   │   2
    │   │   3
    │   └── a
    │       b
    └── Z

    `maxlevel` limits the depth of the tree:

    >>> print(RenderTree(root, maxlevel=2))
    Node('/root', lines=['c0fe', 'c0de'])
    ├── Node('/root/sub0', lines=['ha', 'ba'])
    └── Node('/root/sub1', lines=['Z'])

    The `childiter` is responsible for iterating over child nodes at the
    same level. An reversed order can be achieved by using `reversed`.

    >>> for row in RenderTree(root, childiter=reversed):
    ...     print("%s%s" % (row.pre, row.node.name))
    root
    ├── sub1
    └── sub0
        ├── sub0A
        └── sub0B

    Or writing your own sort function:

    >>> def mysort(items):
    ...     return sorted(items, key=lambda item: item.name)
    >>> for row in RenderTree(root, childiter=mysort):
    ...     print("%s%s" % (row.pre, row.node.name))
    root
    ├── sub0
    │   ├── sub0A
    │   └── sub0B
    └── sub1

    :any:`by_attr` simplifies attribute rendering and supports multiline:

    >>> print(RenderTree(root).by_attr())
    root
    ├── sub0
    │   ├── sub0B
    │   └── sub0A
    └── sub1
    >>> print(RenderTree(root).by_attr("lines"))
    c0fe
    c0de
    ├── ha
    │   ba
    │   ├── 1
    │   │   2
    │   │   3
    │   └── a
    │       b
    └── Z

    And can be a function:

    >>> print(RenderTree(root).by_attr(lambda n: " ".join(n.lines)))
    c0fe c0de
    ├── ha ba
    │   ├── 1 2 3
    │   └── a b
    └── Z
    Nc                 j    t        |t              s |       }|| _        || _        || _        || _        y )N)
isinstancer
   r   style	childitermaxlevel)r   r   r<   r=   r>   s        r   r   zRenderTree.__init__  s/    %/GE	
" r   c                 :    | j                  | j                  d      S )N )_RenderTree__nextr   r   s    r   __iter__zRenderTree.__iter__  s    {{499b))r   c              #   B  K   t         j                  ||| j                         |dz  }| j                  || j                  k  rV|j                  }|rG| j                  |      }t        |      D ]'  \  }}| j                  |g || |      E d {    ) y y y 7 	w)Nr   )level)r9   _RenderTree__itemr<   r>   childrenr=   _is_lastrA   )r   r   	continuesrD   rF   childis_lasts          r   __nextzRenderTree.__next  s     i<<
== EDMM$9}}H>>(3&.x&8 ZNE7#{{52KI2K7{2KSX{YYYZ  %:
 Zs   BBB
Bc                     |st        dd|       S |D cg c]  }|r|j                  n|j                   }}dj                  |d d       }|d   r|j                  n|j
                  }||z   }dj                  |      }t        |||       S c c}w )N )r   r   r   joinr   r   )	r   rH   r<   r   itemsindentbranchr   r   s	            r   __itemzRenderTree.__item  s    r2t$$ENOT4U[[8OOs$(}%))vowwu~3d## Ps   !Bc                 :      fd}dj                   |             S )Nc               3      K   D ][  } t        | j                        j                         xs dg}| j                   |d     |dd  D ]  }| j                   |   ] y wNrM   r   r   )reprr   
splitlinesr   r   )rowlinesliner   s      r   getzRenderTree.__str__.<locals>.get(  sr      .SXX113;t	%(,,!!"I .D XXJtf--..s   A"A%
rO   )r   r\   s   ` r   __str__zRenderTree.__str__'  s    	. yyr   c                     | j                   j                  }t        | j                        d| j                  d| j
                  g}dj                  |dj                  |            S )Nzstyle=z
childiter=z{}({})z, )r   r   rW   r   r<   r=   formatrO   )r   r   argss      r   r   zRenderTree.__repr__1  sU    NN++	TYY6$**!8Jt~~FX:YZy$))D/::r   c                 >      fd}dj                   |             S )ub  
        Return rendered tree with node attribute `attrname`.

        >>> from anytree import AnyNode, RenderTree
        >>> root = AnyNode(id="root")
        >>> s0 = AnyNode(id="sub0", parent=root)
        >>> s0b = AnyNode(id="sub0B", parent=s0, foo=4, bar=109)
        >>> s0a = AnyNode(id="sub0A", parent=s0)
        >>> s1 = AnyNode(id="sub1", parent=root)
        >>> s1a = AnyNode(id="sub1A", parent=s1)
        >>> s1b = AnyNode(id="sub1B", parent=s1, bar=8)
        >>> s1c = AnyNode(id="sub1C", parent=s1)
        >>> s1ca = AnyNode(id="sub1Ca", parent=s1c)
        >>> print(RenderTree(root).by_attr('id'))
        root
        ├── sub0
        │   ├── sub0B
        │   └── sub0A
        └── sub1
            ├── sub1A
            ├── sub1B
            └── sub1C
                └── sub1Ca

        c               3      K   t              r.D ](  }  | j                        }t        | |      E d {    * y D ]-  } t        | j                  d      }t        | |      E d {    / y 7 :7 	w)NrM   )callabler   _format_row_anygetattr)rY   attrattrnamer   s     r   r\   zRenderTree.by_attr.<locals>.getQ  sz     ! :C#CHH-D.sD999:   :C"388Xr:D.sD999: : :s!   2A4A02A4(A2)A42A4r]   r^   )r   ri   r\   s   `` r   by_attrzRenderTree.by_attr6  s    6	: yyr   )r   )name)r   r   r    r!   
CONT_STYLElistr   rB   rA   staticmethodrE   r_   r   rj   r@   r   r   r9   r9      sE    qf $. !*Z $ $ ;
% r   r9   c              #      K   t        |t        t        f      r|xs dg}nt        |      j	                         xs dg}| j
                   |d     |dd  D ]  }| j                   |   y wrV   )r;   rm   tuplestrrX   r   r   )rY   rh   rZ   r[   s       r   rf   rf   ^  sw     $u&D	$$&.2$WWIeAhZ
  ab	 "
4&!!"s   A/A1c              #      K   t        |       }	 t        |      }|}	 	 t        |      }|df |}# t        $ r	 |df Y y w xY w# t        $ r Y y w xY ww)NTF)iternextStopIteration)iterableiter_nextitemitems       r   rG   rG   h  s{     NE; ;Ek! D  ! n$  sG   AA A2 AAAAA	AAAA)r!   collectionsconfigr   
namedtupler   r
   r&   r,   rl   r3   r6   r9   rf   rG   r@   r   r   <module>r}      s     kU$;<   B1 1.T T. [
T] T.T- T0H  H V"r   