/usr/lib/python2.6/site-packages/babel
NameSizeModeActions
locale-data/-0755rm
localedata/-0755rm
localtime/-0755rm
messages/-0755rm
core.py311190644editdlrm
core.pyc325670644editdlrm
dates.py431110644editdlrm
dates.pyc424820644editdlrm
global.dat1096970644editdlrm
languages.py27480644editdlrm
languages.pyc32960644editdlrm
lists.py12710644editdlrm
lists.pyc14660644editdlrm
localedata.py62470644editdlrm
localedata.pyc75630644editdlrm
numbers.py232250644editdlrm
numbers.pyc223750644editdlrm
plural.py160210644editdlrm
plural.pyc201890644editdlrm
support.py218120644editdlrm
support.pyc255100644editdlrm
units.py110880644editdlrm
units.pyc92160644editdlrm
util.py81670644editdlrm
util.pyc108020644editdlrm
_compat.py11050644editdlrm
_compat.pyc24620644editdlrm
__init__.py7100644editdlrm
__init__.pyc9350644editdlrm
Edit: /usr/lib/python2.6/site-packages/babel/plural.pyc (20189B)
Ñò zDVc@sdZddkZd!ZdZd efd „ƒYZd „Zd „Zd „Zd„Z d„Z d„Z de 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 „Z d „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ƒo|iƒ}ntƒ}g|_xŽtt|ƒƒD]z\}}|tjotd|ƒ‚n"||jotd|ƒ‚n|i |ƒ|ii |t |ƒi fƒqEWdS(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+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt__init__(s      c Csc|i}dt|ƒidig}tD],}||jo|d|||fq)q)~ƒfS(Ns<%s %r>s, s%s: %s(Rttypet__name__tjoinR(RRt_[1]ttag((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt__repr__<s   cCst||ƒo|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+/tmp/pip-build-lt8jXN/Babel/babel/plural.pytparseDscCsFtƒi}tg}|iD]\}}||||ƒfq~ƒ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_compileRRR((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRPs cCs,tg}|iD]}||dq~ƒS(i(t frozensetR(txRti((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt[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|iS(N(R(R((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt __getstate__`scCs ||_dS(N(R(RR((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt __setstate__cscCs0t|dƒpt|ƒ|_n|i|ƒS(NR(thasattrt to_pythonR(Rtn((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt__call__fs(sabstracts_func(Rt __module__t__doc__t __slots__RR t classmethodR"tpropertyRttagsR+R,R0(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRs       cCsstƒi}dg}x=ti|ƒiD])\}}|id||ƒ|fƒq(W|idtƒdi|ƒ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+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt to_javascriptls   !cCs·htd6td6td6}tƒi}dg}xCti|ƒiD]/\}}|id||ƒt |ƒfƒqCW|idt ƒtdi |ƒ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 stexectevaluate( t in_range_listtwithin_range_listt cldr_modulot_PythonCompilerR$RR"RRtstrR9Rteval(R:t namespaceR.R<RRtcode((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR.ƒs    ' cCsÚti|ƒ}|ittgƒB}tƒi}g}tD]}||jo ||q<q<~i}dt |ƒg}x:|i D]/\}}|i d||ƒ||ƒfƒqƒW|i d|tƒƒdi |ƒ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)R7( RR"R6R R9t_GettextCompilerR$RtindextlenRRR(R:t used_tagsR%RRt _get_indexR<R((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt to_gettext§s  5 'cCs |t|ƒjo t||ƒ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 (tintRD(tnumt range_list((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRC¾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 c3s2x+|]$\}}ˆ|jo ˆ|jVqWdS(N((t.0tmin_tmax_(RR(s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pys ãs (tany(RRRS((RRs+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRDÒscCsed}|djo|d9}d}n|djo|d9}n||}|o|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+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyREæs      t RuleErrorcBseZdZRS(sRaised if a rule is malformed.(RR1R2(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR\ýsRcBsÝeZdZdeidƒfdeidƒfdeidƒfdeidƒfdeid ƒfgZd „Zdd „Zdd „Z ddd „Z d„Z d„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' 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 |iƒ}g}d}t|ƒ}x”||jo†x|iD]`\}}|i||ƒ}|dj o5|iƒ}|o|i||iƒfƒnPq>q>Wtd||ƒ‚q'W|ddd…|_ |i ƒ|_ |i otd|i ddƒ‚ndS(Nis5malformed CLDR pluralization rule. Got unexpected %riÿÿÿÿsExpected end of rule, got %ri( tlowerRMt_rulestmatchtNonetendRtgroupR\ttokenst conditionR(RtstringR<tposRfttokR:Rd((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR$s*        cCsD|io:|idd|jo"|djp|idd|jS(Niÿÿÿÿii(RhRe(RRR^((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyttest;s"cCs%|i||ƒo|iiƒSdS(N(RmRhtpop(RRR^((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pytskip?scCs˜|i||ƒ}|dj o|S|djo$t|djo|p|ƒ}n|iptd|ƒ‚ntd||iddfƒ‚dS(Ns#expected %s but end of rule reachedsexpected %s but got %riÿÿÿÿi(RoRetreprRhR\(RRR^ttermttoken((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pytexpectCs  $ cCsC|iƒ}x0|iddƒod||iƒff}qW|S(NR]tor(t and_conditionRo(Rtop((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRiMs  cCsC|iƒ}x0|iddƒod||iƒff}qW|S(NR]tand(trelationRo(RRv((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRuSs  cCsÔ|iƒ}|iddƒo1|iddƒodpd||iƒffS|iddƒ}d}|iddƒo d}n|iddddƒd |||iƒff}|od|ff}n|S( NR]tistnottisnottintwithinRqs'within' or 'in'Rx(RRoR^RsRS(RtlefttnegatedtmethodR[((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRxYs  cCs;|iƒ}|idƒo||iƒfS||fSdS(NRa(R^Ro(RR~((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pytrange_or_valueis cCsD|iƒg}x(|idƒo|i|iƒƒqWd|fS(NR_RS(RRoR(RRS((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRSps cCsJ|iddƒ|iddƒodddf|iƒffSddfS(NR]R/tmod(((RsRoR^(R((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRvscCs dt|idƒdƒffS(NR^i(RQRs(R((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR^|sN(RR1R2RetreR$RcRRmRoRsRiRuRxRRSRR^(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRs"         cs ‡fd†S(s%Compiler factory for the `_Compiler`.cs ˆ|i|ƒ|i|ƒfS((R$(Rtltr(ttmpl(s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR)‚s((R†((R†s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt_binary_compiler€scs ‡fd†S(s%Compiler factory for the `_Compiler`.csˆ|i|ƒS((R$(RR'(R†(s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR)‡s((R†((R†s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt_unary_compiler…st _CompilercBszeZdZd„Zd„Zd„ZedƒZedƒZe dƒZ edƒZ edƒZ ed ƒZ d „ZRS( sZThe compilers are able to transform the expressions into multiple output formats. cCs#|\}}t|d|ƒ|ŒS(Ntcompile_(tgetattr(RtargRvtargs((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR$s cCsdS(R/((R'((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR)“scCs t|ƒS((RG(R'tv((s+/tmp/pip-build-lt8jXN/Babel/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(RR€RRS((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pytcompile_relationœs(RR1R2R$t compile_nt compile_valueR‡t compile_andt compile_orRˆt compile_nott compile_modt compile_ist compile_isnotR(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR‰Šs         RFcBsGeZdZedƒZedƒZedƒZedƒZd„Z RS(s!Compiles an expression to Python.s (%s and %s)s (%s or %s)s(not %s)s MOD(%s, %s)c Cshddig}|dD]#}|dtt|i|ƒƒq~ƒ}d|iƒ|i|ƒ|fS(Ns[%s]R`is(%s, %s)s %s(%s, %s)(RttupletmapR$tupper(RR€RRSRtrange_tcompile_range_list((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR¨s  8( RR1R2R‡R“R”RˆR•R–R(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRF s     RKcBseZdZd„ZRS(s)Compile into a gettext plural expression.cCs­g}|i|ƒ}x„|dD]x}|d|djo(|id||i|dƒfƒq t|i|ƒ\}}|id||||fƒq Wddi|ƒS(Niis (%s == %s)s(%s >= %s && %s <= %s)s(%s)s || (R$RRšR(RR€RRSR[titemtmintmax((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR³s   (RR1R2R(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRK°sR8cBseZdZd„ZRS(s/Compiles the expression to plain of JavaScript.cCsOti||||ƒ}|djo&|i|ƒ}d|||f}n|S(NR|s(parseInt(%s) == %s && %s)(RKRR$(RR€RRSRJ((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRÊs  (RR1R2R(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR8ÇsR#cBs_eZdZedƒZedƒZedƒZedƒZedƒZd„Z e d„Z RS(s+Returns a unicode pluralization rule again.s%s is %ss %s is not %ss %s and %ss%s or %ss %s mod %scCs|idt|dŒS(NRi(RtTrue(RRx((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR•ÜscCs¥g}xh|dD]\}|d|djo|i|i|dƒƒq|idtt|i|ƒƒƒqWd|i|ƒ|odpd|di|ƒfS(Niis%s..%ss %s%s %s %ss notR7R`(RR$R™RšR(RR€RRSRtrangesRž((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyRßs '( RR1R2R‡R—R˜R“R”R–R•tFalseR(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyR#Ós      (RRRRRsother(R2RƒRR9tobjectRR=R.RPRCRDREt ExceptionR\RR‡RˆR‰RFRKR8R#(((s+/tmp/pip-build-lt8jXN/Babel/babel/plural.pyt s& Y  $