HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/rio.cpython-39.pyc
a

�*�^y1�
@sddlmZddlZddlmZddlmZddlmZGdd�de	�Z
Gd	d
�d
e	�Zd!dd�Zd
d�Z
dd�ZGdd�de	�Zdd�Zdd�Zdd�Zd"dd�Zdd�Zdd�Zzdd lmZmZmZWnDe�yZz*e�e�dd lmZmZmZWYdZ[n
dZ[00dS)#�)�absolute_importN�)�osutils��IterableFile)�	text_typec@seZdZdd�Zdd�ZdS)�	RioWritercCsd|_||_dS�NF)�_soft_nl�_to_file��selfZto_file�r�,/usr/lib/python3/dist-packages/breezy/rio.py�__init__1szRioWriter.__init__cCs(|jr|j�d�|�|j�d|_dS)N�
T)r
r�write)r
�stanzarrr�write_stanza5szRioWriter.write_stanzaN)�__name__�
__module__�__qualname__rrrrrrr/src@s eZdZdZdd�Zdd�ZdS)�	RioReaderz�Read stanzas from a file as a sequence

    to_file can be anything that can be enumerated as a sequence of
    lines (with newlines.)
    cCs
||_dS�N)�
_from_file)r
�	from_filerrrrCszRioReader.__init__ccs"t|j�}|durqq|VqdSr)�read_stanzar)r
�srrr�__iter__Fs
zRioReader.__iter__N)rrr�__doc__rrrrrrr<srcs��fdd�}t|��S)z6Produce a rio IterableFile from an iterable of stanzasc3sJ�dur�dVd}�D]*}|dur,dV|��D]
}|Vq4d}qdS)NrTF)�to_lines)Zfirst_stanzar�line��header�stanzasrr�str_iterQs
zrio_file.<locals>.str_iterr)r$r#r%rr"r�rio_fileOs
r&ccst|�}|durq|VqdSr)r�rrrrr�read_stanzas^sr(ccst|�}|durq|VqdSr)�read_stanza_unicoder'rrr�read_stanzas_unicodegsr*c@s�eZdZdZdgZdd�Zdd�Zedd��Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZeZdd �Zd!d"�Zd#S)$�Stanzaa+One stanza for rio.

    Each stanza contains a set of named fields.

    Names must be non-empty ascii alphanumeric plus _.  Names can be repeated
    within a stanza.  Names are case-sensitive.  The ordering of fields is
    preserved.

    Each field value must be either an int or a string.
    �itemscKs0g|_|r,t|���D]\}}|�||�qdS)zqConstruct a new Stanza.

        The keyword arguments, if any, are added in sorted order to the stanza.
        N)r,�sorted�add)r
�kwargs�tag�valuerrrr~szStanza.__init__cCs`t|�std|f��t|t�r,|�d�}n t|t�r8ntd|t|�f��|j�	||f�dS)z&Append a name and value to the stanza.zinvalid tag %r�asciiz)invalid type for rio value: %r of type %sN)
�	valid_tag�
ValueError�
isinstance�bytes�decoder�	TypeError�typer,�append)r
r0r1rrrr.�s


�z
Stanza.addcCs|�}||_|Sr�r,)�clsZpairsZretrrr�
from_pairs�szStanza.from_pairscCs"|jD]\}}||krdSqdS)z=True if there is any field in this stanza with the given tag.TFr;)r
Zfind_tagr0r1rrr�__contains__�szStanza.__contains__cCs
t|j�S)z%Return number of pairs in the stanza.)�lenr,�r
rrr�__len__�szStanza.__len__cCst|t�sdS|j|jkSr	)r5r+r,�r
�otherrrr�__eq__�s
z
Stanza.__eq__cCs|�|�Sr)rDrBrrr�__ne__�sz
Stanza.__ne__cCs
d|jS)Nz
Stanza(%r)r;r@rrr�__repr__�szStanza.__repr__cCs
t|j�S)z$Return iterator of tag, value pairs.)�iterr,r@rrr�
iter_pairs�szStanza.iter_pairscCs�|js
gSg}|jD]�\}}|�d�}|�d�}|dkrH|�|d�qd|vr�|�d�}|�|d|dd�|dd	�D]}|�d
|d�q�q|�|d|d�q|S)z{Generate sequence of lines for external version of this file.

        The lines are always utf-8 encoded strings.
        r2zutf-8�s: 
rs: rrN�	)r,�encoder:�split)r
�resultZtext_tagZ
text_valuer0r1�	val_linesr!rrrr �s


zStanza.to_linescCsd�|���S)z Return stanza as a single stringrI)�joinr r@rrr�	to_string�szStanza.to_stringcCs�|js
dSg}|jD]�\}}|dkr4|�|d�qd|vr�|�d�}|�|d|dd�|dd�D]}|�d|d�qlq|�|d|d�qd�|�S)	zwReturn stanza as a single Unicode string.

        This is most useful when adding a Stanza to a parent Stanza
        �z: 
�
z: rrN�	)r,r:rLrO)r
rMr0r1rNr!rrr�
to_unicode�s
zStanza.to_unicodecCs|�|���dS)zWrite stanza to a fileN)�
writelinesr rrrrr�szStanza.writecCs,|jD]\}}||kr|Sqt|��dS)z�Return the value for a field wih given tag.

        If there is more than one value, only the first is returned.  If the
        tag is not present, KeyError is raised.
        N)r,�KeyError)r
r0�t�vrrr�get�s
z
Stanza.getcCs*g}|jD]\}}||kr
|�|�q
|Sr)r,r:)r
r0�rrWrXrrr�get_all�s
zStanza.get_allcCs i}|jD]\}}|||<q
|S)zBReturn a dict containing the unique values of the stanza.
        r;)r
�dr0r1rrr�as_dicts
zStanza.as_dictN)rrrr�	__slots__rr.�classmethodr=r>rArDrErFrHr rPrTrrY�__getitem__r[r]rrrrr+ps(


r+cCst|�Sr)�
_valid_tag)r0rrrr3	sr3cCst|�S)a�Return new Stanza read from list of lines or a file

    Returns one Stanza that was read, or returns None at end of file.  If a
    blank line follows the stanza, it is consumed.  It's not an error for
    there to be no blank at end of file.  If there is a blank file at the
    start of the input this is really an empty stanza and that is returned.

    Only the stanza lines and the trailing blank (if any) are consumed
    from the line_iter.

    The raw lines must be in utf-8 encoding.
    )�_read_stanza_utf8��	line_iterrrrr
s
rcCst|�S)a�Read a Stanza from a list of lines or a file.

    The lines should already be in unicode form. This returns a single
    stanza that was read. If there is a blank line at the end of the Stanza,
    it is consumed. It is not an error for there to be no blank line at
    the end of the iterable. If there is a blank line at the beginning,
    this is treated as an empty Stanza and None is returned.

    Only the stanza lines and the trailing blank (if any) are consumed
    from the unicode_iter

    :param unicode_iter: A iterable, yeilding Unicode strings. See read_stanza
        if you have a utf-8 encoded string.
    :return: A Stanza object if there are any lines in the file.
        None otherwise
    )�_read_stanza_unicode)Zunicode_iterrrrr)sr)�Hc	Csz|dkrt|��|d}g}|��D�]N}|�d�dd�D�]4}t�dd|�}t|�dkr<|d|�}||d�}t|�dkr�|dd	�d
gkr�d}|�d
d�}|dkr�|�d
d�}|d	7}|dkr�|�dd�}|dkr�||d�|}|d|�}t|�dk�rd|}t�dd|�}d}t|�dk�r6|d7}nt�d|��rP|d7}d}|�d|d�|rP|�d�qPq<q$|S)awConvert a stanza into RIO-Patch format lines.

    RIO-Patch is a RIO variant designed to be e-mailed as part of a patch.
    It resists common forms of damage such as newline conversion or the removal
    of trailing whitespace, yet is also reasonably easy to read.

    :param max_width: The maximum number of characters per physical line.
    :return: a list of lines
    ��rN����\\s\\\\rr� i����-�/s  �
s\\rF�\s $T�# s#   
)	r4r rL�re�subr?�rfind�searchr:)	rZ	max_widthZ
max_rio_width�linesZpliner!ZpartlineZbreak_indexZ
blank_linerrr�to_patch_lines1sD

rwc#s�dddd���fdd�}d}|D]�}|�d�r<|dd�}n&|�d	�rT|d
d�}ntd|f��|dur�t|�dkr�|dd�}t�dd|�}t�d||�}|dur�|}n||7}|d
d�dkr |Vd}q |dur�|VdS)NrprorI)rjs\rs\
cs�|�d�S)Nr)�group)�match��maprr�mapgetdsz"_patch_stanza_iter.<locals>.mapgetrq��#rzbad line %rs\\(.|
)rir)�
startswithr4r?rrrs)rdr|�	last_liner!rrzr�_patch_stanza_iter_s0�

r�cCstt|��S)a5Convert an iterable of RIO-Patch format lines into a Stanza.

    RIO-Patch is a RIO variant designed to be e-mailed as part of a patch.
    It resists common forms of damage such as newline conversion or the removal
    of trailing whitespace, yet is also reasonably easy to read.

    :return: a Stanza
    )rr�rcrrr�read_patch_stanza~s	r�)rbrera)N)rf)Z
__future__rrrrQrZiterablefilerZsixishr�objectrrr&r(r*r+r3rr)rwr�r�Z_rio_pyxrbrera�ImportError�eZfailed_to_load_extensionZ_rio_pyrrrr�<module>s,

		
.