Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/gettext.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c@s�dZddkZddkZddkZddkZddkZddkZddklZdddddd	d
ddd
ddgZ	ei
ieidd�Z
d�Zd�Zd�Zdd'd��YZdefd��YZdddd�ZhZdddedd�Zdeddd�Zhahadadd�Zdd�Zdd�Zd�Zd �Z d!�Z!d"�Z"d#�Z#d$�Z$d%�Z%d&�Z&eZ'dS((s�Internationalization 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.

i�N(tENOENTtNullTranslationstGNUTranslationstCatalogtfindttranslationtinstallt
textdomaintbindtextdomaintdgettextt	dngettexttgettexttngettexttsharetlocalecCs|o|Sn|SdS(sy
    Implements the C expression:

      condition ? true : false

    Required to correctly interpret plural forms.
    N((t	conditionttruetfalse((s/sys/lib/python/gettext.pyttest=scsyddkl}Wn#tj
oddkl}nXddk}ddk}|i||�i�}yNg}|D]6}|d|ijo|ddjo||qxqx~}Wn|ij
ot	d�nX|o
t	d�n|i
d	d
�}|i
dd�}tid
���i
d|�}tid����fd��dg}x�|D]�}	|	djo|id�qd|	djoPt|�djo
t	d�n�i
�|i��}
|dcd|
7<qd|dc|	7<qdW�i
�|i��}td|�S(s�Gets a C expression as used in PO files for plural forms and returns a
    Python lambda function that implements an equivalent expression.
    i�(tStringIONiitns;plural forms expression error, maybe unbalanced parenthesiss*plural forms expression could be dangerouss&&s and s||s or s\!([^=])s not \1s(.*?)\?(.*?):(.*)cs8d|id�|id��i�|id��fS(Nstest(%s, %s, %s)iii(tgrouptsub(tx(trepltexpr(s/sys/lib/python/gettext.pyRistt(t)s%unbalanced parenthesis in plural forms(%s)slambda n: int(%s)(t	cStringIORtImportErrorttokenttokenizetgenerate_tokenstreadlinetNAMEt
TokenErrort
ValueErrortreplacetretcompileRtappendtlentpopteval(tpluralRRR ttokenst_[1]Rtdangertstacktcts((RRs/sys/lib/python/gettext.pytc2pyKs@N
	


c
Cs�ddkl}||�}d
}d}d}d}|id�}|djo"||}|| }||O}nd}|id�}|djo"||}|| }||O}nd}|id	�}|djo"||}	|| }||O}nd}	|}
g}x�t|d�D]t}||@pb|
}
||@o|
|	7}
n||@o|
|7}
n||@o|
|7}
n|i|
�qqW|i�|S(
Ni�(t	normalizeiiit@Rt.t_iii(RR5RtrangeR)treverse(RR5tCOMPONENT_CODESETtCOMPONENT_TERRITORYtCOMPONENT_MODIFIERtmasktpostmodifiertcodesett	territorytlanguagetrettitval((s/sys/lib/python/gettext.pyt_expand_lang�sH









cBs�eZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zedd
�ZRS(cCsFh|_d|_d|_d|_|dj	o|i|�ndS(N(t_infotNonet_charsett_output_charsett	_fallbackt_parse(tselftfp((s/sys/lib/python/gettext.pyt__init__�s				
cCsdS(N((RNRO((s/sys/lib/python/gettext.pyRM�scCs+|io|ii|�n
||_dS(N(RLtadd_fallback(RNtfallback((s/sys/lib/python/gettext.pyRQ�s
cCs"|io|ii|�Sn|S(N(RLR(RNtmessage((s/sys/lib/python/gettext.pyR�s
cCs"|io|ii|�Sn|S(N(RLtlgettext(RNRS((s/sys/lib/python/gettext.pyRT�s
cCsA|io|ii|||�Sn|djo|Sn|SdS(Ni(RLR(RNtmsgid1tmsgid2R((s/sys/lib/python/gettext.pyR�s


cCsA|io|ii|||�Sn|djo|Sn|SdS(Ni(RLt	lngettext(RNRURVR((s/sys/lib/python/gettext.pyRW�s


cCs(|io|ii|�Snt|�S(N(RLtugettexttunicode(RNRS((s/sys/lib/python/gettext.pyRX�s
cCsM|io|ii|||�Sn|djot|�Snt|�SdS(Ni(RLt	ungettextRY(RNRURVR((s/sys/lib/python/gettext.pyRZ�s


cCs|iS(N(RH(RN((s/sys/lib/python/gettext.pytinfo�scCs|iS(N(RJ(RN((s/sys/lib/python/gettext.pytcharset�scCs|iS(N(RK(RN((s/sys/lib/python/gettext.pytoutput_charset�scCs
||_dS(N(RK(RNR\((s/sys/lib/python/gettext.pytset_output_charset�scCs�ddk}|o
|ip|i|id<t|d�o�d|jo|id|id<nd|jo%|o
|ip|i|id<nd|jo|i|id<nd|jo|i|id<q�ndS(Ni�R8t__contains__RRRTRW(	t__builtin__RXRt__dict__thasattrRZRRTRW(RNRYtnamesR`((s/sys/lib/python/gettext.pyR�s!



N(t__name__t
__module__RIRPRMRQRRTRRWRXRZR[R\R]R^tFalseR(((s/sys/lib/python/gettext.pyR�s												cBsSeZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	l�*l�$<cCs�ti}t|dd�}h|_}d�|_|i�}t|�}|d|d �d}||ijo,|d|dd!�\}}	}
}d	}nO||ijo,|d
|dd!�\}}	}
}d}nt	dd|��x�
d|	�D]�}
||||
|
d
!�\}}||}|||||d
!�\}}||}||jo+||jo|||!}|||!}nt	dd|��|djo(d}}x|i�D]	}|i
�}|pq�nd|joM|idd�\}}|i
�i�}|i
�}||i|<|}n#|o|i|cd|7<n|djo|id�d|_q�|djo9|id�}|did�d}t|�|_q�q�Wnd|jo�|id�\}}|id�}|ioCt||i�}g}|D]}|t||i�q.~}nxntt|��D]}
||
|||
f<qgWn=|io(t||i�}t||i�}n|||<|
d
7}
|d
7}q�S(s8Override this method to support alternative .mo formats.tnameRcSst|dj�S(i(tint(R((s/sys/lib/python/gettext.pyt<lambda>
ss<Iiis<4Iis<IIs>4Is>IIsBad magic numberisFile is corruptt:is
scontent-typescharset=splural-formst;splural=tN(tstructtunpacktgetattrt_catalogR-treadR*tLE_MAGICtBE_MAGICtIOErrortxrangeRIt
splitlineststriptsplittlowerRHRJR4RYR9(RNRORntfilenametcatalogtbuftbuflentmagictversiontmsgcountt	masteridxttransidxtiiREtmlentmofftmendttlenttoffttendtmsgttmsgtlastktktitemtvR-RURVR/R((s/sys/lib/python/gettext.pyRMsx	
"
"
 
 












1


cCs�t�}|ii||�}||jo&|io|ii|�Sn|Sn|io|i|i�Sn|io|i|i�Sn|S(N(tobjectRptgetRLRRKtencodeRJ(RNRStmissingR�((s/sys/lib/python/gettext.pyRWs	



cCs�t�}|ii||�}||jo&|io|ii|�Sn|Sn|io|i|i�Sn|iti��S(N(	R�RpR�RLRTRKR�Rtgetpreferredencoding(RNRSR�R�((s/sys/lib/python/gettext.pyRTes	


cCs�y`|i||i|�f}|io|i|i�Sn|io|i|i�Sn|SWnPtj
oD|io|ii|||�Sn|djo|Sq�|SnXdS(Ni(RpR-RKR�RJtKeyErrorRLR(RNRURVRR�((s/sys/lib/python/gettext.pyRps



cCs�yQ|i||i|�f}|io|i|i�Sn|iti��SWnPtj
oD|io|ii|||�Sn|djo|Sq�|SnXdS(Ni(	RpR-RKR�RR�R�RLRW(RNRURVRR�((s/sys/lib/python/gettext.pyRW�s


cCs[t�}|ii||�}||jo,|io|ii|�Snt|�Sn|S(N(R�RpR�RLRXRY(RNRSR�R�((s/sys/lib/python/gettext.pyRX�s	

cCs�y |i||i|�f}Wn`tj
oT|io|ii|||�Sn|djot|�}q�t|�}nX|S(Ni(RpR-R�RLRZRY(RNRURVRR�((s/sys/lib/python/gettext.pyRZ�s 

(RdReRrRsRMRRTRRWRXRZ(((s/sys/lib/python/gettext.pyRs	Q						icCsf|djo
t}n|djofg}x;dD]3}tii|�}|o|id�}Pq1q1Wd|jo|id�q�ng}xC|D];}x2t|�D]$}||jo|i|�q�q�Wq�W|o
g}	nd}	xr|D]j}|djoPntii	||dd|�}
tii
|
�o |o|	i|
�q^|
Sq��	S(	NtLANGUAGEtLC_ALLtLC_MESSAGEStLANGRjtCs%s.mo(R�R�R�R�(RIt_default_localedirtostenvironR�RxR)RGtpathtjointexists(tdomaint	localedirt	languagestalltenvarRFtnelangstlangtnelangtresulttmofile((s/sys/lib/python/gettext.pyR�s@


	




cCs|djo
t}nt|||dd�}|p(|ot�Snttd|��nd}x�|D]�}tii|�}	t	i
|	�}
|
djo%t	i|	|t|d���}
nt
i
|
�}
|o|
i|�n|djo
|
}qk|i|
�qkW|S(NR�is$No translation file found for domaintrb(RIRRRRtRR�R�tabspatht
_translationsR�t
setdefaulttopentcopyR^RQ(R�R�R�tclass_RRRAtmofilesR�R�tkeytt((s/sys/lib/python/gettext.pyR�s*


%

cCs/t||dtd|�}|i||�dS(NRRRA(RtTrueR(R�R�RYRARcR�((s/sys/lib/python/gettext.pyR�stmessagescCs|dj	o
|antS(N(RIt_current_domain(R�((s/sys/lib/python/gettext.pyR�s

cCs+|dj	o|t|<nti|t�S(N(RIt_localedirsR�R�(R�R�((s/sys/lib/python/gettext.pyRs
cCs(|dj	o|t|<nti|�S(N(RIt_localecodesetsR�(R�RA((s/sys/lib/python/gettext.pytbind_textdomain_codesets
c	CsUy.t|ti|d�dti|��}Wntj
o|SnX|i|�S(NRA(RR�R�RIR�RtR(R�RSR�((s/sys/lib/python/gettext.pyR	s	c	CsUy.t|ti|d�dti|��}Wntj
o|SnX|i|�S(NRA(RR�R�RIR�RtRT(R�RSR�((s/sys/lib/python/gettext.pyt	ldgettexts	c	Cspy.t|ti|d�dti|��}Wn,tj
o |djo|Sq]|SnX|i|||�S(NRAi(RR�R�RIR�RtR(R�RURVRR�((s/sys/lib/python/gettext.pyR
s
	c	Cspy.t|ti|d�dti|��}Wn,tj
o |djo|Sq]|SnX|i|||�S(NRAi(RR�R�RIR�RtRW(R�RURVRR�((s/sys/lib/python/gettext.pyt
ldngettext*s
	cCs
tt|�S(N(R	R�(RS((s/sys/lib/python/gettext.pyR5scCs
tt|�S(N(R�R�(RS((s/sys/lib/python/gettext.pyRT8scCstt|||�S(N(R
R�(RURVR((s/sys/lib/python/gettext.pyR;scCstt|||�S(N(R�R�(RURVR((s/sys/lib/python/gettext.pyRW>s(((t__doc__RR�R�R'RmtsysterrnoRt__all__R�R�tprefixR�RR4RGRRRIRR�RfRRR�R�R�RRR�R	R�R
R�RRTRRWR(((s/sys/lib/python/gettext.pys<module>s>&H			7	+T�&								

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.