kfUdZddlmZddlZddlZddlmZddlmZm Z erddl m Z m Z dZ ded <d Zded <ddZdddZdS)z babel.messages.mofile ~~~~~~~~~~~~~~~~~~~~~ Writing of files in the ``gettext`` MO (machine object) format. :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details. ) annotationsN) TYPE_CHECKING)CatalogMessage) SupportsRead SupportsWritel*intLE_MAGICl$<BE_MAGICfileobjSupportsRead[bytes]returnrcti}t|dd}|}t|}tj}|d|ddd}|t kr|d|dd\}}} } d } n8|tkr|d |dd\}}} } d } ntdd |t|D]} || || | d z\} }|| z}|| || | d z\}}||z}||kr||kr|||}|||}ntdd|| dkrdx}}| D]}| }|sd|vrY| dd\}}| x}}| ||<v|r||xxd|zz cc<d|vr| d\}}nd}d|vrN| d}| d}jrfd|D}fd|D}n;jr4|j}|j}t!||||<| d z } | d z } |_S)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: cDg|]}|jSdecodecharset.0xcatalogs u/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/babel/messages/mofile.py zread_mo..]s'>>>Qqxx00>>>cDg|]}|jSrrrs r#r$zread_mo..^s'@@@a11@@@r%)context)rgetattrreadlenstructunpackr r OSErrorrange splitlinesstripsplitlowerrrritems mime_headers)r headersfilenamebufbuflenr,magicversionmsgcountorigidxtransidxii_imlenmoffmendtlentofftendmsgtmsglastkeykeyitemvaluectxtr"s @r#read_morMsNiiGGw++H ,,..C XXF ]F F4RaR ! !! $E /5veS2Y/G/G,7H  (  /5veS2Y/G/G,7H a+X666Hoo--VBGGaK$7 899 dd{VBHX\$9 :;; dd{ &==TF]]d4i.CtDy>DD!.99 9 199 Gc)) 5 5zz||4<> '**ID##D c>>))G$$C::g&&D A>>>>#>>>@@@@4@@@ 4jj11{{7?33sD$777  1 A "==??G Nr%FSupportsWrite[bytes]r" use_fuzzyboolNonec |t}fd|ddD|dd<|dx}}g}|D]}|jrdfd|jD}g} t |jD]X\} } | s<| |jtt| dC| | Ydfd| D} n>|j j }|j j } |j r4d|j j |g}|t|t|t|t| f||dzz }|| dzz }d d t|zz} | t|z}g}g}|D]\}}}}|||| zgz }||||zgz }||z}|tjd t"d t|d d t|d zzd d t$jt%jd|z|z|zdS)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 c4g|]}|j s|j|Sr)stringfuzzy)r mrOs r#r$zwrite_mo..sJ@@@!x@%.@67g@A@@@r%rNr%rcDg|]}|jSrencoder)r msgidr"s r#r$zwrite_mo..s4"""27 W_--"""r%cDg|]}|jSrrX)r msgstrr"s r#r$zwrite_mo..s4###39 go..###r%rIiiiiiirri)listsort pluralizablejoinid enumeraterTappendminr rYrr'r*writer+packr arraytobytes)r r"rOmessagesidsstrsoffsetsmessagerZmsgstrsidxrTr\keystart valuestartkoffsetsvoffsetso1l1o2l2s `` r#write_mor|msB`G}}H@@@@x|@@@HQRRL MMOOOC$G!!   <LL"""";B:"""EG(88 + + V+NN7:c#c((A.>.>#?@@@@NN6****\\####=D###FFJ%%go66E^**7?;;F ? *LL'/"8"8"I"I"'")**EC#e**c$iiVEFFF uw   rCMM))HCHH$JHH!**BBRh''Rj))!G MM&+i&!(mm##c(mma&77   #(+"5"5ek#w6O6O"P"PQTWWZ^^_____r%)r r rr)F)r rNr"rrOrPrrQ)__doc__ __future__rrkr+typingrbabel.messages.catalogrr _typeshedrrr __annotations__r rMr|rr%r#rs#""""" 33333333655555555QQQQhg_g_g_g_g_g_g_r%