ƪb>dZddlZddlZddlmZmZdZdZdZddZ y) z babel.messages.mofile ~~~~~~~~~~~~~~~~~~~~~ Writing of files in the ``gettext`` MO (machine object) format. :copyright: (c) 2013-2022 by the Babel Team. :license: BSD, see LICENSE for more details. N)CatalogMessagel*l$<cVt}i}t|dd}|j}t|}tj }|d|ddd}|t k(r|d|dd\}} } } d } n*|tk(r|d |dd\}} } } d } n tdd |td| D]} || || | d z\}}||z}|| || | d z\}}||z}||kr||kr |||}|||}n tdd||dk(rdx}}|jD]u}|j}|sd|vrI|jdd\}}|jjx}}|j||<c|sf||xxd|zz cc<wd|vr|jd\}}nd}d|vr|jd}|jd}|jr|Dcgc]}|j|j}}|Dcgc]}|j|j}}nB|jr6|j|j}|j|j}t!|||||<| d z } | d z } |j#|_|Scc}wcc}w)aaRead 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. namez4Iz>IIzBad magic numberzFile is corrupt: )context)rgetattrreadlenstructunpackLE_MAGICBE_MAGICOSErrorrange splitlinesstripsplitlowercharsetdecoderitems mime_headers)fileobjcatalogheadersfilenamebufbuflenrmagicversionmsgcountorigidxtransidxiiimlenmoffmendtlentofftendmsgtmsglastkeykeyitemvaluectxtxs 7/usr/lib/python3/dist-packages/babel/messages/mofile.pyread_mor>siGGw+H ,,.C XF ]]F 4Ra !! $E /5eS2Y/G,7H  ( /5eS2Y/G,7H a+X661h -BGGaK 89 dd{BHX\ :; dd{ &=TF]d4.CtD>D!.9 9 19 Gc) 5zz|4 '*ID#D c>))G$C::g&D:=>Qqxx0>>;?@a1@@jj1{{7??3sD$7  1 A [-^#==?G N?@s "J!"J&c t|}|ddDcgc]}|jr|s |js| c}|dd|jdx}}g}|D]}|jrdj |j D cgc]} | j|jc} } g} t|jD]J\} } | s2| j|j tt| d:| j| Ldj | D cgc]} | j|jc} } nJ|j j|j} |jj|j} |jr6dj |jj|j| g} |jt|t| t|t| f|| dzz }|| dzz }ddt|zz}|t|z}g}g}|D]\}}}}||||zgz }||||zgz }||z}|jt!j"dt$d t|ddt|d zzd d t&j&j)t'j&d |z|z|zycc}wcc} wcc} w) aWrite 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 io import BytesIO >>> catalog = Catalog(locale='en_US') >>> catalog.add('foo', 'Voh') >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz')) >>> catalog.add('fuz', 'Futz', flags=['fuzzy']) >>> catalog.add('Fizz', '') >>> catalog.add(('Fuzz', 'Fuzzes'), ('', '')) >>> 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 r NrrIiiiiiirr r.)liststringfuzzysort pluralizablejoinidencoder enumerateappendminintrrwriterpackrarraytobytes)r"r# use_fuzzymessagesmidsstrsoffsetsmessagemsgidmsgstrsidxrEmsgstrkeystart valuestartkoffsetsvoffsetso1l1o2l2s r=write_morgis`G}H'|@!xxYagg@HQRL MMOC$G!   LL;B::"27 W__-"EG(8 + VNN7::c#c(A.>#?@NN6*  + \\=D#39 goo.#FJJ%%goo6E^^**7??;F ??LL'//"8"8"I"'")*EC#e*c$iVEF uw   1!8rCM))HCH$JHH!*BBRh''Rj))*!G MM&++i&!(m##c(ma&77  #(++"5"5ekk#w6O"PQTWWZ^^__@"#s#K%="K* "K/ )F) __doc__rRrbabel.messages.catalogrrrrr>rgr@r=rks/ 3  Qhg_r@