Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/StringIOTree.cpython-35.pyc



Z��Z��@sidZddlmZyddlmZWn"ek
rNddlmZYnXGdd�de�ZdS)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']

>>> i = StringIOTree()
>>> d.insert(i)
>>> _= i.write('inserted\n')
>>> out = StringIO()
>>> a.copyto(out)
>>> out.getvalue().split()
['first', 'second', 'alpha', 'inserted', 'beta', 'gamma', 'third']
�)�absolute_import)�StringIOc@smeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�StringIOTreez
    See module docs.
    NcCs@g|_|dkrt�}||_|j|_g|_dS)N)�prepended_childrenr�stream�write�markers)�selfr�r
�F/opt/alt/python35/lib64/python3.5/site-packages/Cython/StringIOTree.py�__init__/s			zStringIOTree.__init__cCs9dd�|jD�}|j|jj��dj|�S)NcSsg|]}|j��qSr
)�getvalue)�.0�xr
r
r�
<listcomp>8s	z)StringIOTree.getvalue.<locals>.<listcomp>�)r�appendrr
�join)r	�contentr
r
rr
7szStringIOTree.getvaluecCsGx|jD]}|j|�q
W|jj�}|rC|j|�dS)zUPotentially cheaper than getvalue as no string concatenation
        needs to happen.N)r�copytorr
r)r	�target�childZstream_contentr
r
rr<s
zStringIOTree.copytocCsc|jj�r_|jjt|j��|j|jd_g|_t�|_|jj|_dS)N����)r�tellrrrrrr)r	r
r
r�commitEs	zStringIOTree.commitcCs|j�|jj|�dS)z�
        Insert a StringIOTree (and all of its contents) at this location.
        Further writing to self appears after what is inserted.
        N)rrr)r	Ziotreer
r
r�insertOs
zStringIOTree.insertcCs'|j�t�}|jj|�|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.
        )rrrr)r	�otherr
r
r�insertion_pointWs
	zStringIOTree.insertion_pointcCs!|j}dd�|D�|jS)NcSs)g|]}|j�D]}|�qqSr
)�
allmarkers)r�c�mr
r
rrjs	z+StringIOTree.allmarkers.<locals>.<listcomp>)rr)r	�childrenr
r
rrhs	zStringIOTree.allmarkers)�__name__�
__module__�__qualname__�__doc__rr
rrrrrr
r
r
rr*s	
rN)	r&�
__future__r�	cStringIOr�ImportError�io�objectrr
r
r
r�<module>s