
    i'                         S r SSKrSSKJr  \R                  " SS5      r " S S5      r " S	 S
\5      r " S S\5      r\" 5       r	 " S S\5      r
 " S S\5      r " S S5      rS rS rg)z
Tree Rendering.

* :any:`RenderTree` using the following styles:
    * :any:`AsciiStyle`
    * :any:`ContStyle`
    * :any:`ContRoundStyle`
    * :any:`DoubleStyle`
    N   )
ASSERTIONSRow)prefillnodec                   B   ^  \ rS rSrSrU 4S jr\S 5       rS rSr	U =r
$ )AbstractStyle   z
Tree Render Style.

Args:

    vertical: Sign for vertical line.

    cont: Chars for a continued branch.

    end: Chars for the last branch.
c                    > [         TU ]  5         Xl        X l        X0l        [
        (       a<  [        U5      [        U5      s=:X  a  [        U5      :X  d  O   SU SU SU S35       eg g )N'z', 'z' and 'z' need to have equal length)super__init__verticalcontendr   len)selfr   r   r   	__class__s       ;/app/mltbenv/lib/python3.13/site-packages/anytree/render.pyr   AbstractStyle.__init__   sf     	:t9H9S9 H:T$wse3NO9     c                 2    S[        U R                  5      -  $ )zEmpty string as placeholder. )r   r   r   s    r   emptyAbstractStyle.empty)   s     S]""r   c                 8    U R                   R                  nU S3$ )Nz())r   __name__)r   	classnames     r   __repr__AbstractStyle.__repr__.   s    NN++	Br   )r   r   r   )r   
__module____qualname____firstlineno____doc__r   propertyr   r!   __static_attributes____classcell__r   s   @r   r
   r
      s+    
 # #   r   r
   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
AsciiStyle3   a  
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U ]  SSS5        g )Nz|   z|-- z+-- r   r   r   r   s    r   r   AsciiStyle.__init__F   s    0r    r   r#   r$   r%   r&   r   r(   r)   r*   s   @r   r,   r,   3   s    $1 1r   r,   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )	ContStyleJ   u  
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U ]  SSS5        g )N   │   
   ├── u
   └── r/   r0   s    r   r   ContStyle.__init__]       &;=RSr   r2   r3   r*   s   @r   r5   r5   J       $T Tr   r5   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )ContRoundStyled   u  
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U ]  SSS5        g )Nr8   r9   u
   ╰── r/   r0   s    r   r   ContRoundStyle.__init__w   r;   r   r2   r3   r*   s   @r   r>   r>   d   r<   r   r>   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )DoubleStyle{   u  
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U ]  SSS5        g )Nu   ║   u
   ╠══ u
   ╚══ r/   r0   s    r   r   DoubleStyle.__init__   r;   r   r2   r3   r*   s   @r   rC   rC   {   s    &T Tr   rC   c                   ^    \ rS rSrSr\\S4S jrS rSS jr	\
S 5       rS rS	 rSS
 jrSrg)
RenderTree   u	  
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                 l    [        U[        5      (       d  U" 5       nXl        X l        X0l        X@l        g )N)
isinstancer
   r   style	childitermaxlevel)r   r   rL   rM   rN   s        r   r   RenderTree.__init__  s*    %//GE	
" r   c                 :    U R                  U R                  S5      $ )Nr2   )_RenderTree__nextr   r   s    r   __iter__RenderTree.__iter__  s    {{499b))r   c              #   P  #    [         R                  XU R                  5      v   US-  nU R                  b  X0R                  :  a]  UR                  nU(       aI  U R                  U5      n[        U5       H(  u  pVU R                  U/ UQU(       + P7US9 S h  vN   M*     g g g  N7f)Nr   )level)rH   _RenderTree__itemrL   rN   childrenrM   _is_lastrQ   )r   r   	continuesrU   rW   childis_lasts          r   __nextRenderTree.__next  s     <<
== EMM$9}}H>>(3&.x&8NE#{{52KI2K7{2KSX{YYY '9  %:
 Zs   BB&B$B&c                 >   U(       d  [        SSU 5      $ U Vs/ s H!  o3(       a  UR                  OUR                  PM#     nnSR                  US S 5      nUS   (       a  UR                  OUR
                  nXV-   nSR                  U5      n[        XxU 5      $ s  snf )N )r   r   r   joinr   r   )	r   rY   rL   r   itemsindentbranchr   r   s	            r   __itemRenderTree.__item  s    r2t$$ENOYT4U[[8YOs$(}%))owwu~3d## Ps   (Bc                 <   ^  U 4S jnSR                  U" 5       5      $ )Nc               3      >#    T Hc  n [        U R                  5      R                  5       =(       d    S/nU R                   US    3v   USS   H  nU R                   U 3v   M     Me     g 7fNr_   r   r   )reprr   
splitlinesr   r   )rowlinesliner   s      r   getRenderTree.__str__.<locals>.get(  sg     SXX113;t	%(,,!!"ID XXJtf-- & s   A+A.
ra   )r   ro   s   ` r   __str__RenderTree.__str__'  s    	. yyr   c                     U R                   R                  n[        U R                  5      SU R                  < 3SU R
                  < 3/nSR                  USR                  U5      5      $ )Nzstyle=z
childiter=z{}({})z, )r   r   rj   r   rL   rM   formatra   )r   r    argss      r   r!   RenderTree.__repr__1  sU    NN++	TYY6$**!8Jt~~FX:YZy$))D/::r   c                 @   ^ ^ UU 4S jnSR                  U" 5       5      $ )u  
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      >#    [        T5      (       a/  T H(  n T" U R                  5      n[        X5       S h  vN   M*     g T H-  n [        U R                  TS5      n[        X5       S h  vN   M/     g  N= N7f)Nr_   )callabler   _format_row_anygetattr)rl   attrattrnamer   s     r   ro   RenderTree.by_attr.<locals>.getQ  sm     !!C#CHH-D.s999    C"388Xr:D.s999   : :s!   6A;A73A;-A9.
A;9A;rq   rr   )r   r   ro   s   `` r   by_attrRenderTree.by_attr6  s    6	: yyr   )rM   rN   r   rL   )r   )name)r   r#   r$   r%   r&   
CONT_STYLElistr   rR   rQ   staticmethodrV   rs   r!   r   r(   r2   r   r   rH   rH      sE    qf $. !*Z $ $ ;
% r   rH   c              #     #    [        U[        [        45      (       a  U=(       d    S/nO#[        U5      R	                  5       =(       d    S/nU R
                   US    3v   USS   H  nU R                   U 3v   M     g 7fri   )rK   r   tuplestrrk   r   r   )rl   r~   rm   rn   s       r   r|   r|   ^  st     $u&&D	$$&.2$WWIeAhZ
  ab	
4&!! s   B Bc              #      #    [        U 5      n [        U5      nUn  [        U5      nUS4v   UnM  ! [         a	    US4v    g f = f! [         a     g f = f7f)NTF)iternextStopIteration)iterableiter_nextitemitems       r   rX   rX   h  sz     NE; ;Ek! D  ! n$  sG   AA	 A3 AAAAA	
AAAA)r&   collectionsconfigr   
namedtupler   r
   r,   r5   r   r>   rC   rH   r|   rX   r2   r   r   <module>r      s     U$;<   B1 1.T T. [
T] T.T- T0H  H V"r   