3 \T@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z dddddd d d d d dddddddgZ ej j ej ddZejdejejBZddZddZdPZd)d*eed+DZd,d-d.d/ZdRd0d1Zd2d3Zd4d5Zd6d7ZGd8ddZGd9ddeZdSd;dZiZdTda$dVd?d Z%dWd@d Z&dXdAd Z'dBd Z(dCdZ)dDdZ*dEdZ+dFdZ,dGdZ-dHdZ.dIdZ/e Z0dS)YaInternationalization 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. N)ENOENTNullTranslationsGNUTranslationsCatalogfind translationinstall textdomainbindtextdomainbind_textdomain_codesetdgettext dngettextgettextlgettext ldgettext ldngettext lngettextngettextZsharelocalea (?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 ccsTxHtjt|D]8}|j}|dkr"q|j|}|dkr@td||VqWdVdS)NZ WHITESPACESZINVALIDz invalid token in plural form: %s)refinditer_token_pattern lastgroupgroup ValueError)pluralZmoZkindvaluer/usr/lib64/python3.6/gettext.py _tokenizeTs   r cCs|rtd|StdSdS)Nz#unexpected token in plural form: %szunexpected end of plural form)r)rrrr_error_s r!||&&==!=<><=>=+-*/%cCs i|]\}}|D] }||qqSrr).0iZopsoprrr msr2orandz//)z||z&&r-c Csd}t|}x|dkr(|d7}t|}qW|dkr\t|\}}d||f}|dkrtdnP|dkrrd ||f}n:yt|d }Wntk rt|dYnXd ||f}t|}d }xh|tkr t|}||krP|dkr|dkrd|}tj||}t||d\} }d||| f}|}qW||ko6dknrFd|}|dkr|dkrt|d\} }|dkrzt|t|\} }d| || f}|dkrd|}||fS)Nr!znot (z%s(%s))z%unbalanced parenthesis in plural formnz%s%s z%s%ddz(%s)r3z%s %s %s?r:z%s if %s else %s)r<r=)r<r=)next_parserintr! _binary_ops _c2py_opsget) tokensZpriorityresultnexttoksubrjr0r1rightZif_trueZif_falserrrrApsP           rAc Cs:y t|}Wn(tk r4td|jjfdYnX|S)Nz'Plural value must be an integer, got %s)round TypeError __class____name__)r9r0rrr_as_ints  rPc Cst|dkrtdy~tt|\}}|r2t|d}x>|D]6}|dkrb|d7}|dkrrtdq<|dkr<|d8}qt|D]\}}!t |!||||f<qWnt |||t ||<| d7} | d7} qWdS)z8Override this method to support alternative .mo formats.namercSs t|dkS)Nr3)rB)r9rrrUsz(GNUTranslations._parse..z4Iz>IIzBad magic numberzBad version number zFile is corrupt r?r3 z content-typezcharset=z plural-forms;zplural=ascii)structunpackgetattr_catalogrreadrSLE_MAGICBE_MAGICOSErrorrVERSIONSstrr]splitdecodestriplowerrfrgrX enumerate)"rjrkrfilenameZcatalogZbufZbuflenmagicrZmsgcountZ masteridxZtransidxZiiZ major_versionZ minor_versionr0ZmlenZmoffZmendZtlenZtoffZtendmsgrtZlastkZb_itemitemkvrrvrrrsxrrrrANsr                     zGNUTranslations._parsecCsRt}|jj||}||kr2|jr.|jj|S|}|jrD|j|jS|jtjS)N) objectrrErirrhrprrq)rjromissingrtrrrrs  zGNUTranslations.lgettextc Csvy|j||j|f}Wn<tk rT|jr>|jj|||S|dkrL|}n|}YnX|jrh|j|jS|jtjS)Nr3) rrKeyErrorrirrhrprrq)rjrrrsr9rtrrrrs  zGNUTranslations.lngettextcCs6t}|jj||}||kr2|jr.|jj|S|S|S)N)rrrErir)rjrorrtrrrrs zGNUTranslations.gettextc CsZy|j||j|f}Wn<tk rT|jr>|jj|||S|dkrL|}n|}YnX|S)Nr3)rrrrir)rjrrrsr9rtrrrrs zGNUTranslations.ngettextN)rr3) rOr~rrrrrrArrrrrrrrrBsT  Fc Cs|dkr t}|dkrTg}x(dD] }tjj|}|r|jd}PqWd|krT|jdg}x0|D](}x"t|D]}||krl|j|qlWq^W|rg} nd} xL|D]D}|dkrPtjj||dd|} tjj | r|r| j| q| SqW| S) NLANGUAGELC_ALL LC_MESSAGESLANGr?Cz%s.mo)rrrr) _default_localedirosenvironrErr^repathjoinexists) domain localedir languagesallZenvarrdZnelangsZlangZnelangrGmofilerrrrs8        c Cs|dkr t}t|||dd}|s6|r*tSttd|d}x|D]|}|tjj|f} tj | } | dkrt |d} tj | || } WdQRXt j | } |r| j ||dkr| }q@|j| q@W|S)NT)rz$No translation file found for domainrb)rrrrrrrabspath _translationsrEopen setdefaultcopyrxrm) rrrZclass_rnrcZmofilesrGrkeytrkrrrrs*      cCst||d|d}|j|dS)NT)rnrc)rr)rrrcr}rrrrrsZmessagescCs|dk r |atS)N)_current_domain)rrrrr 'scCs|dk r|t|<tj|tS)N) _localedirsrEr)rrrrrr .scCs|dk r|t|<tj|S)N)_localecodesetsrE)rrcrrrr 5sc Cs@y t|tj|dtj|d}Wntk r4|SX|j|S)N)rc)rrrErrr)rrorrrrr <s c CsRtj|}yt|tj|d|d}Wn"tk rF|j|pBtjSX|j|S)N)rc) rrErrrrprrqr)rrorcrrrrrDs  c CsTy t|tj|dtj|d}Wn$tk rD|dkr<|S|SYnX|j|||S)N)rcr3)rrrErrr)rrrrsr9rrrrr Ls c Cshtj|}yt|tj|d|d}Wn4tk rX|dkrB|}n|}|j|pTtjSX|j|||S)N)rcr3) rrErrrrprrqr)rrrrsr9rcrrtrrrrWs cCs tt|S)N)r r)rorrrrcscCs tt|S)N)rr)rorrrrfscCstt|||S)N)r r)rrrsr9rrrriscCstt|||S)N)rr)rrrsr9rrrrlsr"r#r$r%r&r'r(r)r*r+r,r-r.)rrrrrr)r)NNF)NNNFN)NNN)N)N)N)1__doc__rriorrrsyserrnor__all__rr base_prefixrcompileVERBOSEDOTALLrr r!rCrrDrArPrXrerrrrrrrrrr r r r rr rrrrrrrrrr s^&8         1$*K &