관리-도구
편집 파일: mofile.cpython-39.opt-1.pyc
a �����`$����������������������@���sR���d�Z�ddlZddlZddlmZmZ�ddlmZmZ�dZ dZ dd��Zdd d�ZdS�) z� babel.messages.mofile ~~~~~~~~~~~~~~~~~~~~~ Writing of files in the ``gettext`` MO (machine object) format. :copyright: (c) 2013-2021 by the Babel Team. :license: BSD, see LICENSE for more details. �����N)�Catalog�Message)� range_type� array_tobytesl����*�l����$<�c��������������������sn��t�����i�}t|�dd�}|����}t|�}tj}|d|dd���d�}|tkrj|d|dd���\}}} } d }n4|tkr�|d |dd���\}}} } d}ntdd|��t d|�D��]�}|||| | d ����\} }|| �}|||| | d ����\}}||�}||k��r ||k��r |||��}|||��}ntdd|��| dk�r�d�}}|� ��D�]j}|���}|�s\�qFd|v��r�|�dd�\}}|���� ���}}|���||<�n|�rF||��d|�7��<��qFd|v��r�|�d�\}}nd}d|v��r|�d�}|�d�}��j�r<��fdd�|D��}��fdd�|D��}n ��j�r<|���j�}|���j�}t|||d���|<�| d 7�} | d 7�} q�|�����_��S�)aa��Read a binary MO file from the given file-like object and return a corresponding `Catalog` object. :param fileobj: the file-like object to read the MO file from :note: The implementation of this function is heavily based on the ``GNUTranslations._parse`` method of the ``gettext`` module in the standard library. �name��z<IN����r���z<4I����z<IIz>4Iz>IIzBad magic number����zFile is corrupt����:�������� ���������c��������������������s���g�|�]}|����j��qS�����decode�charset��.0�x��catalogr����9/usr/lib/python3.9/site-packages/babel/messages/mofile.py� <listcomp>[��������zread_mo.<locals>.<listcomp>c��������������������s���g�|�]}|����j��qS�r���r���r���r���r���r���r���\���r���)�context)r����getattr�read�len�struct�unpack�LE_MAGIC�BE_MAGIC�IOErrorr���� splitlines�strip�split�lowerr���r���r����itemsZmime_headers)�fileobjZheaders�filename�buf�buflenr!����magic�version�msgcountZorigidx�transidx�ii�i�mlen�moff�mend�tlen�toff�tend�msg�tmsgZlastkey�key�item�valueZctxtr���r���r����read_mo���sh���� r?���Fc��������������������s���t����}�fdd�|dd��D��|dd�<�|����d�}}g�}|D�]�}|jr�d���fdd�|jD���}g�} t|j�D�]2\} }|s�| �|jtt | �d����qt| �|��qtd���fdd�| D���}n|j� ��j�}|j� ��j�}|jr�d �|j� ��j�|g�}|�t |�t |�t |�t |�f��||d�7�}||d�7�}qBd dt |���} | t |��}g�}g�}|D�].\}}}}|||| �g7�}||||�g7�}�q`||�}|��t�dtd t |�d d t |�d��d d �tt�d|���|�|���dS�)a���Write a catalog to the specified file-like object using the GNU MO file format. >>> import sys >>> from babel.messages import Catalog >>> from gettext import GNUTranslations >>> from babel._compat import BytesIO >>> catalog = Catalog(locale='en_US') >>> catalog.add('foo', 'Voh') <Message ...> >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz')) <Message ...> >>> catalog.add('fuz', 'Futz', flags=['fuzzy']) <Message ...> >>> catalog.add('Fizz', '') <Message ...> >>> catalog.add(('Fuzz', 'Fuzzes'), ('', '')) <Message ...> >>> buf = BytesIO() >>> write_mo(buf, catalog) >>> x = buf.seek(0) >>> translations = GNUTranslations(fp=buf) >>> if sys.version_info[0] >= 3: ... translations.ugettext = translations.gettext ... translations.ungettext = translations.ngettext >>> translations.ugettext('foo') u'Voh' >>> translations.ungettext('bar', 'baz', 1) u'Bahr' >>> translations.ungettext('bar', 'baz', 2) u'Batz' >>> translations.ugettext('fuz') u'fuz' >>> translations.ugettext('Fizz') u'Fizz' >>> translations.ugettext('Fuzz') u'Fuzz' >>> translations.ugettext('Fuzzes') u'Fuzzes' :param fileobj: the file-like object to write to :param catalog: the `Catalog` instance :param use_fuzzy: whether translations marked as "fuzzy" should be included in the output c��������������������s ���g�|�]}|j�r��s|js|�qS�r���)�stringZfuzzy)r����m)� use_fuzzyr���r���r�������s����zwrite_mo.<locals>.<listcomp>r���Nr���r���c��������������������s���g�|�]}|����j��qS�r�����encoder���)r����msgidr���r���r���r�������s���c��������������������s���g�|�]}|����j��qS�r���rC���)r����msgstrr���r���r���r�������s���r�����������ZIiiiiiir���r ���r3���)�list�sortZpluralizable�join�id� enumerater@����append�min�intrD���r���r���r����writer ����packr"���r����array)r*���r���rB����messagesZidsZstrsZoffsets�messagerE���Zmsgstrs�idxr@���rF���ZkeystartZ valuestartZkoffsetsZvoffsetsZo1�l1Zo2�l2r���)r���rB���r����write_mok���sb����0"�� �" ����rY���)F) �__doc__rS���r ���Zbabel.messages.catalogr���r���Z babel._compatr���r���r"���r#���r?���rY���r���r���r���r����<module>���s��� T