>QgZ UdZddlmZddlZddlZddlmZmZddlm Z m Z m Z e rddl m Z dZdZdUd ZGddZdVdZdWdZdVdZdXdZdXdZdYd ZGd!d"eZhd#Zdejd$ejfd%ejd&d'ed(fd)ejd*fd+ejd,fd-ejd.ejfgZd/ed0<dZd3Z d[d\d8Z!d[d]d9Z"d^d<Z#d_d?Z$d`dAZ%dadEZ&GdFdGZ'dHZ(dIZ)dJZ*GdKdLZ+GdMdNe+Z,GdOdPe+Z-GdQdRe-Z.GdSdTe+Z/dS)bz babel.numbers ~~~~~~~~~~~~~ CLDR Plural support. See UTS #35. :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details. ) annotationsN)IterableMapping) TYPE_CHECKINGAnyCallable)Literal)zeroonetwofewmanyotherrsourcefloat | decimal.DecimalreturnMtuple[decimal.Decimal | int, int, int, int, int, int, Literal[0], Literal[0]]cjt|}t|}t|tr*||kr|}n!t jt |}t|tjr|}|j}|dkr|j |dnd}d d|D}| d}t|}t|} t|pd} t|pd} ndx}x} x} } dx} } |||| | | | | fS)uExtract operands from a decimal, a float or an int, according to `CLDR rules`_. The result is a 8-tuple (n, i, v, w, f, t, c, e), where those symbols are as follows: ====== =============================================================== Symbol Value ------ --------------------------------------------------------------- n absolute value of the source number (integer and decimals). i integer digits of n. v number of visible fraction digits in n, with trailing zeros. w number of visible fraction digits in n, without trailing zeros. f visible fractional digits in n, with trailing zeros. t visible fractional digits in n, without trailing zeros. c compact decimal exponent value: exponent of the power of 10 used in compact decimal formatting. e currently, synonym for ‘c’. however, may be redefined in the future. ====== =============================================================== .. _`CLDR rules`: https://www.unicode.org/reports/tr35/tr35-61/tr35-numbers.html#Operands :param source: A real number :type source: int|float|decimal.Decimal :return: A n-i-v-w-f-t-c-e tuple :rtype: tuple[decimal.Decimal, int, int, int, int, int, int, int] rNc34K|]}t|VdSNstr).0ds l/builddir/build/BUILD/imunify360-venv-2.5.0/opt/imunify360/venv/lib/python3.11/site-packages/babel/plural.py z#extract_operands..Gs(;;a3q66;;;;;;0) absint isinstancefloatdecimalDecimalras_tupleexponentdigitsjoinrstriplen)rni dec_tupleexpfraction_digitstrailing no_trailingvwftces rextract_operandsr:s<2 F A AA!U( 66AAA''A!W_%% JJLL  47!GG)*3440077;;?;;;;;ooc** MM     A     q ! !AA IA aAq!Q !!rceZdZdZdZddZdd Zedd Ze dd Z e ddZ ddZ ddZ ddZdS) PluralRuleafRepresents 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. .. _`CLDR rules`: https://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#Language_Plural_Rules )abstract_funcrules-Mapping[str, str] | Iterable[tuple[str, str]]rNonect|tr|}t}g|_t |D]~\}}|t vrtd|||vrtd|d||t|j }|r|j ||fdS)a$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 z unknown tag ztag z defined twiceN) r#ritemssetr=sorted _plural_tags ValueErroradd_Parserastappend)selfr?foundkeyexprrJs r__init__zPluralRule.__init__js eW % % "KKMME/1  1 1IC,&& !7!7!7888 !=!=!=!=>>> IIcNNN$--#C 1 $$c3Z000 1 1rrc|jdfdtD}dt|jd|dS)N, c2g|]}|v|d|S)z: r)rtagr?s r z'PluralRule.__repr__..s1YYYSCSXLLS00E#J00LLLr< >)r?r*rFtype__name__)rLargsr?s @r__repr__zPluralRule.__repr__sR yyYYYYLYYYZZ24::&222222r:Mapping[str, str] | Iterable[tuple[str, str]] | PluralRulecFt|tr|S||S)a 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#r<)clsr?s rparsezPluralRule.parses) eZ ( ( Ls5zzrMapping[str, str]cPtjfd|jDS)zThe `PluralRule` as a dict of unicode plural rules. >>> rule = PluralRule({'one': 'n is 1'}) >>> rule.rules {'one': 'n is 1'} c.i|]\}}||Srr)rrTrJ_compiles r z$PluralRule.rules..s'AAAxsCXXc]]AAAr)_UnicodeCompilercompiler=)rLrds @rr?zPluralRule.ruless/$%%-AAAA4=AAAArfrozenset[str]c>td|jDS)zA 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. c3&K|] }|dV dS)rNr)rr.s rrz"PluralRule.tags..s&55!1555555r) frozensetr=rLs rtagszPluralRule.tagss# 55t}555555rlist[tuple[str, Any]]c|jSrr=rls r __getstate__zPluralRule.__getstate__s }rr=c||_dSrrp)rLr=s r __setstate__zPluralRule.__setstate__s   rr-rctt|dst||_||S)Nr>)hasattr to_pythonr>)rLr-s r__call__zPluralRule.__call__s1tW%% )"4DJzz!}}rN)r?r@rrA)rr)r?r]rr<)rra)rrh)rrn)r=rnrrA)r-rrr)rZ __module__ __qualname____doc__ __slots__rPr\ classmethodr`propertyr?rmrqrsrwrrrr<r<Ss(&I1111,3333    [ BBBXB666X6!!!!rr<ruler]rc$tj}dg}t|jD])\}}|||d|d*|dt zd|S)aConvert 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 z(function(n) { return  ?  : z%r; })r)_JavaScriptCompilerrgr<r`r=rK _fallback_tagr*)r~to_jsresultrTrJs r to_javascriptrs ! ! )E& 'F$$T**344S s222223333 MM(]*+++ 776??r(Callable[[float | decimal.Decimal], str]c ttttd}t j}ddg}t |jD]6\}}| d||dt|7| dtt d |dd }t|||d S) a<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 )INWITHINMODr:zdef evaluate(n):z- n, i, v, w, f, t, c, e = extract_operands(n)z if (z ): return z return  zexecevaluate) in_range_listwithin_range_list cldr_modulor:_PythonCompilerrgr<r`r=rKrrr*eval)r~ namespaceto_python_funcrrTrJcodes rrvrvs(#, I %&&.N7F$$T**3KKS  InnS11IISXXIIJJJJ MM.]../// 499V$$h 7 7Dy Z  rct|}|jthzt j}fdt Dj}dtdg}|j D]2\}}| ||d||d3| |tdd |S)aThe 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 cg|]}|v| Srr)rrT used_tagss rrUzto_gettext..s#BBB# 1A1A#1A1A1Arz nplurals=z ; plural=(rrz);r) r<r`rmr_GettextCompilerrgrFindexr,r=rKr*)r~rd _get_indexrrTrJrs @r to_gettextrs   D ! !D ]O+I!!)HBBBBBBBHJ4#i..444 5FMAAS #??::c?????@@@@ MMZZ ..222333 776??rnum range_list+Iterable[Iterable[float | decimal.Decimal]]boolcH|t|kot||S)aInteger 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 )r"rrrs rrrs$" #c((? A0jAAArc:tfd|DS)aFloat 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 c36K|]\}}|ko|kVdSrr)rmin_max_rs rrz$within_range_list..+s4HHztTsd{*sd{HHHHHHr)anyrs` rrrs(" HHHHZHHH H HHrar$bcRd}|dkr|dz}d}|dkr|dz}||z}|r|dz}|S)zJavaish 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 rr)rrreverservs rrr.sQG1uu R1uu R QB b IrceZdZdZdS) RuleErrorzRaised if a rule is malformed.N)rZrxryrzrrrrrEs((((rr>r8r9r6r.r-r7r4r5z\s+wordz"\b(and|or|is|(?:with)?in|not|mod|[rz])\bvaluez\d+symbolz%|,|!=|=ellipsisz\.{2,3}|\u2026z(list[tuple[str | None, re.Pattern[str]]]_RULESslist[tuple[str, str]]c|dd}g}d}t|}||krtD]^\}}|||}|A|}|r)|||fn_td||z||k|dddS)N@rz5malformed CLDR pluralization rule. Got unexpected %rr)splitr,rmatchendrKgroupr)rrposrtokr~rs r tokenize_ruler]s  QA$&F C a&&C )) : :ICJJq#&&E iikk8MM3 "6777 ! 023C&9:: : )) $$B$<rtokenstype_ str | Nonelist[tuple[str, str]] | boolcV|o'|dd|ko|dup|dd|kS)Nrrrrrrrs rtest_next_tokenrps>  2fRjmu, 2 $ 0&*Q-502rcPt|||r|SdSr)rpoprs r skip_tokenrys.vue,,zz||rr"#tuple[Literal['value'], tuple[int]]c d|ffS)Nrr)rs r value_noder~s UI rnametuple[str, tuple[()]]c |dfS)Nrr)rs r ident_noders 8OrItuple[Literal['range_list'], Iterable[Iterable[float | decimal.Decimal]]]c d|fS)Nrr)rs rrange_list_noders  ##rrtuple[Any, ...]-tuple[Literal['not'], tuple[tuple[Any, ...]]]c d|ffS)Nnotr)rs rnegaters 2%<rcPeZdZdZdZd dZdZdZdZdZ d Z d Z d Z d Z dS)rIuInternal 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)* ('@integer' samples)? ('@decimal' samples)? and_condition = relation ('and' relation)* relation = is_relation | in_relation | within_relation is_relation = expr 'is' ('not')? value in_relation = expr (('not')? 'in' | '=' | '!=') range_list within_relation = expr ('not')? 'within' range_list expr = operand (('mod' | '%') value)? operand = 'n' | 'i' | 'f' | 't' | 'v' | 'w' range_list = (range | value) (',' range_list)* value = digit+ digit = 0|1|2|3|4|5|6|7|8|9 range = value'..'value samples = sampleRange (',' sampleRange)* (',' ('…'|'...'))? sampleRange = decimalValue '~' decimalValue decimalValue = 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'. - Samples are ignored. The translator parses the expression on instantiation into an attribute called `ast`. ct||_|js d|_dS||_|jr#t d|jdddS)NzExpected end of rule, got rr)rrrJ conditionr)rLstrings rrPz_Parser.__init__ss#F++ { DH F>>## ; QOR9KOOPP P Q QrNct|j||}||S|t|dur|p|}|jstd|dtd|d|jdd)Nz expected z but end of rule reachedz but got rr)rrreprr)rLrrtermtokens rexpectz_Parser.expects4;u55  L < /%8599D{ HFFFFGG GIDII4;r?13EIIJJJrc|}t|jddr.d||ff}t|jdd.|S)Nror) and_conditionrrrLops rrz_Parser.conditionsa    ! !fd33 2D..0011Bfd33 2 rc|}t|jddr.d||ff}t|jdd.|S)Nrand)relationrrrs rrz_Parser.and_conditionsY ]]__fe44 .T]]__--Bfe44 . rc|}t|jddr0t|jddrdpd||ffSt|jdd}d}t|jddrd}nz"_binary_compiler.. s)TT\\$-?-?eATAT,U%Urrrs`r_binary_compilerr s U U U UUrcfdS)rc4||zSrr)rLxrs rrz!_unary_compiler..s4$,,q//1rrrs`r_unary_compilerr s 1 1 1 11rcdS)Nr rr s rrrsrceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z ed Zed ZedZedZedZedZdZdS) _CompilerzZThe compilers are able to transform the expressions into multiple output formats. c8|\}}t|d||S)Ncompile_)getattr)rLargrr[s rrgz_Compiler.compiles(D-wt___--t44rcdS)Nr-rrs rrz_Compiler. #rcdS)Nr.rrs rrz_Compiler.!rrcdS)Nr4rrs rrz_Compiler."rrcdS)Nr5rrs rrz_Compiler.#rrcdS)Nr6rrs rrz_Compiler.$rrcdS)Nr7rrs rrz_Compiler.%rrcdS)Nr8rrs rrz_Compiler.&rrcdS)Nr9rrs rrz_Compiler.'rrc t|Srr)r r4s rrz_Compiler.(s Qrz (%s && %s)z (%s || %s)z(!%s)z (%s %% %s)z (%s == %s)z (%s != %s)ctr)NotImplementedError)rLrrOrs rcompile_relationz_Compiler.compile_relation0s!###rN)rZrxryrzrg compile_n compile_i compile_v compile_w compile_f compile_t compile_c compile_e compile_valuer compile_and compile_orr  compile_not compile_mod compile_is compile_isnotr!rrrrrs555 I I I I I I I I''M""<00K!!,//J!/'**K""<00K!!,//J$$\22M$$$$$rrcpeZdZdZedZedZedZedZ dZ dS)rz!Compiles an expression to Python.z (%s and %s)z (%s or %s)z(not %s)z MOD(%s, %s)cdfd|dD}|d|d|dS)Nrctg|]4\}}d|d|d5S)(rR)r)rrrrLs rrUz4_PythonCompiler.compile_relation..=sEaaa!QDt||ADD$,,q//DDDaaarrr4z, [z]))r*upperrg)rLrrOrrangess` rr!z _PythonCompiler.compile_relation<scaaaaS]^_S`aaabb,,..DD4<<#5#5DD&DDDDrN) rZrxryrzrr+r,r r-r.r!rrrrr4sm++""=11K!!,//J!/*--K""=11KEEEEErrc6eZdZdZejZeZeZ eZ eZ dZ dS)rz)Compile into a gettext plural expression.c |g}||}|dD]}|d|dkr6|d|d||ddJt|j|\}}|d|d|d|d|d dd |dS) Nrrr4z == r5z >=  && z <= z || )rgrKmapr*)rLrrOrritemminmaxs rr!z!_GettextCompiler.compile_relationJs ||D!!qM C CDAw$q'!! @d@@ T!W(=(=@@@AAAAt|T22S AdAAAAAA3AAABBBB%6;;r??%%%%rN) rZrxryrzrr"r# compile_zeror$r%r&r'r!rrrrrAsE33#IIIII & & & & &rrc.eZdZdZdZeZeZeZeZ dZ dS)rz/Compiles the expression to plain of JavaScript.cdS)NzparseInt(n, 10)rrs rrz_JavaScriptCompiler.[s+rct||||}|dkr!||}d|d|d|d}|S)Nrz (parseInt(z , 10) == r:r5)rr!rg)rLrrOrrs rr!z$_JavaScriptCompiler.compile_relationas_00 &$ ,, T>><<%%D@@@t@@@@@D rN) rZrxryrzr#r?r$r%r&r'r!rrrrrVsG99,+IIIIIrrceZdZdZedZedZedZedZedZ dZ d d Z d S) rfz+Returns a unicode pluralization rule again.z%s is %sz %s is not %sz %s and %sz%s or %sz %s mod %sc(|j|dddiS)NrrT)r!)rLrs rr-z_UnicodeCompiler.compile_notws$t$hqk@4@@@rFc g}|dD]}|d|dkr/|||dC|||dd||d|||rdndd|dd|S)Nrrz..z notrrWr)rKrgr*)rLrrOrrr7r<s rr!z!_UnicodeCompiler.compile_relationzsqM S SDAw$q'!! dll47334444 d1g!6!6QQ$,,tAw:O:OQQRRRR,,t$$]&?ffR]]&]]388TZK[K[]]]rN)F) rZrxryrzrr/r0r+r,r.r-r!rrrrfrfjs55 "!*--J$$^44M"";//K!!*--J"";//KAAA^^^^^^rrf)rrrr)r~r]rr)r~r]rr)rrrrrr)rr$rr$rr$)rrrrr)rrrrrrrr)rrrrrr)rr"rr)rrrr)rrrr)rrrr)0rz __future__rr%recollections.abcrrtypingrrrtyping_extensionsr rFrr:r<rrvrrrr ExceptionrrrgUNICODEr*r__annotations__rrrrrrrrIrr r?rrrrrfrrrrNs#""""" --------//////////*))))))=  8"8"8"8"vZZZZZZZZz.%!%!%!%!P.BBBB(IIII(.))))) )))    :2:fbj ) )* ZRZRbggennRRR S ST jbj  ! zrz+&&'-rz::; 4,22222 $$$$ w8w8w8w8w8w8w8w8tVVV 222 } $$$$$$$$: E E E E Ei E E E&&&&&y&&&**(^^^^^y^^^^^r