%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/babel/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyc

�
A��Qc@sdZddlZd!ZdZd	efd
��YZd�Zd�Zd
�Zd�Z	d�Z
d�Zdefd��YZ
defd��YZd�Zd�Zdefd��YZdefd��YZdefd��YZdefd��YZdefd ��YZdS("s�
    babel.numbers
    ~~~~~~~~~~~~~

    CLDR Plural support.  See UTS #35.

    :copyright: (c) 2013 by the Babel Team.
    :license: BSD, see LICENSE for more details.
i����Ntzerotonettwotfewtmanytothert
PluralRulecBsteZdZd
Zd�Zd�Zed��Zed��Z	ed�dd	�Z
d
�Zd�Zd�Z
RS(s�Represents a set of language pluralization rules.  The constructor
    accepts a list of (tag, expr) tuples or a dict of CLDR rules. The
    resulting object is callable and accepts one parameter with a positive or
    negative number (both integer and float) for the number that indicates the
    plural form for a string and returns the tag for the format:

    >>> rule = PluralRule({'one': 'n is 1'})
    >>> rule(1)
    'one'
    >>> rule(2)
    'other'

    Currently the CLDR defines these tags: zero, one, two, few, many and
    other where other is an implicit default.  Rules should be mutually
    exclusive; for a given numeric value, only one rule should apply (i.e.
    the condition should only be true for one of the plural rule elements.
    tabstractt_funccCs�t|t�r|j�}nt�}g|_x�tt|��D]v\}}|tkrntd|��n||kr�td|��n|j	|�|jj
|t|�jf�qCWdS(s$Initialize the rule instance.

        :param rules: a list of ``(tag, expr)``) tuples with the rules
                      conforming to UTS #35 or a dict with the tags as keys
                      and expressions as values.
        :raise RuleError: if the expression is malformed
        sunknown tag %rstag %r defined twiceN(
t
isinstancetdicttitemstsetRtsortedtlistt_plural_tagst
ValueErrortaddtappendt_Parsertast(tselftrulestfoundtkeytexpr((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt__init__(s		
c	CsV|j}dt|�jdjgtD]&}||kr%d|||f^q%�fS(Ns<%s %r>s, s%s: %s(Rttypet__name__tjoinR(RRttag((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt__repr__<s
	cCst||�r|S||�S(s
Create a `PluralRule` instance for the given rules.  If the rules
        are a `PluralRule` object, that object is returned.

        :param rules: the rules as list or dict, or a `PluralRule` object
        :raise RuleError: if the expression is malformed
        (R	(tclsR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pytparseDscCs>t�j}tg|jD]\}}|||�f^q�S(s�The `PluralRule` as a dict of unicode plural rules.

        >>> rule = PluralRule({'one': 'n is 1'})
        >>> rule.rules
        {'one': 'n is 1'}
        (t_UnicodeCompilertcompileR
R(Rt_compileRR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRPscCs$tg|jD]}|d^q
�S(Ni(t	frozensetR(txti((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt<lambda>[stdocs�
        A set of explicitly defined tags in this rule.  The implicit default
        ``'other'`` rules is not part of this set unless there is an explicit
        rule for it.cCs|jS(N(R(R((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt__getstate__`scCs
||_dS(N(R(RR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt__setstate__cscCs.t|d�s!t|�|_n|j|�S(NR(thasattrt	to_pythonR(Rtn((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt__call__fs(sabstracts_func(Rt
__module__t__doc__t	__slots__RRtclassmethodR!tpropertyRttagsR*R+R/(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRs					cCsst�j}dg}x=tj|�jD])\}}|jd||�|f�q(W|jdt�dj|�S(s�Convert a list/dict of rules or a `PluralRule` object into a JavaScript
    function.  This function depends on no external library:

    >>> to_javascript({'one': 'n is 1'})
    "(function(n) { return (n == 1) ? 'one' : 'other'; })"

    Implementation detail: The function generated will probably evaluate
    expressions involved into range operations multiple times.  This has the
    advantage that external helper functions are not required and is not a
    big performance hit for these simple calculations.

    :param rule: the rules as list or dict, or a `PluralRule` object
    :raise RuleError: if the expression is malformed
    s(function(n) { return s
%s ? %r : s%r; })t(t_JavaScriptCompilerR#RR!RRt
_fallback_tagR(truletto_jstresultRR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt
to_javascriptls	!cCs�itd6td6td6}t�j}dg}xCtj|�jD]/\}}|jd||�t	|�f�qCW|jdt
�tdj|�dd	�}t||�|d
S(s<Convert a list/dict of rules or a `PluralRule` object into a regular
    Python function.  This is useful in situations where you need a real
    function and don't are about the actual rule object:

    >>> func = to_python({'one': 'n is 1', 'few': 'n in 2..4'})
    >>> func(1)
    'one'
    >>> func(3)
    'few'
    >>> func = to_python({'one': 'n in 1,11', 'few': 'n in 3..10,13..19'})
    >>> func(11)
    'one'
    >>> func(15)
    'few'

    :param rule: the rules as list or dict, or a `PluralRule` object
    :raise RuleError: if the expression is malformed
    tINtWITHINtMODsdef evaluate(n):s if (%s): return %rs
 return %rs
s<rule>texectevaluate(
t
in_range_listtwithin_range_listtcldr_modulot_PythonCompilerR#RR!RRtstrR8Rteval(R9t	namespaceR-R;RRtcode((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR-�s
	'
cCs�tj|�}|jttg�B}t�j}gtD]}||kr8|^q8j}dt	|�g}x:|j
D]/\}}|jd||�||�f�qvW|jd|t��dj|�S(s~The plural rule as gettext expression.  The gettext expression is
    technically limited to integers and returns indices rather than tags.

    >>> to_gettext({'one': 'n is 1', 'two': 'n is 2'})
    'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)'

    :param rule: the rules as list or dict, or a `PluralRule` object
    :raise RuleError: if the expression is malformed
    snplurals=%d; plural=(s
%s ? %d : s%d)R6(
RR!R5RR8t_GettextCompilerR#RtindextlenRRR(R9t	used_tagsR$Rt
_get_indexR;R((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt
to_gettext�s
('cCs|t|�kot||�S(s�Integer range list test.  This is the callback for the "in" operator
    of the UTS #35 pluralization rule language:

    >>> in_range_list(1, [(1, 3)])
    True
    >>> in_range_list(3, [(1, 3)])
    True
    >>> in_range_list(3, [(1, 3), (5, 8)])
    True
    >>> in_range_list(1.2, [(1, 4)])
    False
    >>> in_range_list(10, [(1, 4)])
    False
    >>> in_range_list(10, [(1, 4), (6, 8)])
    False
    (tintRC(tnumt
range_list((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRB�scst�fd�|D��S(s�Float range test.  This is the callback for the "within" operator
    of the UTS #35 pluralization rule language:

    >>> within_range_list(1, [(1, 3)])
    True
    >>> within_range_list(1.0, [(1, 3)])
    True
    >>> within_range_list(1.2, [(1, 4)])
    True
    >>> within_range_list(8.8, [(1, 4), (7, 15)])
    True
    >>> within_range_list(10, [(1, 4)])
    False
    >>> within_range_list(10.5, [(1, 4), (20, 30)])
    False
    c3s-|]#\}}�|ko$�|kVqdS(N((t.0tmin_tmax_(RQ(s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pys	<genexpr>�s(tany(RQRR((RQs=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRC�scCs_d}|dkr%|d9}d}n|dkr>|d9}n||}|r[|d9}n|S(s�Javaish modulo.  This modulo operator returns the value with the sign
    of the dividend rather than the divisor like Python does:

    >>> cldr_modulo(-3, 5)
    -3
    >>> cldr_modulo(-3, -5)
    -3
    >>> cldr_modulo(3, 5)
    3
    ii����i((tatbtreversetrv((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRD�s
	


t	RuleErrorcBseZdZRS(sRaised if a rule is malformed.(RR0R1(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR[�sRcBs�eZdZdejd�fdejd�fdejd�fdejd�fdejd	�fgZd
�Zdd�Zdd�Z	ddd
�Z
d�Zd�Zd�Z
d�Zd�Zd�Zd�ZRS(s�Internal parser.  This class can translate a single rule into an abstract
    tree of tuples. It implements the following grammar::

        condition     = and_condition ('or' and_condition)*
        and_condition = relation ('and' relation)*
        relation      = is_relation | in_relation | within_relation | 'n' <EOL>
        is_relation   = expr 'is' ('not')? value
        in_relation   = expr ('not')? 'in' range_list
        within_relation = expr ('not')? 'within' range_list
        expr          = 'n' ('mod' value)?
        range_list    = (range | value) (',' range_list)*
        value         = digit+
        digit         = 0|1|2|3|4|5|6|7|8|9
        range         = value'..'value

    - Whitespace can occur between or around any of the above tokens.
    - Rules should be mutually exclusive; for a given numeric value, only one
      rule should apply (i.e. the condition should only be true for one of
      the plural rule elements).
    - The in and within relations can take comma-separated lists, such as:
      'n in 3,5,7..15'.

    The translator parses the expression on instanciation into an attribute
    called `ast`.
    s\s+(?u)twords%\b(and|or|is|(?:with)?in|not|mod|n)\btvalues\d+tcommat,tellipsiss\.\.cCs|j�}g}d}t|�}x�||kr�x{|jD]\\}}|j||�}|dk	r=|j�}|r�|j||j�f�nPq=q=Wtd||��q'W|ddd�|_	|j
�|_|j	rtd|j	dd��ndS(Nis5malformed CLDR pluralization rule.  Got unexpected %ri����sExpected end of rule, got %ri(tlowerRLt_rulestmatchtNonetendRtgroupR[ttokenst	conditionR(RtstringR;tposRettokR9Rc((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR$s&	cCsA|jo@|jdd|ko@|dkp@|jdd|kS(Ni����ii(RgRd(RRR]((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyttest;s cCs#|j||�r|jj�SdS(N(RlRgtpop(RRR]((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pytskip?scCs�|j||�}|dk	r"|S|dkrOt|dkrC|pF|�}n|jsktd|��ntd||jddf��dS(Ns#expected %s but end of rule reachedsexpected %s but got %ri����i(RnRdtreprRgR[(RRR]ttermttoken((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pytexpectCs!	cCsA|j�}x.|jdd�r<d||j�ff}qW|S(NR\tor(t
and_conditionRn(Rtop((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRhMscCsA|j�}x.|jdd�r<d||j�ff}qW|S(NR\tand(trelationRn(RRu((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRtSscCs�|j�}|jdd�rL|jdd�r6dp9d||j�ffS|jdd�}d}|jdd�rd}n|jdddd�d	|||j�ff}|r�d|ff}n|S(
NR\tistnottisnottintwithinRps'within' or 'in'Rw(RRnR]RrRR(RtlefttnegatedtmethodRZ((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRwYs	cCs9|j�}|jd�r+||j�fS||fSdS(NR`(R]Rn(RR}((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pytrange_or_valueiscCsB|j�g}x&|jd�r7|j|j��qWd|fS(NR^RR(R�RnR(RRR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRRpscCsH|jdd�|jdd�r>dddf|j�ffSddfS(NR\R.tmod(((RrRnR](R((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRvscCs dt|jd�d�ffS(NR]i(RPRr(R((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR]|sN(RR0R1RdtreR#RbRRlRnRrRhRtRwR�RRRR](((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRs"	
						cs
�fd�S(s%Compiler factory for the `_Compiler`.cs �|j|�|j|�fS(N(R#(Rtltr(ttmpl(s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR(�s((R�((R�s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt_binary_compiler�scs
�fd�S(s%Compiler factory for the `_Compiler`.cs�|j|�S(N(R#(RR&(R�(s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR(�s((R�((R�s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt_unary_compiler�st	_CompilercBszeZdZd�Zd�Zd�Zed�Zed�Ze	d�Z
ed�Zed�Zed	�Z
d
�ZRS(sZThe compilers are able to transform the expressions into multiple
    output formats.
    cCs#|\}}t|d|�|�S(Ntcompile_(tgetattr(RtargRutargs((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR#�scCsdS(NR.((R&((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR(�scCs
t|�S(N(RF(R&tv((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR(�ss
(%s && %s)s
(%s || %s)s(!%s)s
(%s %% %s)s
(%s == %s)s
(%s != %s)cCs
t��dS(N(tNotImplementedError(RRRRR((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pytcompile_relation�s(RR0R1R#t	compile_nt
compile_valueR�tcompile_andt
compile_orR�tcompile_nottcompile_modt
compile_ist
compile_isnotR�(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��s			REcBsGeZdZed�Zed�Zed�Zed�Zd�Z	RS(s!Compiles an expression to Python.s(%s and %s)s
(%s or %s)s(not %s)sMOD(%s, %s)c	Cs`ddjg|dD]"}dtt|j|��^q�}d|j�|j|�|fS(Ns[%s]R_is(%s, %s)s
%s(%s, %s)(RttupletmapR#tupper(RRRRRtrange_tcompile_range_list((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��s
	4(
RR0R1R�R�R�R�R�R�R�(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRE�sRJcBseZdZd�ZRS(s)Compile into a gettext plural expression.cCs�g}|j|�}x�|dD]v}|d|dkra|jd||j|d�f�q t|j|�\}}|jd||||f�q Wddj|�S(Niis
(%s == %s)s(%s >= %s && %s <= %s)s(%s)s || (R#RR�R(RRRRRRZtitemtmintmax((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��s		(RR0R1R�(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyRJ�sR7cBseZdZd�ZRS(s/Compiles the expression to plain of JavaScript.cCsMtj||||�}|dkrI|j|�}d|||f}n|S(NR{s(parseInt(%s) == %s && %s)(RJR�R#(RRRRRRI((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��s(RR0R1R�(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR7�sR"cBs_eZdZed�Zed�Zed�Zed�Zed�Zd�Z	e
d�ZRS(s+Returns a unicode pluralization rule again.s%s is %ss%s is not %ss	%s and %ss%s or %ss	%s mod %scCs|jdt|d�S(NR~i(R�tTrue(RRw((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��scCs�g}xf|dD]Z}|d|dkrH|j|j|d��q|jdtt|j|���qWd|j|�|r�dp�d|dj|�fS(Niis%s..%ss
%s%s %s %ss notR6R_(RR#R�R�R(RRRRRR~trangesR�((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR��s'(RR0R1R�R�R�R�R�R�R�tFalseR�(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyR"�s	(RRRRRsother(R1R�RR8tobjectRR<R-RORBRCRDt	ExceptionR[RR�R�R�RERJR7R"(((s=/opt/alt/python27/lib/python2.7/site-packages/babel/plural.pyt<module>
s&Y		$						

Zerion Mini Shell 1.0