
    -Ph                     0    d Z ddlmZ  G d d          ZdS )a  
Implements a buffer with insertion points. When you know you need to
"get back" to a place and write more later, simply call insertion_point()
at that spot and get a new StringIOTree object that is "left behind".

EXAMPLE:

>>> a = StringIOTree()
>>> _= a.write('first\n')
>>> b = a.insertion_point()
>>> _= a.write('third\n')
>>> _= b.write('second\n')
>>> a.getvalue().split()
['first', 'second', 'third']

>>> c = b.insertion_point()
>>> d = c.insertion_point()
>>> _= d.write('alpha\n')
>>> _= b.write('gamma\n')
>>> _= c.write('beta\n')
>>> b.getvalue().split()
['second', 'alpha', 'beta', 'gamma']

>>> try: from cStringIO import StringIO
... except ImportError: from io import StringIO

>>> i = StringIOTree()
>>> d.insert(i)
>>> _= i.write('inserted\n')
>>> out = StringIO()
>>> a.copyto(out)
>>> out.getvalue().split()
['first', 'second', 'alpha', 'inserted', 'beta', 'gamma', 'third']
    )StringIOc                   P    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZdS )StringIOTreez
    See module docs.
    Nc                 h    g | _         |t                      }|| _        |j        | _        g | _        d S N)prepended_childrenr   streamwritemarkers)selfr	   s     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/StringIOTree.py__init__zStringIOTree.__init__-   s3    "$>ZZF\
    c                     | j                                         rdS | j        rt          d | j        D                       ndS )NFc                 6    g | ]}|                                 S  )empty).0childs     r   
<listcomp>z&StringIOTree.empty.<locals>.<listcomp>8   s     GGGeEKKMMGGGr   T)r	   tellr   allr   s    r   r   zStringIOTree.empty5   sK    ; 	5LPLcmsGGt/FGGGHHHimmr   c                 Z    g }|                      |           d                    |          S )N )_collect_injoin)r   contents     r   getvaluezStringIOTree.getvalue:   s-    !!!wwwr   c                     | j         D ]}|                    |           | j                                        }|r|                    |           d S d S r   )r   r   r	   r   append)r   target_listxstream_contents       r   r   zStringIOTree._collect_in?   sh    ( 	' 	'AMM+&&&&--// 	/~.....	/ 	/r   c                     | j         D ]}|                    |           | j                                        }|r|                    |           dS dS )zUPotentially cheaper than getvalue as no string concatenation
        needs to happen.N)r   copytor	   r   r
   )r   targetr   r$   s       r   r&   zStringIOTree.copytoG   sh     , 	! 	!ELL    --// 	)LL(((((	) 	)r   c                    | j                                         rp| j                            t	          | j                              | j        | j        d         _        g | _        t                      | _         | j         j        | _        d S d S )N)r	   r   r   r!   r   r   r   r
   r   s    r   commitzStringIOTree.commitQ   sy     ; 	+#**<+D+DEEE26,D#B'/DL"**DK*DJJJ	+ 	+r   c                 j    g | _         g | _        t                      | _        | j        j        | _        d S r   )r   r   r   r	   r
   r   s    r   resetzStringIOTree.reset[   s,    "$jj[&


r   c                 b    |                                   | j                            |           dS )z
        Insert a StringIOTree (and all of its contents) at this location.
        Further writing to self appears after what is inserted.
        N)r*   r   r!   )r   iotrees     r   insertzStringIOTree.inserta   s.    
 	&&v.....r   c                 ~    |                                   t                      }| j                            |           |S )a3  
        Returns a new StringIOTree, which is left behind at the current position
        (it what is written to the result will appear right before whatever is
        next written to self).

        Calling getvalue() or copyto() on the result will only return the
        contents written to it.
        )r*   r   r   r!   )r   others     r   insertion_pointzStringIOTree.insertion_pointi   s6     	&&u---r   c                 8    | j         }d |D             | j        z   S )Nc                 @    g | ]}|                                 D ]}|S r   )
allmarkers)r   cms      r   r   z+StringIOTree.allmarkers.<locals>.<listcomp>}   s-    <<<aQ\\^^<<<<<<r   )r   r   )r   childrens     r   r5   zStringIOTree.allmarkersz   s%    *<<8<<<t|KKr   r   )__name__
__module____qualname____doc__r   r   r   r   r&   r*   r,   r/   r2   r5   r   r   r   r   r   (   s            n n n
     
/ / /) ) )+ + +' ' '/ / /  "L L L
+ +r   r   N)r<   ior   r   r   r   r   <module>r>      s`   ! !H      B B B B B B B B B Br   