Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/gettext.pyo

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


�`^c@s�dZddlZddlZddlZddlZddlZddlZddlmZdddddd	d
ddd
ddgZ	ej
jejdd�Z
d�Zd�Zd�Zdd'd��YZdefd��YZdddd�ZiZdddedd�Zdeddd�Ziaiadadd�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|r
|S|SdS(sy
    Implements the C expression:

      condition ? true : false

    Required to correctly interpret plural forms.
    N((t	conditionttruetfalse((s/sys/lib/python2.7/gettext.pyttest=sc
syddlm}Wn!tk
r7ddlm}nXddl}ddl}|j||�j�}y@g|D]/}|d|jkrr|ddkrr|^qr}Wn|jk
r�t	d�nX|r�t	d�n|j
d	d
�}|j
dd�}tjd
���j
d|�}tjd����fd��dg}x�|D]�}|dkrr|jd�qP|dkr�t|�dkr�t	d�n�j
�|j��}	|dcd|	7<qP|dc|7<qPW�j
�|j��}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|jd�|jd��j�|jd��fS(Nstest(%s, %s, %s)iii(tgrouptsub(tx(texprtrepl(s/sys/lib/python2.7/gettext.pyRistt(t)s%unbalanced parenthesis in plural forms(%s)slambda n: int(%s)(t	cStringIORtImportErrorttokenttokenizetgenerate_tokenstreadlinetNAMEt
TokenErrort
ValueErrortreplacetretcompileRtappendtlentpopteval(
tpluralRRR ttokensRtdangertstacktcts((RRs/sys/lib/python2.7/gettext.pytc2pyKs>
@
	
cCs�ddlm}||�}d
}d}d}d}|jd�}|dkrp||}|| }||O}nd}|jd�}|dkr�||}|| }||O}nd}|jd	�}|dkr�|}	|| }||O}nd}	|}
g}x~t|d�D]l}||@s|
}
||@rE|
|	7}
n||@r\|
|7}
n||@rs|
|7}
n|j|
�qqW|j�|S(
Ni�(t	normalizeiiit@Rt.t_iii(RR4RtrangeR)treverse(RR4tCOMPONENT_CODESETtCOMPONENT_TERRITORYtCOMPONENT_MODIFIERtmasktpostmodifiertcodesett	territorytlanguagetrettitval((s/sys/lib/python2.7/gettext.pyt_expand_lang�sL















cBs�eZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zedd
�ZRS(cCsDi|_d|_d|_d|_|dk	r@|j|�ndS(N(t_infotNonet_charsett_output_charsett	_fallbackt_parse(tselftfp((s/sys/lib/python2.7/gettext.pyt__init__�s				cCsdS(N((RMRN((s/sys/lib/python2.7/gettext.pyRL�scCs)|jr|jj|�n	||_dS(N(RKtadd_fallback(RMtfallback((s/sys/lib/python2.7/gettext.pyRP�s	cCs|jr|jj|�S|S(N(RKR(RMtmessage((s/sys/lib/python2.7/gettext.pyR�s	cCs|jr|jj|�S|S(N(RKtlgettext(RMRR((s/sys/lib/python2.7/gettext.pyRS�s	cCs7|jr|jj|||�S|dkr/|S|SdS(Ni(RKR(RMtmsgid1tmsgid2R((s/sys/lib/python2.7/gettext.pyR�s
	cCs7|jr|jj|||�S|dkr/|S|SdS(Ni(RKt	lngettext(RMRTRUR((s/sys/lib/python2.7/gettext.pyRV�s
	cCs#|jr|jj|�St|�S(N(RKtugettexttunicode(RMRR((s/sys/lib/python2.7/gettext.pyRW�s	cCsC|jr|jj|||�S|dkr5t|�St|�SdS(Ni(RKt	ungettextRX(RMRTRUR((s/sys/lib/python2.7/gettext.pyRY�s
	
cCs|jS(N(RG(RM((s/sys/lib/python2.7/gettext.pytinfo�scCs|jS(N(RI(RM((s/sys/lib/python2.7/gettext.pytcharset�scCs|jS(N(RJ(RM((s/sys/lib/python2.7/gettext.pytoutput_charset�scCs
||_dS(N(RJ(RMR[((s/sys/lib/python2.7/gettext.pytset_output_charset�scCs�ddl}|r|jp!|j|jd<t|d�r�d|kr]|jd|jd<nd|kr�|rx|jp~|j|jd<nd|kr�|j|jd<nd|kr�|j|jd<q�ndS(Ni�R7t__contains__RRRSRV(	t__builtin__RWRt__dict__thasattrRYRRSRV(RMRXtnamesR_((s/sys/lib/python2.7/gettext.pyR�sN(t__name__t
__module__RHRORLRPRRSRRVRWRYRZR[R\R]tFalseR(((s/sys/lib/python2.7/gettext.pyR�s												cBsSeZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	l�*l�$<cCs�tj}t|dd�}i|_}d�|_|j�}t|�}|d|d �d}||jkr�|d|dd!�\}}	}
}d	}nL||jkr�|d
|dd!�\}}	}
}d}nt	dd|��x�t
d|	�D]�}
||||
|
d
!�\}}||}|||||d
!�\}}||}||kr�||kr�|||!}|||!}nt	dd|��|dkr�d}}x|j�D]�|j
�}|s�q�nd|kr3|jdd�\}}|j
�j�}|j
�}||j|<|}n |rS|j|cd|7<n|dkrx|jd�d|_q�|dkr�|jd�}|djd�d}t|�|_q�q�Wnd|krj|jd�\}}|jd�}|jr6t||j�}g|D]}t||j�^q}nxktt|��D]}
||
|||
f<qIWn:|jr�t||j�}t||j�}n|||<|
d
7}
|d
7}q�S(s8Override this method to support alternative .mo formats.tnameRcSst|dk�S(Ni(tint(R((s/sys/lib/python2.7/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_MAGICtIOErrortxrangeRHt
splitlineststriptsplittlowerRGRIR3RXR8(RMRNRmtfilenametcatalogtbuftbuflentmagictversiontmsgcountt	masteridxttransidxtiiRDtmlentmofftmendttlenttoffttendtmsgttmsgtlastktktitemtvR-RTRUR((s/sys/lib/python2.7/gettext.pyRLsr	
"	"	 
 



	
	(	

cCs}t�}|jj||�}||krG|jrC|jj|�S|S|jr`|j|j�S|jry|j|j�S|S(N(tobjectRotgetRKRRJtencodeRI(RMRRtmissingR�((s/sys/lib/python2.7/gettext.pyRWs				cCsst�}|jj||�}||krG|jrC|jj|�S|S|jr`|j|j�S|jtj��S(N(	R�RoR�RKRSRJR�Rtgetpreferredencoding(RMRRR�R�((s/sys/lib/python2.7/gettext.pyRSes			cCs�yV|j||j|�f}|jr8|j|j�S|jrQ|j|j�S|SWnDtk
r�|jr�|jj|||�S|dkr�|S|SnXdS(Ni(RoR-RJR�RItKeyErrorRKR(RMRTRURR�((s/sys/lib/python2.7/gettext.pyRps		
	cCs�yL|j||j|�f}|jr8|j|j�S|jtj��SWnDtk
r�|jr{|jj|||�S|dkr�|S|SnXdS(Ni(	RoR-RJR�RR�R�RKRV(RMRTRURR�((s/sys/lib/python2.7/gettext.pyRV�s	
	cCsQt�}|jj||�}||krM|jrC|jj|�St|�S|S(N(R�RoR�RKRWRX(RMRRR�R�((s/sys/lib/python2.7/gettext.pyRW�s		
cCs~y |j||j|�f}WnWtk
ry|jrO|jj|||�S|dkrjt|�}qzt|�}nX|S(Ni(RoR-R�RKRYRX(RMRTRURR�((s/sys/lib/python2.7/gettext.pyRY�s 
	(RcRdRqRrRLRRSRRVRWRY(((s/sys/lib/python2.7/gettext.pyRs	Q						icCsT|dkrt}n|dkr�g}x9dD]1}tjj|�}|r.|jd�}Pq.q.Wd|kr�|jd�q�ng}xA|D]9}x0t|�D]"}||kr�|j|�q�q�Wq�W|r�g}	nd}	xl|D]d}|dkr�tjj	||dd|�}
tjj
|
�r�rE|	j|
�qL|
Sq��|	S(	NtLANGUAGEtLC_ALLtLC_MESSAGEStLANGRitCs%s.mo(R�R�R�R�(RHt_default_localedirtostenvironR�RwR)RFtpathtjointexists(tdomaint	localedirt	languagestalltenvarREtnelangstlangtnelangtresulttmofile((s/sys/lib/python2.7/gettext.pyR�s8	

	
c	Cs|dkrt}nt|||dd�}|sU|r@t�Sttd|��nd}x�|D]�}|tjj|�f}	t	j
|	�}
|
dkr�t|d��}t	j|	||��}
WdQXnt
j
|
�}
|r�j|�n|dkr|
}qb|j|
�qbW|S(NR�is$No translation file found for domaintrb(RHRRRRsRR�R�tabspatht
_translationsR�topent
setdefaulttcopyR]RP(R�R�R�tclass_RQR@tmofilesR�R�tkeyttRN((s/sys/lib/python2.7/gettext.pyR�s*	
!	cCs/t||dtd|�}|j||�dS(NRQR@(RtTrueR(R�R�RXR@RbR�((s/sys/lib/python2.7/gettext.pyR�stmessagescCs|dk	r|antS(N(RHt_current_domain(R�((s/sys/lib/python2.7/gettext.pyR�s	cCs)|dk	r|t|<ntj|t�S(N(RHt_localedirsR�R�(R�R�((s/sys/lib/python2.7/gettext.pyRs
cCs&|dk	r|t|<ntj|�S(N(RHt_localecodesetsR�(R�R@((s/sys/lib/python2.7/gettext.pytbind_textdomain_codesets
cCsPy.t|tj|d�dtj|��}Wntk
rB|SX|j|�S(NR@(RR�R�RHR�RsR(R�RRR�((s/sys/lib/python2.7/gettext.pyR	s
cCsPy.t|tj|d�dtj|��}Wntk
rB|SX|j|�S(NR@(RR�R�RHR�RsRS(R�RRR�((s/sys/lib/python2.7/gettext.pyt	ldgettexts
cCsiy.t|tj|d�dtj|��}Wn%tk
rU|dkrN|S|SnX|j|||�S(NR@i(RR�R�RHR�RsR(R�RTRURR�((s/sys/lib/python2.7/gettext.pyR
s
cCsiy.t|tj|d�dtj|��}Wn%tk
rU|dkrN|S|SnX|j|||�S(NR@i(RR�R�RHR�RsRV(R�RTRURR�((s/sys/lib/python2.7/gettext.pyt
ldngettext*s
cCs
tt|�S(N(R	R�(RR((s/sys/lib/python2.7/gettext.pyR5scCs
tt|�S(N(R�R�(RR((s/sys/lib/python2.7/gettext.pyRS8scCstt|||�S(N(R
R�(RTRUR((s/sys/lib/python2.7/gettext.pyR;scCstt|||�S(N(R�R�(RTRUR((s/sys/lib/python2.7/gettext.pyRV>s(((t__doc__RR�R�R'RltsysterrnoRt__all__R�R�tprefixR�RR3RFRRRHRR�ReRRR�R�R�RRR�R	R�R
R�RRSRRVR(((s/sys/lib/python2.7/gettext.pyt<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 [email protected].