HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/babel/__pycache__/plural.cpython-310.pyc
o

!we�Z�	@s�UdZddlmZddlZddlZddlmZmZddlm	Z	m
Z
mZe	r+ddlm
Z
dZdZdfd
d�ZGdd�d�Zdgdd�Zdhdd�Zdgdd�Zdidd �Zdid!d"�Zdjd&d'�ZGd(d)�d)e�Zhd*�Zde�d+ej�fd,e�d-d.�e��d/��fd0e�d1�fd2e�d3�fd4e�d5ej�fgZd6ed7<dkd:d;�Z 	dldmd@dA�Z!dldndBdC�Z"dodFdG�Z#dpdJdK�Z$dqdMdN�Z%drdRdS�Z&GdTdU�dU�Z'dVdW�Z(dXdY�Z)dZd[�Z*Gd\d]�d]�Z+Gd^d_�d_e+�Z,Gd`da�dae+�Z-Gdbdc�dce-�Z.Gddde�dee+�Z/dS)sz�
    babel.numbers
    ~~~~~~~~~~~~~

    CLDR Plural support.  See UTS #35.

    :copyright: (c) 2013-2023 by the Babel Team.
    :license: BSD, see LICENSE for more details.
�)�annotationsN)�Iterable�Mapping)�
TYPE_CHECKING�Any�Callable)�Literal)�zero�one�two�few�many�otherr�source�float | decimal.Decimal�return�Mtuple[decimal.Decimal | int, int, int, int, int, int, Literal[0], Literal[0]]cCs�t|�}t|�}t|t�r||kr|}nt�t|��}t|tj�rY|��}|j}|dkr3|j	|d�nd}d�
dd�|D��}|�d�}t|�}t|�}	t|pPd�}
t|pVd�}nd}}	}
}d}}
||||	|
|||
fS)u�Extract operands from a decimal, a float or an int, according to `CLDR rules`_.

    The result is an 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]
    rN��css�|]}t|�VqdS�N��str)�.0�drr�E/home/arjun/projects/env/lib/python3.10/site-packages/babel/plural.py�	<genexpr>G��z#extract_operands.<locals>.<genexpr>�0)
�abs�int�
isinstance�float�decimal�Decimalr�as_tuple�exponent�digits�join�rstrip�len)r�n�i�	dec_tuple�exp�fraction_digits�trailing�no_trailing�v�w�f�t�c�errr�extract_operandss&

r7c@speZdZdZdZd dd�Zd!d
d�Zed"d
d��Ze	d#dd��Z
e	d$dd��Zd%dd�Zd&dd�Z
d'dd�ZdS)(�
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�_func�rules�-Mapping[str, str] | Iterable[tuple[str, str]]r�NonecCs�t|t�r	|��}t�}g|_t|�D]/\}}|tvr"td|����||vr.td|�d���|�|�t	|�j
}|rB|j�||f�qdS)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 r�items�setr9�sorted�_plural_tags�
ValueError�add�_Parser�ast�append)�selfr;�found�key�exprrErrr�__init__js


��zPluralRule.__init__rcs6|j�d��fdd�tD��}dt|�j�d|�d�S)N�, cs&g|]}|�vr|�d�|���qS)z: r�r�tag�r;rr�
<listcomp>�s&z'PluralRule.__repr__.<locals>.<listcomp>�<� �>)r;r'rA�type�__name__)rG�argsrrOr�__repr__�szPluralRule.__repr__�:Mapping[str, str] | Iterable[tuple[str, str]] | PluralRulecCst|t�r|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 r8)�clsr;rrr�parse�s
zPluralRule.parse�Mapping[str, str]cst�j��fdd�|jD�S)z�The `PluralRule` as a dict of unicode plural rules.

        >>> rule = PluralRule({'one': 'n is 1'})
        >>> rule.rules
        {'one': 'n is 1'}
        csi|]	\}}|�|��qSrr)rrNrE��_compilerr�
<dictcomp>�sz$PluralRule.rules.<locals>.<dictcomp>)�_UnicodeCompiler�compiler9�rGrr\rr;�szPluralRule.rules�frozenset[str]cCstdd�|jD��S)z�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.
        css�|]}|dVqdS)rNr)rr+rrrr�rz"PluralRule.tags.<locals>.<genexpr>)�	frozensetr9rarrr�tags�szPluralRule.tags�list[tuple[str, Any]]cCs|jSr�r9rarrr�__getstate__��zPluralRule.__getstate__r9cCs
||_dSrrf)rGr9rrr�__setstate__��
zPluralRule.__setstate__r*rcCst|d�s
t|�|_|�|�S)Nr:)�hasattr�	to_pythonr:)rGr*rrr�__call__�s


zPluralRule.__call__N)r;r<rr=)rr)r;rXrr8)rr[)rrb)rre)r9rerr=)r*rrr)rU�
__module__�__qualname__�__doc__�	__slots__rKrW�classmethodrZ�propertyr;rdrgrirmrrrrr8Ss




r8�rulerXrcCsVt�j}dg}t�|�jD]\}}|�||��d|�d��q
|�dt�d�|�S)a�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
    z(function(n) { return � ? � : z%r; })r)�_JavaScriptCompilerr`r8rZr9rF�
_fallback_tagr')rt�to_js�resultrNrErrr�
to_javascript�s
r{�(Callable[[float | decimal.Decimal], str]cCs�ttttd�}t�j}ddg}t�|�jD]\}}|�	d||��dt
|����q|�	dt���td�|�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
    )�IN�WITHIN�MODr7zdef evaluate(n):z- n, i, v, w, f, t, c, e = extract_operands(n)z if (z
): return z return �
z<rule>�exec�evaluate)�
in_range_list�within_range_list�cldr_modulor7�_PythonCompilerr`r8rZr9rFrrxr'�eval)rt�	namespace�to_python_funcrzrNrE�coderrrrl�s�� 
rlcs�t�|�}|jthB�t�j}�fdd�tD�j}dt���d�g}|j	D]\}}|�
||��d||��d��q%|�
|t��d��d�|�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
    csg|]}|�vr|�qSrrrM��	used_tagsrrrP��zto_gettext.<locals>.<listcomp>z	nplurals=z
; plural=(rurvz);r)r8rZrdrx�_GettextCompilerr`rA�indexr)r9rFr')rtr]�
_get_indexrzrNrErr�r�
to_gettext�s

 
r��num�
range_list�+Iterable[Iterable[float | decimal.Decimal]]�boolcCs|t|�ko
t||�S)a�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
    )rr��r�r�rrrr��r�cst�fdd�|D��S)a�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
�|kVqdSrr)r�min_�max_�r�rrr+s�"z$within_range_list.<locals>.<genexpr>)�anyr�rr�rr�r�r��ar!�bcCs@d}|dkr|d9}d}|dkr|d9}||}|r|d9}|S)z�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
    r����r)r�r��reverse�rvrrrr�.sr�c@seZdZdZdS)�	RuleErrorzRaised if a rule is malformed.N)rUrnrorprrrrr�Esr�>r5r6r3r+r*r4r1r2z\s+�wordz"\b(and|or|is|(?:with)?in|not|mod|[rz])\b�valuez\d+�symbolz%|,|!=|=�ellipsisz\.{2,3}|\u2026z(list[tuple[str | None, re.Pattern[str]]]�_RULES�s�list[tuple[str, str]]cCs�|�d�d}g}d}t|�}||krAtD]\}}|�||�}|dur4|��}|r2|�||��f�n	qtd||��||ks|ddd�S)N�@rz5malformed CLDR pluralization rule.  Got unexpected %rr�)�splitr)r��match�endrF�groupr�)r�rz�posr��tokrtr�rrr�
tokenize_rule]s$���r��tokens�type_�
str | None�list[tuple[str, str]] | boolcCs,|o|dd|ko|dup|dd|kS)Nr�rr�r�r�r�r�rrr�test_next_tokenps�r�cCst|||�r
|��SdSr)r��popr�rrr�
skip_tokenys�r�r�#tuple[Literal['value'], tuple[int]]cC�
d|ffS)Nr�r)r�rrr�
value_node~rjr��name�tuple[str, tuple[()]]cCs|dfS)Nrr)r�rrr�
ident_node�sr��Ituple[Literal['range_list'], Iterable[Iterable[float | decimal.Decimal]]]cCsd|fS)Nr�r)r�rrr�range_list_node�sr�r��tuple[Any, ...]�-tuple[Literal['not'], tuple[tuple[Any, ...]]]cCr�)N�notr)r�rrr�negate�rjr�c@sbeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rDu�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)*
                        ('@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`.
    cCsFt|�|_|js
d|_dS|��|_|jr!td|jdd����dS)NzExpected end of rule, got r�r�)r�r�rE�	conditionr�)rG�stringrrrrK�s

�z_Parser.__init__NcCsjt|j||�}|dur
|S|durt|dur|p|�}|js&td|�d���td|�d|jdd����)Nz	expected z but end of rule reachedz	 but got r�r�)r�r��reprr�)rGr�r��term�tokenrrr�expect�sz_Parser.expectcC�8|��}t|jdd�rd||��ff}t|jdd�s|S)Nr��or)�
and_conditionr�r��rG�oprrrr���
�z_Parser.conditioncCr�)Nr��and)�relationr�r�r�rrrr��r�z_Parser.and_conditioncCs�|��}t|jdd�rt|jdd�rdpd||��ffSt|jdd�}d}t|jdd�r/d}nt|jdd�sA|r<td��|�|�Sd|||��ff}|rPt|�S|S)	Nr��isr��isnot�in�withinz#Cannot negate operator based rules.r�)rJr�r�r�r��newfangled_relationr�r�)rG�left�negated�methodr�rrrr��s
�
z_Parser.relationcCsRt|jdd�r
d}nt|jdd�rd}ntd��dd||��ff}|r't|�S|S)	Nr��=Fz!=Tz'Expected "=" or "!=" or legacy relationr�r�)r�r�r�r�r�)rGr�r�r�rrrr��sz_Parser.newfangled_relationcCs(|��}t|jd�r||��fS||fS)Nr�)r�r�r�)rGr�rrr�range_or_value�sz_Parser.range_or_valuecCs<|��g}t|jdd�r|�|���t|jdd�st|�S)Nr��,)r�r�r�rFr�)rGr�rrrr��s

�z_Parser.range_listcCs|t|jd�}|dus|dtvrtd��|d}t|jdd�r)d|df|��ffSt|jdd�r:d|df|��ffSt|�S)Nr�r�zExpected identifier variable�modrr��%)r�r��_VARSr�r�r�)rGr�r�rrrrJ�sz_Parser.exprcCstt|�d�d��S)Nr�r�)r�rr�rarrrr�sz
_Parser.value)NN)rUrnrorprKr�r�r�r�r�r�r�rJr�rrrrrD�s!


rDc��fdd�S)�%Compiler factory for the `_Compiler`.cs�|�|�|�|�fSr�r`)rGr��right��tmplrr�<lambda>r�z"_binary_compiler.<locals>.<lambda>rr�rr�r�_binary_compiler
�r�cr�)r�cs�|�|�Srr�)rG�xr�rrr�sz!_unary_compiler.<locals>.<lambda>rr�rr�r�_unary_compilerr�r�cC�dS)Nrr�r�rrrr��r�c@s�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zd	d�Z	d
d�Z
dd�Zdd�Zd
d�Z
ed�Zed�Zed�Zed�Zed�Zed�Zdd�ZdS)�	_CompilerzZThe compilers are able to transform the expressions into multiple
    output formats.
    cCs|\}}t|d|���|�S)N�compile_)�getattr)rG�argr�rVrrrr`sz_Compiler.compilecCr�)Nr*rr�rrrr� r�z_Compiler.<lambda>cCr�)Nr+rr�rrrr�!r�cCr�)Nr1rr�rrrr�"r�cCr�)Nr2rr�rrrr�#r�cCr�)Nr3rr�rrrr�$r�cCr�)Nr4rr�rrrr�%r�cCr�)Nr5rr�rrrr�&r�cCr�)Nr6rr�rrrr�'r�cCst|�Srr)r�r1rrrr�(sz
(%s && %s)z
(%s || %s)z(!%s)z
(%s %% %s)z
(%s == %s)z
(%s != %s)cCst��r)�NotImplementedError)rGr�rJr�rrr�compile_relation0rhz_Compiler.compile_relationN)rUrnrorpr`�	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�rrrrr�s&r�c@s8eZdZdZed�Zed�Zed�Zed�Z	dd�Z
dS)	r�z!Compiles an expression to Python.z(%s and %s)z
(%s or %s)z(not %s)zMOD(%s, %s)cs<d��fdd�|dD��}|���d��|��d|�d�S)Nr�cs.g|]\}}d��|��d��|��d��qS)�(rL�)r�)rr�r�rarrrP=s.z4_PythonCompiler.compile_relation.<locals>.<listcomp>r�rz, [z]))r'�upperr`)rGr�rJr��rangesrrarr�<s z _PythonCompiler.compile_relationN)rUrnrorpr�r�rr�rrr�rrrrr�4sr�c@s.eZdZdZejZeZeZ	eZ
eZdd�ZdS)r�z)Compile into a gettext plural expression.cCs�g}|�|�}|dD]6}|d|dkr'|�d|�d|�|d��d��qt|j|�\}}|�d|�d|�d|�d|�d�	�qdd	�|��d�S)
Nr�rrz == rz >= � && z <= z || )r`rF�mapr')rGr�rJr�r��item�min�maxrrrr�Js
$&z!_GettextCompiler.compile_relationN)
rUrnrorpr�r�r��compile_zeror�r�r�r�r�rrrrr�Asr�c@s0eZdZdZdd�ZeZeZeZeZ	dd�Z
dS)rwz/Compiles the expression to plain of JavaScript.cCr�)NzparseInt(n, 10)rr�rrrr�[r�z_JavaScriptCompiler.<lambda>cCs>t�||||�}|dkr|�|�}d|�d|�d|�d�}|S)Nr�z
(parseInt(z	, 10) == r	r)r�r�r`)rGr�rJr�r�rrrr�as�
z$_JavaScriptCompiler.compile_relationN)rUrnrorpr�rr�r�r�r�r�rrrrrwVsrwc@sJeZdZdZed�Zed�Zed�Zed�Zed�Z	dd�Z
d
d
d�ZdS)r_z+Returns a unicode pluralization rule again.z%s is %sz%s is not %sz	%s and %sz%s or %sz	%s mod %scCs|j|dddi�S)Nr�r�T)r�)rGr�rrrrwsz_UnicodeCompiler.compile_notFc	Cs�g}|dD])}|d|dkr|�|�|d��q|�|�|d��d|�|d����q|�|��|r9dnd�d|�dd�|���S)Nr�rz..z notrrRr�)rFr`r')rGr�rJr�r�rrrrrr�zs*,z!_UnicodeCompiler.compile_relationN)F)rUrnrorpr�rrr�rrrr�rrrrr_jsr_)rrrr)rtrXrr)rtrXrr|)r�rr�r�rr�)r�r!r�r!rr!)r�rrr�r)r�r�r�rr�r�rr�)r�r�r�rr�r�)r�rrr�)r�rrr�)r�r�rr�)r�r�rr�)0rp�
__future__rr"�re�collections.abcrr�typingrrr�typing_extensionsrrArxr7r8r{rlr�r�r�r��	Exceptionr�r�r`�UNICODEr'r��__annotations__r�r�r�r�r�r�r�rDr�r�rr�r�r�rwr_rrrr�<module>sV	
;
]

(


�
	�	



z