HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/babel/messages/__pycache__/pofile.cpython-37.pyc
B

�`�V�@s�dZddlmZddlZddlZddlmZmZddlm	Z	ddl
mZmZdd�Z
d	d
�ZGdd�de�ZGd
d�de�ZGdd�de�Zd dd�Ze�d�Zdd�Zd!dd�Zd"dd�Zdd�ZdS)#z�
    babel.messages.pofile
    ~~~~~~~~~~~~~~~~~~~~~

    Reading and writing of files in the ``gettext`` PO (portable object)
    format.

    :copyright: (c) 2013-2021 by the Babel Team.
    :license: BSD, see LICENSE for more details.
�)�print_functionN)�Catalog�Message)�wraptext)�	text_type�cmpcCs"dd�}t�d��||dd��S)z�Reverse `escape` the given string.

    >>> print(unescape('"Say:\\n  \\"hello, world!\\"\\n"'))
    Say:
      "hello, world!"
    <BLANKLINE>

    :param string: the string to unescape
    cSs2|�d�}|dkrdS|dkr"dS|dkr.dS|S)N��n�
�t�	�r�
)�group)�match�m�r�F/opt/alt/python37/lib/python3.7/site-packages/babel/messages/pofile.py�replace_escapes s
z!unescape.<locals>.replace_escapesz\\([\\trn"])r���)�re�compile�sub)�stringrrrr�unescapes

rcCsFd|kr:|��}|�d�r&|dd�}tt|�}d�|�St|�SdS)a�Reverse the normalization done by the `normalize` function.

    >>> print(denormalize(r'''""
    ... "Say:\n"
    ... "  \"hello, world!\"\n"'''))
    Say:
      "hello, world!"
    <BLANKLINE>

    >>> print(denormalize(r'''""
    ... "Say:\n"
    ... "  \"Lorem ipsum dolor sit "
    ... "amet, consectetur adipisicing"
    ... " elit, \"\n"'''))
    Say:
      "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
    <BLANKLINE>

    :param string: the string to denormalize
    r
z""rN�)�
splitlines�
startswith�mapr�join)rZ
escaped_lines�linesrrr�denormalize-s


r!cs eZdZdZ�fdd�Z�ZS)�PoFileErrorzDException thrown by PoParser when an invalid po file is encountered.cs0tt|��dj||d��||_||_||_dS)Nz{message} on {lineno})�message�lineno)�superr"�__init__�format�catalog�liner$)�selfr#r(r)r$)�	__class__rrr&NszPoFileError.__init__)�__name__�
__module__�__qualname__�__doc__r&�
__classcell__rr)r+rr"Lsr"c@speZdZdd�Zdd�Zdd�Zdd�ZeZd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�_NormalizedStringcGs"g|_x|D]}|�|�qWdS)N)�_strs�append)r*�args�argrrrr&Ws
z_NormalizedString.__init__cCs|j�|���dS)N)r2r3�strip)r*�srrrr3\sz_NormalizedString.appendcCsd�tt|j��S)Nr)rrrr2)r*rrrr!_sz_NormalizedString.denormalizecCs
t|j�S)N)�boolr2)r*rrr�__nonzero__bsz_NormalizedString.__nonzero__cCstj�|j�S)N)�os�lineseprr2)r*rrr�__repr__gsz_NormalizedString.__repr__cCs|sdStt|�t|��S)Nr)rr)r*�otherrrr�__cmp__jsz_NormalizedString.__cmp__cCs|�|�dkS)Nr)r>)r*r=rrr�__gt__psz_NormalizedString.__gt__cCs|�|�dkS)Nr)r>)r*r=rrr�__lt__ssz_NormalizedString.__lt__cCs|�|�dkS)Nr)r>)r*r=rrr�__ge__vsz_NormalizedString.__ge__cCs|�|�dkS)Nr)r>)r*r=rrr�__le__ysz_NormalizedString.__le__cCs|�|�dkS)Nr)r>)r*r=rrr�__eq__|sz_NormalizedString.__eq__cCs|�|�dkS)Nr)r>)r*r=rrr�__ne__sz_NormalizedString.__ne__N)r,r-r.r&r3r!r9�__bool__r<r>r?r@rArBrCrDrrrrr1Usr1c@sreZdZdZddddgZddd�Zd	d
�Zdd�Zd
d�Zddd�Z	ddd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�PoFileParserz�Support class to  read messages from a ``gettext`` PO (portable object) file
    and add them to a `Catalog`

    See `read_po` for simple cases.
    �msgid�msgstr�msgctxt�msgid_pluralFcCs*||_||_d|_d|_||_|��dS)Nr)r(�ignore_obsolete�counter�offset�
abort_invalid�_reset_message_state)r*r(rKrNrrrr&�szPoFileParser.__init__cCsFg|_g|_g|_g|_g|_g|_d|_d|_d|_d|_	d|_
dS)NF)�messages�translations�	locations�flags�
user_comments�
auto_comments�context�obsolete�in_msgid�	in_msgstr�
in_msgctxt)r*rrrrO�sz!PoFileParser._reset_message_statec
Cs@|j��t|j�dkr.tdd�|jD��}n|jd��}t|ttf�r�dd�t|j	j
�D�}x<|jD]2\}}||j	j
kr�|�d|jd�qh|��||<qhWt|�}n|jdd��}|j
r�|j
��}nd}t||t|j�t|j�|j|j|jd|d	�}|j�r|j�s&||j	j|<n
||j	|<|jd7_|��dS)
z�
        Add a message to the catalog based on the current parser state and
        clear the state ready to process the next message.
        rcSsg|]}|���qSr)r!)�.0rrrr�
<listcomp>�sz-PoFileParser._add_message.<locals>.<listcomp>rcSsg|]}d�qS)rr)r[�_rrrr\�srz5msg has more translations than num_plurals of catalogN)r$rV)rQ�sort�lenrP�tupler!�
isinstance�list�ranger(�num_plurals�_invalid_pofilerMrVrrR�setrSrUrTrWrKrLrO)r*rGr�idxZtranslationrIr#rrr�_add_message�s2


zPoFileParser._add_messagecCs|jr|��dS)N)rPrh)r*rrr�_finish_current_message�sz$PoFileParser._finish_current_messagecCs*|�d�r|�||�n|�|||�dS)N�")r�!_process_string_continuation_line�_process_keyword_line)r*r$r)rWrrr�_process_message_line�s
z"PoFileParser._process_message_linec	CsHxt|jD]X}y0|�|�r:|t|�dkr:|t|�d�}PWqtk
r^|�||d�YqXqW|�||d�dS|dkr�|��||_|dkr�||_|dkr�d|_d|_	|j
�t|��n�|d	k�r*d|_	d|_
|�d
��r|dd��dd�\}}|j�t|�t|�g�n|j�d
t|�g�n|dk�rDd|_t|�|_dS)N)� �[z$Keyword must be followed by a stringz0Start of line didn't match any expected keyword.)rGrIrG)rGrJFTrHror�]rrI)�	_keywordsrr_�
IndexErrorrerirWrMrZrXrPr3r1rY�splitrQ�intrV)r*r$r)rW�keywordr5rg�msgrrrrl�s8

z"PoFileParser._process_keyword_linecCsV|jr|jd}n6|jr(|jdd}n |jr6|j}n|�||d�dS|�|�dS)Nrrz<Got line starting with " but not in msgid, msgstr or msgctxt)rXrPrYrQrZrVrer3)r*r)r$r7rrrrk�sz.PoFileParser._process_string_continuation_linec	Cs>|��|dd��d�r�x�|dd�����D]p}|�d�}|dkr�yt||dd��}Wntk
rtw0YnX|j�|d|�|f�q0|j�|df�q0Wn�|dd��d�r�x�|dd����d�D]}|j	�|�
��q�WnP|dd��d��r"|dd��
�}|�r:|j�|�n|j�|dd��
��dS)Nr�:�r�,�.)
rir�lstriprs�rfindrt�
ValueErrorrRr3rSr6rUrT)r*r)�location�posr$�flag�commentrrr�_process_comment	s&
zPoFileParser._process_commentcCs�x�t|�D]�\}}|��}t|t�s2|�|jj�}|s8q
|�d�r~|dd��d�rr|j||dd��	�dd�q�|�
|�q
|�||�q
W|��|js�|j
s�|js�|jr�|j�td��|j�d	td�g�|��dS)
z�
        Reads from the file-like object `fileobj` and adds any po file
        units found in it to the `Catalog` supplied to the constructor.
        �#rN�~rxT)rWz""r)�	enumerater6rar�decoder(�charsetrrmr{r�rirLrSrTrUrPr3r1rQrh)r*�fileobjr$r)rrr�parse$s 

zPoFileParser.parsecCsJt|t�st�|jr$t||j||��td|�td�|dt|���dS)NzWARNING:z!WARNING: Problem on line {0}: {1}r)	rar�AssertionErrorrNr"r(�printr'�repr)r*r)r$rvrrrreAs

zPoFileParser._invalid_pofileN)FF)F)F)r,r-r.r/rqr&rOrhrirmrlrkr�r�rerrrrrF�s

#

)rFFcCs*t|||d�}t|||d�}|�|�|S)a�Read messages from a ``gettext`` PO (portable object) file from the given
    file-like object and return a `Catalog`.

    >>> from datetime import datetime
    >>> from babel._compat import StringIO
    >>> buf = StringIO('''
    ... #: main.py:1
    ... #, fuzzy, python-format
    ... msgid "foo %(name)s"
    ... msgstr "quux %(name)s"
    ...
    ... # A user comment
    ... #. An auto comment
    ... #: main.py:3
    ... msgid "bar"
    ... msgid_plural "baz"
    ... msgstr[0] "bar"
    ... msgstr[1] "baaz"
    ... ''')
    >>> catalog = read_po(buf)
    >>> catalog.revision_date = datetime(2007, 4, 1)

    >>> for message in catalog:
    ...     if message.id:
    ...         print((message.id, message.string))
    ...         print(' ', (message.locations, sorted(list(message.flags))))
    ...         print(' ', (message.user_comments, message.auto_comments))
    (u'foo %(name)s', u'quux %(name)s')
      ([(u'main.py', 1)], [u'fuzzy', u'python-format'])
      ([], [])
    ((u'bar', u'baz'), (u'bar', u'baaz'))
      ([(u'main.py', 3)], [])
      ([u'A user comment'], [u'An auto comment'])

    .. versionadded:: 1.0
       Added support for explicit charset argument.

    :param fileobj: the file-like object to read the PO file from
    :param locale: the locale identifier or `Locale` object, or `None`
                   if the catalog is not bound to a locale (which basically
                   means it's a template)
    :param domain: the message domain
    :param ignore_obsolete: whether to ignore obsolete messages in the input
    :param charset: the character set of the catalog.
    :param abort_invalid: abort read if po file is invalid
    )�locale�domainr�)rN)rrFr�)r�r�r�rKr�rNr(�parserrrr�read_poLs/
r�zL(\s+|[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))cCs0d|�dd��dd��dd��dd	��d
d�S)z�Escape the given string so that it can be included in double-quoted
    strings in ``PO`` files.

    >>> escape('''Say:
    ...   "hello, world!"
    ... ''')
    '"Say:\\n  \\"hello, world!\\"\\n"'

    :param string: the string to escape
    z"%s"�\z\\rz\trz\rr
z\nrjz\")�replace)rrrr�escape�s
r�r�Lc
s<|r�|dkr�t��}g}x�|�d�D]�}tt|��||kr�t�|�}|��x�|r�g}d}xX|r�tt|d��d|}	||	|kr�|�|���||	7}q^|s�|�|���Pq^W|�d�|��qPWq$|�|�q$Wn
|�d�}t|�dkr�t|�S|�r |d�s |d=|dd7<dd��fd	d
�|D��S)a�Convert a string into a format that is appropriate for .po files.

    >>> print(normalize('''Say:
    ...   "hello, world!"
    ... ''', width=None))
    ""
    "Say:\n"
    "  \"hello, world!\"\n"

    >>> print(normalize('''Say:
    ...   "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
    ... ''', width=32))
    ""
    "Say:\n"
    "  \"Lorem ipsum dolor sit "
    "amet, consectetur adipisicing"
    " elit, \"\n"

    :param string: the string to normalize
    :param prefix: a string that should be prepended to every line
    :param width: the maximum line width; use `None`, 0, or a negative number
                  to completely disable line wrapping
    rTrxrrrr
z""
csg|]}�t|��qSr)r�)r[r))�prefixrrr\�sznormalize.<locals>.<listcomp>)	r_rr��WORD_SEPrs�reverser3�popr)
rr��widthZ	prefixlenr r)ZchunksZbuf�size�lr)r�r�	normalize�s6


r�Tc
	s�d#�fdd�	���fdd��d$��fdd�	}
d%���fdd	�	}d
}|rLd}n|rTd}�x�t�|d
�D�]�}
|
js�|rvqd�j}�r��dkr�g}x"|��D]}|t|�dd�7}q�Wd�|�}�|d�x|
jD]}|
|�q�Wx|
jD]}|
|dd�q�W|�s�g}yt|
j	dd�d�}Wnt
k
�r6|
j	}YnXxT|D]L\}}|�rp|	�rp|�d|�t
jd�|f�n|�d|�t
jd���q>W|
d�|�dd�|
j�rƈdd�dgt|
j���|
j�r|�r|
d�|
jd�dd�t|
j�d k�r|
d!�|
jd �dd�||
��d�qdW|�s~xJt�j��|d
�D]4}
x|
jD]}|
|��qRW||
d"d��d��qFWd
S)&a�Write a ``gettext`` PO (portable object) template file for a given
    message catalog to the provided file-like object.

    >>> catalog = Catalog()
    >>> catalog.add(u'foo %(name)s', locations=[('main.py', 1)],
    ...             flags=('fuzzy',))
    <Message...>
    >>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)])
    <Message...>
    >>> from babel._compat import BytesIO
    >>> buf = BytesIO()
    >>> write_po(buf, catalog, omit_header=True)
    >>> print(buf.getvalue().decode("utf8"))
    #: main.py:1
    #, fuzzy, python-format
    msgid "foo %(name)s"
    msgstr ""
    <BLANKLINE>
    #: main.py:3
    msgid "bar"
    msgid_plural "baz"
    msgstr[0] ""
    msgstr[1] ""
    <BLANKLINE>
    <BLANKLINE>

    :param fileobj: the file-like object to write to
    :param catalog: the `Catalog` instance
    :param width: the maximum line width for the generated output; use `None`,
                  0, or a negative number to completely disable line wrapping
    :param no_location: do not emit a location comment for every message
    :param omit_header: do not include the ``msgid ""`` entry at the top of the
                        output
    :param sort_output: whether to sort the messages in the output by msgid
    :param sort_by_file: whether to sort the messages in the output by their
                         locations
    :param ignore_obsolete: whether to ignore obsolete messages and not include
                            them in the output; by default they are included as
                            comments
    :param include_previous: include the old msgid as a comment when
                             updating the catalog
    :param include_lineno: include line number in the location comment
    rcst||�d�S)N)r�r�)r�)�keyr�)r�rr�
_normalizeszwrite_po.<locals>._normalizecs&t|t�r|��jd�}��|�dS)N�backslashreplace)rar�encoder��write)�text)r(r�rr�_writes
zwrite_po.<locals>._writecsB�r�dkr�}nd}x&t||�D]}�d||��f�q"WdS)Nrr�z#%s %s
)rr6)r�r�Z_widthr))r�r�rr�_write_comment
s
z write_po.<locals>._write_commentc	st|jttf�r�|jr.�d|�|j|�f��d|�|jd|�f��d|�|jd|�f�x�t�j�D]D}y|j|}Wntk
r�d}YnX�d||�||�f�qrWnT|jrڈd|�|j|�f��d|�|j|�f��d|�|j�pd|�f�dS)	Nz
%smsgctxt %s
z%smsgid %s
rz%smsgid_plural %s
rrz%smsgstr[%d] %s
z%smsgstr %s
)	ra�idrbr`rVrcrdrrr)r#r�rgr)r�r�r(rr�_write_messages(
z write_po.<locals>._write_messageNr#r~)�sort_byrz# )r�Zsubsequent_indentr
rz)r�cSs"|dt|dt�r|dpdfS)Nrrr)rart)�xrrr�<lambda>S�zwrite_po.<locals>.<lambda>)r�z%s:%d�/z%srnrwz#%s
z, zmsgid %s�|rzmsgid_plural %sz#~ )r)r)r)�_sort_messagesr�Zheader_commentrrrrTrU�sortedrR�	TypeErrorr3r�r:�seprSZprevious_idr_rW�values)r�r(r�Zno_locationZomit_headerZsort_outputZsort_by_filerKZinclude_previousZinclude_linenor�r�r�r#Zcomment_headerr r)r�ZlocsrR�filenamer$r)r�r�r(r�r�r�write_po�sp.

r�cCs6t|�}|dkr|��n|dkr2|jdd�d�|S)z�
    Sort the given message iterable by the given criteria.

    Always returns a list.

    :param messages: An iterable of Messages.
    :param sort_by: Sort by which criteria? Options are `message` and `location`.
    :return: list[Message]
    r#r~cSs|jS)N)rR)rrrrr��r�z _sort_messages.<locals>.<lambda>)r�)rbr^)rPr�rrrr�vs

r�)NNFNF)rr�)r�FFFFFFT)r/Z
__future__rr:rZbabel.messages.catalogrrZ
babel.utilrZ
babel._compatrrrr!�	Exceptionr"�objectr1rFr�rr�r�r�r�r�rrrr�<module>s*	/I
5

=