U e5dj@sdZddlZddlZddlZddlZddddddd d d d d ddddddddddgZejejddZ e dej ej BZ ddZddZdZd d!eed"DZd#d$d%d&ZdGd(d)Zd*d+Zd,d-Zd.d/ZGd0ddZGd1ddeZdHd3dZiZd4gZdddd2efd5dZdedfd6dZiaiad7a dId8d Z!dJd9d Z"dKd:d Z#d;d Z$ddZ'd?dZ(d@dZ)dAdZ*dBdZ+dCdZ,dDdZ-dEdZ.dFdZ/eZ0dS)LaInternationalization and localization support. This module provides internationalization (I18N) and localization (L10N) support for your Python programs by providing an interface to the GNU gettext message catalog library. I18N refers to the operation by which a program is made aware of multiple languages. L10N refers to the adaptation of your program, once internationalized, to the local language and cultural habits. NNullTranslationsGNUTranslationsCatalogfind translationinstall textdomainbindtextdomainbind_textdomain_codesetdgettext dngettextgettextlgettext ldgettext ldngettext lngettextngettextpgettext dpgettext npgettext dnpgettextZsharelocalea (?P[ \t]+) | # spaces and horizontal tabs (?P[0-9]+\b) | # decimal integer (?Pn\b) | # only n is allowed (?P[()]) | (?P[-*/%+?:]|[>, # <=, >=, ==, !=, &&, ||, # ? : # unary and bitwise ops # not allowed (?P\w+|.) # invalid token ccsPtt|D]8}|j}|dkr q ||}|dkr>td||Vq dVdS)NZ WHITESPACESZINVALIDz invalid token in plural form: %s)refinditer_token_pattern lastgroupgroup ValueError)pluralZmoZkindvaluer!/usr/lib64/python3.8/gettext.py _tokenizeWs  r#cCs|rtd|StdSdS)Nz#unexpected token in plural form: %szunexpected end of plural form)r)r r!r!r"_errorbs r$))||)&&)z==z!=)<>z<=z>=)+-)*/%cCs i|]\}}|D] }||qqSr!r!).0iZopsopr!r!r" ps r1orandz//)r%r&r,c Csd}t|}|dkr&|d7}t|}q |dkrXt|\}}d||f}|dkrtdnP|dkrnd ||f}n:zt|d }Wntk rt|dYnXd ||f}t|}d }|tkrt|}||krҐq|d kr|d krd|}t||}t||d\} }d||| f}|}q||kr4dkr@nnd|}|dkr|dkrt|d\} }|dkrtt|t|\} }d| || f}|dkrd|}||fS)Nr!znot (z%s(%s))z%unbalanced parenthesis in plural formnz%s%s z%s%dd)z(%s)r2z%s %s %sr=?r:z%s if %s else %s)next_parserintr$ _binary_ops _c2py_opsget) tokensZpriorityresultnexttoksubr jr/r0rightZif_trueZif_falser!r!r"rAssP          rAcCsZz t|}Wn(tk r4td|jjfdYnXddl}|d|jjftd|S)Nz'Plural value must be an integer, got %srr=)round TypeError __class____name__warningswarnDeprecationWarning)r9r/rPr!r!r"_as_ints  rScCst|dkrtdz|tt|\}}|r2t|d}|D]6}|dkr`|d7}|dkrptdq:|dkr:|d8}q:d ti}td |||d WStk rtdYnXd S) zGets a C expression as used in PO files for plural forms and returns a Python function that implements an equivalent expression. iz"plural form expression is too longrr7r2z%plural form expression is too complexr8rSzif True: def func(n): if not isinstance(n, int): n = _as_int(n) return int(%s) funcN)lenrrAr#r$rSexecRecursionError)rrGrHZdepthcnsr!r!r"c2pys.    r[c Cs4t|}d}d}d}d}|d}|dkrN||d}|d|}||O}nd}|d}|dkr||d}|d|}||O}nd}|d}|dkr||d}|d|}||O}nd}|} g} t|dD]P} | |@s| } | |@r| |7} | |@r | |7} | |@r| |7} | | q| | S) Nr2r=r@r._)rZ normalizerrangeappendreverse) ZlocZCOMPONENT_CODESETZCOMPONENT_TERRITORYZCOMPONENT_MODIFIERmaskposZmodifiercodesetZ territoryZlanguageZretr/valr!r!r" _expand_langsJ                 rgc@seZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZdddZdS) rNcCs.i|_d|_d|_d|_|dk r*||dSN)_info_charset_output_charset _fallbackrAselffpr!r!r"__init__s zNullTranslations.__init__cCsdSrhr!rmr!r!r"rAszNullTranslations._parsecCs|jr|j|n||_dSrh)rl add_fallback)rnfallbackr!r!r"rq szNullTranslations.add_fallbackcCs|jr|j|S|Srh)rlr )rnmessager!r!r"r s zNullTranslations.gettextc Csrddl}|dtd|jrR|(|ddt|j|W5QRSQRX|jrd||jS|t S)Nr/lgettext() is deprecated, use gettext() insteadr\ignore.*\blgettext\b.*) rPrQrRrlcatch_warningsfilterwarningsrrkencodergetpreferredencoding)rnrsrPr!r!r"rs  zNullTranslations.lgettextcCs*|jr|j|||S|dkr"|S|SdSNr2)rlr)rnmsgid1msgid2r9r!r!r"r"s zNullTranslations.ngettextc Csddl}|dtd|jrV|,|ddt|j|||W5QRSQRX|dkrd|}n|}|jrz||jS|t S)Nr1lngettext() is deprecated, use ngettext() insteadr\ru.*\blngettext\b.*r2) rPrQrRrlrwrxrrkryrrzrnr|r}r9rPtmsgr!r!r"r*s" " zNullTranslations.lngettextcCs|jr|j||S|Srh)rlr)rncontextrsr!r!r"r;szNullTranslations.pgettextcCs,|jr|j||||S|dkr$|S|SdSr{)rlr)rnrr|r}r9r!r!r"r@s zNullTranslations.npgettextcCs|jSrh)rirnr!r!r"infoHszNullTranslations.infocCs|jSrh)rjrr!r!r"charsetKszNullTranslations.charsetcCsddl}|dtd|jS)Nrzoutput_charset() is deprecatedr\rPrQrRrk)rnrPr!r!r"output_charsetNs zNullTranslations.output_charsetcCs ddl}|dtd||_dS)Nrz"set_output_charset() is deprecatedr\r)rnrrPr!r!r"set_output_charsetTs z#NullTranslations.set_output_charsetcCsRddl}|j|jd<|dk rNddddddh}|t|@D]}t|||j|<q8dS) Nrr_r rrrrr)builtinsr __dict__setgetattr)rnnamesrZallowednamer!r!r"rZs zNullTranslations.install)N)N)rO __module__ __qualname__rprArqr rrrrrrrrrrr!r!r!r"rs  c@s\eZdZdZdZdZdZddZddZd d Z d d Z d dZ ddZ ddZ ddZdS)rl*l$<z%s%s)rr2cCs|d?|d@fS)z/Returns a tuple of major version, minor versionir!)rnversionr!r!r" _get_versionspszGNUTranslations._get_versionsc"Csddlm}t|dd}i|_}dd|_|}t|}|d|dd d}||jkr||d |d d \}} } } d } n6||jkr|d |d d \}} } } d} n t dd|| |\} }| |j krt ddt | |t d| D]}|| || | d\}}||}|| || | d\}}||}||kr`||kr`|||}|||}n t dd||dkrld}|dD]}|}|sq|dr|drqd}}d|kr|dd\}}|}|}||j|<|}n|r|j|d|7<|dkr8|dd|_n0|dkr|d}|ddd}t||_q|jpvd}d|kr|d\}} |d}t ||}t|D]\}}!t |!||||f<qnt |||t ||<| d7} | d7} qdS)z8Override this method to support alternative .mo formats.r)unpackrrcSs t|dkSr{)rB)r9r!r!r"}z(GNUTranslations._parse..z4Iz>IIzBad magic numberzBad version number zFile is corrupt z #-#-#-#-#r?r2 z content-typezcharset=z plural-forms;zplural=ascii)Zstructrr_catalogrreadrVLE_MAGICBE_MAGICOSErrorrVERSIONSstrr`splitdecodestrip startswithendswithlowerrirjr[ enumerate)"rnrorfilenameZcatalogZbufZbuflenmagicrZmsgcountZ masteridxZtransidxZiiZ major_versionZ minor_versionr/ZmlenZmoffZmendZtlenZtoffZtendmsgrZlastkZb_itemitemkvrrr|r}xr!r!r"rAtsv                      zGNUTranslations._parsecCshddl}|dtdt}|j||}||krH|jrD|j|S|}|jrZ| |jS| t S)Nrrtr\) rPrQrRobjectrrErlrrkryrrz)rnrsrPmissingrr!r!r"rs  zGNUTranslations.lgettextcCsddl}|dtdz|j|||f}Wn@tk rn|jrX|j|||YS|dkrf|}n|}YnX|jr| |jS| t S)Nrr~r\r2) rPrQrRrrKeyErrorrlrrkryrrzrr!r!r"rs   zGNUTranslations.lngettextcCs6t}|j||}||kr2|jr.|j|S|S|Srh)rrrErlr )rnrsrrr!r!r"r s zGNUTranslations.gettextcCs^z|j|||f}Wn@tk rX|jrB|j|||YS|dkrP|}n|}YnX|Sr{)rrrrlr)rnr|r}r9rr!r!r"rs zGNUTranslations.ngettextcCsF|j||f}t}|j||}||krB|jr>|j||S|S|Srh)CONTEXTrrrErlr)rnrrs ctxt_msg_idrrr!r!r"rszGNUTranslations.pgettextc Csn|j||f}z|j|||f}WnBtk rh|jrR|j||||YS|dkr`|}n|}YnX|Sr{)rrrrrlr)rnrr|r}r9rrr!r!r"r s zGNUTranslations.npgettextN)rOrrrrrrrrArrr rrrr!r!r!r"rdsY   Fc Cs|dkr t}|dkrRg}dD]"}tj|}|r|d}q@qd|krR|dg}|D]$}t|D]}||krf||qfqZ|rg} nd} |D]J}|dkrqtj||dd|} tj | r|r| | q| Sq| S)N)ZLANGUAGELC_ALL LC_MESSAGESZLANGr?Crz%s.mo) _default_localedirosenvironrErrargpathjoinexists) domain localedir languagesallZenvarrfZnelangsZlangZnelangrGmofiler!r!r"rs8       Z unspecifiedc Cs|dkr t}t|||dd}|sB|r*tSddlm}t|d|d}|D]} |tj| f} t | } | dkrt | d} t | || } W5QRXddl } | | } |tk rddl}|dtd|r||d d t| |W5QRX|dkr| }qJ|| qJ|S) NT)rr)ENOENTz$No translation file found for domainrbzparameter codeset is deprecatedr\ruz.*\bset_output_charset\b.*)rrrerrnorFileNotFoundErrorrrabspath _translationsrEopen setdefaultcopy _unspecifiedrPrQrRrwrxrrq)rrrZclass_rrreZmofilesrrGrkeytrorrPr!r!r"rCsH       cCst||d|d}||dS)NT)rrre)rr)rrrerrr!r!r"rnsZmessagescCs|dk r |atSrh)_current_domain)rr!r!r"r|scCs|dk r|t|<t|tSrh) _localedirsrEr)rrr!r!r"r scCs0ddl}|dtd|dk r&|t|<t|S)Nrz'bind_textdomain_codeset() is deprecatedr\)rPrQrR_localecodesetsrE)rrerPr!r!r"r scCs:zt|t|d}Wntk r.|YSX||Srh)rrrErr )rrsrr!r!r"r s  c Csddl}|dtdt|}z<|*|ddtt|t|d|d}W5QRXWn&t k r| |pzt YSX|&|ddt| |W5QRSQRXdS)Nrz1ldgettext() is deprecated, use dgettext() insteadr\ru.*\bparameter codeset\b.*rerv)rPrQrRrrErwrxrrrryrrzr)rrsrPrerr!r!r"rs&  $ cCsRzt|t|d}Wn,tk rB|dkr6|YS|YSYnX||||Sr{)rrrErr)rr|r}r9rr!r!r"r sc Csddl}|dtdt|}z<|*|ddtt|t|d|d}W5QRXWn8t k r|dkrz|}n|}| |pt YSX|*|ddt| |||W5QRSQRXdS) Nrz3ldngettext() is deprecated, use dngettext() insteadr\rurrr2r)rPrQrRrrErwrxrrrryrrzr)rr|r}r9rPrerrr!r!r"rs,  $ cCs<zt|t|d}Wntk r.|YSX|||Srh)rrrErr)rrrsrr!r!r"rs  cCsTzt|t|d}Wn,tk rB|dkr6|YS|YSYnX|||||Sr{)rrrErr)rrr|r}r9rr!r!r"rscCs tt|Srh)r r)rsr!r!r"r sc CsNddl}|dtd|&|ddttt|W5QRSQRXdS)Nrrtr\ruz.*\bldgettext\b.*)rPrQrRrwrxrr)rsrPr!r!r"rs cCstt|||Srh)r r)r|r}r9r!r!r"rsc CsRddl}|dtd|*|ddttt|||W5QRSQRXdS)Nrr~r\ruz.*\bldngettext\b.*)rPrQrRrwrxrr)r|r}r9rPr!r!r"rs cCs tt||Srh)rr)rrsr!r!r"rscCstt||||Srh)rr)rr|r}r9r!r!r"rs)r5)NNF)N)N)N)1__doc__rrrsys__all__rr base_prefixrcompileVERBOSEDOTALLrr#r$rCrrDrArSr[rgrrrrrrrrrrrr r r rr rrrr rrrrrrr!r!r!r"s0      1 $*f7 & +