D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
lib
/
python2.7
/
site-packages
/
babel
/
messages
/
Filename :
mofile.pyc
back
Copy
� 4\0Xc @ so d Z d d l Z d d l Z d d l m Z m Z d d l m Z m Z d Z d Z d � Z e d � Z d S( s� babel.messages.mofile ~~~~~~~~~~~~~~~~~~~~~ Writing of files in the ``gettext`` MO (machine object) format. :copyright: (c) 2013 by the Babel Team. :license: BSD, see LICENSE for more details. i����N( t Catalogt Message( t range_typet array_tobytesI�� I�� c C s] t � } i } t | d d � } | j � } t | � } t j } | d | d � d } | t k r� | d | d d !� \ } } } } d } nI | t k r� | d | d d !� \ } } } } d } n t d d | � � xnt d | � D]]} | | | | | d !� \ } } | | } | | | | | d !� \ } } | | } | | k rx| | k rx| | | !} | | | !} n t d d | � � | d k r<d } } x� | j � D]� } | j � } | s�q�n d | k r| j d d � \ } } | j � j � } } | j � | | <q�| r�| | c d | 7<q�q�Wn d | k r`| j d � \ } } n d } d | k r�| j d � } | j d � } | j rg | D] } | j | j � ^ q�} g | D] } | j | j � ^ q�} qn0 | j r| j | j � } | j | j � } n t | | d | �| | <| d 7} | d 7} q� W| j � | _ | S( sa 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. t namet s <Ii i s <4Ii s <IIs >4Is >IIs Bad magic numberi s File is corruptt :i s s s t contextN( R t getattrt readt lent structt unpackt LE_MAGICt BE_MAGICt IOErrorR t Nonet splitlinest stript splitt lowert charsett decodeR t itemst mime_headers( t fileobjt catalogt headerst filenamet buft buflenR t magict versiont msgcountt origidxt transidxt iit it mlent mofft mendt tlent tofft tendt msgt tmsgt lastkeyt keyt itemt valuet ctxtt x( ( s9 /usr/lib/python2.7/site-packages/babel/messages/mofile.pyt read_mo sh " " %+ c C s� t | � } | s? g | d D] } | j s | ^ q | d )n | j � d } } g } x�| D]�} | j r0d j g | j D] } | j | j � ^ q � } g } xV t | j � D]E \ } } | s� | j | j t t | � d � � q� | j | � q� Wd j g | D] } | j | j � ^ q� } nK | j j | j � } | j sf| j j | j � } n | j j | j � } | j r�d j | j j | j � | g � } n | j t | � t | � t | � t | � f � | | d 7} | | d 7} q` Wd d t | � } | t | � } g } g } xB | D]: \ } } } } | | | | g 7} | | | | g 7} q3W| | } | j t j d t d t | � d d t | � d d d � t t j d | � � | | � d S( s� 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 i R s s i i i t Iiiiiiii i R% Ni i i ( t listt fuzzyt sortt pluralizablet joint idt encodeR t enumeratet stringt appendt mint intR R t writeR t packR R t array( R R t use_fuzzyt messagest mt idst strst offsetst messaget msgidt msgstrst idxR>