3
HXM @ s d Z ddlmZ ddlZddlZddlmZmZ ddlm Z ddl
mZ dd Zd d
Z
G dd deZG d
d deZdddZejdZdd ZdddZd ddZdd ZdS )!z
babel.messages.pofile
~~~~~~~~~~~~~~~~~~~~~
Reading and writing of files in the ``gettext`` PO (portable object)
format.
:copyright: (c) 2013 by the Babel Team.
:license: BSD, see LICENSE for more details.
)print_functionN)CatalogMessage)wraptext) text_typec C s" dd }t jdj|| dd S )zReverse `escape` the given string.
>>> print(unescape('"Say:\\n \\"hello, world!\\"\\n"'))
Say:
"hello, world!"
:param string: the string to unescape
c S s2 | j d}|dkrdS |dkr"dS |dkr.dS |S )N n
t r
)group)matchm r /usr/lib/python3.6/pofile.pyreplace_escapes s
z!unescape..replace_escapesz\\([\\trn"])r )recompilesub)stringr r r r unescape s
r c C sF d| kr:| j }| jdr&|dd }tt|}dj|S t| S dS )a Reverse the normalization done by the `normalize` function.
>>> print(denormalize(r'''""
... "Say:\n"
... " \"hello, world!\"\n"'''))
Say:
"hello, world!"
>>> print(denormalize(r'''""
... "Say:\n"
... " \"Lorem ipsum dolor sit "
... "amet, consectetur adipisicing"
... " elit, \"\n"'''))
Say:
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
:param string: the string to denormalize
r z""r N )
splitlines
startswithmapr join)r Z
escaped_lineslinesr r r denormalize- s
r c @ s, e Zd Zdd Zdd Zdd Zdd Zd S )
_NormalizedStringc G s" g | _ x|D ]}| j| qW d S )N)_strsappend)selfargsargr r r __init__N s
z_NormalizedString.__init__c C s | j j|j d S )N)r" r# strip)r$ sr r r r# S s z_NormalizedString.appendc C s dj tt| jS )Nr )r r r r" )r$ r r r r V s z_NormalizedString.denormalizec C s
t | jS )N)boolr" )r$ r r r __nonzero__Y s z_NormalizedString.__nonzero__N)__name__
__module____qualname__r' r# r r+ r r r r r! L s r! c @ sr e Zd ZdZddddgZdddZd d
Zdd Zd
d ZdddZ dddZ
dd Zdd Zdd Z
dd ZdS )PoFileParserzSupport class to read messages from a ``gettext`` PO (portable object) file
and add them to a `Catalog`
See `read_po` for simple cases.
msgidmsgstrmsgctxtmsgid_pluralFc C s$ || _ || _d| _d| _| j d S )Nr )catalogignore_obsoletecounteroffset_reset_message_state)r$ r4 r5 r r r r' k s
zPoFileParser.__init__c C sF g | _ g | _g | _g | _g | _g | _d | _d| _d| _d| _ d| _
d S )NF)messagestranslations locationsflags
user_comments
auto_commentscontextobsoletein_msgid in_msgstr
in_msgctxt)r$ r r r r8 r s z!PoFileParser._reset_message_statec
C s@ | j j t| jdkr.tdd | jD }n| jd j }t|ttfrdd t| j j
D }x<| j D ]2\}}|| j j
kr| jd| jd qh|j ||<