CasperSecurity

Current Path : /lib/python3/dist-packages/babel/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/babel/__pycache__/plural.cpython-310.pyc

o

V��\BS�	@s�dZddlZddlmZdZdZdd�ZGdd	�d	e�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZGdd�de�ZdZde�dej�fde�d�e��fde�d�fde�d�fd e�d!ej�fgZd"d#�ZdBd$d%�ZdBd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�ZGd0d1�d1e�Zd2d3�Zd4d5�Zd6d7�Z Gd8d9�d9e�Z!Gd:d;�d;e!�Z"Gd<d=�d=e!�Z#Gd>d?�d?e#�Z$Gd@dA�dAe!�Z%dS)Cz�
    babel.numbers
    ~~~~~~~~~~~~~

    CLDR Plural support.  See UTS #35.

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
�N)�decimal)�zero�one�two�few�many�otherrcCs�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}}	}
}||||	|
|fS)a#Extract operands from a decimal, a float or an int, according to `CLDR rules`_.

    The result is a 6-tuple (n, i, v, w, f, t), 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.
    ====== ===============================================================

    .. _`CLDR rules`: https://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#Operands

    :param source: A real number
    :type source: int|float|decimal.Decimal
    :return: A n-i-v-w-f-t tuple
    :rtype: tuple[decimal.Decimal, int, int, int, int, int]
    rN��css�|]}t|�VqdS�N��str)�.0�dr	r	�./usr/lib/python3/dist-packages/babel/plural.py�	<genexpr>As�z#extract_operands.<locals>.<genexpr>�0)
�abs�int�
isinstance�floatr�Decimalr
�as_tuple�exponent�digits�join�rstrip�len)�source�n�i�	dec_tuple�exp�fraction_digits�trailing�no_trailing�v�w�f�tr	r	r�extract_operandss$

r*c@sdeZdZdZdZdd�Zdd�Zedd��Ze	d	d
��Z
e	dd�d
d�Zdd�Zdd�Z
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�_funccCs�t|t�r	|��}t�}g|_tt|��D],\}}|tvr#td|��||vr-td|��|�	|�t
|�j}|rA|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
        zunknown tag %rztag %r defined twiceN)
r�dict�items�setr,�sorted�list�_plural_tags�
ValueError�add�_Parser�ast�append)�self�rules�found�key�exprr7r	r	r�__init__cs


��zPluralRule.__init__cs,|j�dt|�jd��fdd�tD��fS)Nz<%s %r>z, cs$g|]}|�vrd|�|f�qS)z%s: %sr	�r�tag�r:r	r�
<listcomp>}s�z'PluralRule.__repr__.<locals>.<listcomp>)r:�type�__name__rr3�r9r	rAr�__repr__ys
�zPluralRule.__repr__cCst||�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)�clsr:r	r	r�parse�s
zPluralRule.parsecs t�j�t�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'}
        csg|]
\}}|�|�f�qSr	r	)rr@r7��_compiler	rrB�sz$PluralRule.rules.<locals>.<listcomp>)�_UnicodeCompiler�compiler.r,rEr	rIrr:�szPluralRule.rulescCstdd�|jD��S)NcSsg|]}|d�qS)rr	)rr r	r	rrB��z'PluralRule.<lambda>.<locals>.<listcomp>)�	frozensetr,��xr	r	r�<lambda>�rMzPluralRule.<lambda>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.)�doccCs|jSr�r,rEr	r	r�__getstate__��zPluralRule.__getstate__cCs
||_dSrrS)r9r,r	r	r�__setstate__��
zPluralRule.__setstate__cCst|d�s
t|�|_|�|�S)Nr-)�hasattr�	to_pythonr-)r9rr	r	r�__call__�s


zPluralRule.__call__N)rD�
__module__�__qualname__�__doc__�	__slots__r>rF�classmethodrH�propertyr:�tagsrTrVrZr	r	r	rr+Ls


r+cCsRt�j}dg}t�|�jD]\}}|�d||�|f�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
%s ? %r : z%r; })r
)�_JavaScriptCompilerrLr+rHr,r8�
_fallback_tagr)�rule�to_js�resultr@r7r	r	r�
to_javascript�s
rgcCs�ttttd�}t�j}ddg}t�|�jD]\}}|�	d||�t
|�f�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�MODr*zdef evaluate(n):z' n, i, v, w, f, t = extract_operands(n)z if (%s): return %rz
 return %r�
z<rule>�exec�evaluate)�
in_range_list�within_range_list�cldr_modulor*�_PythonCompilerrLr+rHr,r8r
rcr�eval)rd�	namespace�to_python_funcrfr@r7�coder	r	rrY�s��
rYcs�t�|�}|jthB�t�j}�fdd�tD�j}dt��g}|j	D]\}}|�
d||�||�f�q#|�
d|t��d�|�S)a~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
    csg|]}|�vr|�qSr	r	r?��	used_tagsr	rrB��zto_gettext.<locals>.<listcomp>znplurals=%d; plural=(z
%s ? %d : z%d)r
)r+rHrarc�_GettextCompilerrLr3�indexrr,r8r)rdrJ�
_get_indexrfr@r7r	rvr�
to_gettext�s


r|cCs|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
    )rro��num�
range_listr	r	rrn��rncst�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~r	rr$s�"z$within_range_list.<locals>.<genexpr>)�anyr}r	r�rror�rocCs@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	)�a�b�reverse�rvr	r	rrp'srpc@seZdZdZdS)�	RuleErrorzRaised if a rule is malformed.N)rDr[r\r]r	r	r	rr�>sr��nivwftz\s+�wordz)\b(and|or|is|(?:with)?in|not|mod|[{0}])\b�valuez\d+�symbolz%|,|!=|=�ellipsisz\.{2,3}|\u2026cCs�|�d�d}g}d}t|�}||krAtD]\}}|�||�}|dur4|��}|r2|�||��f�n	qtd||��||ks|ddd�S)N�@rz5malformed CLDR pluralization rule.  Got unexpected %rr�)�splitr�_RULES�match�endr8�groupr�)�srf�posr��tokrdr�r	r	r�
tokenize_ruleMs$���r�cCs,|o|dd|ko|dup|dd|kS)Nr�rr�r	��tokens�type_r�r	r	r�test_next_token`s�r�cCst|||�r
|��SdSr)r��popr�r	r	r�
skip_tokenes�r�cC�
d|ffS)Nr�r	)r�r	r	r�
value_nodejrWr�cCs|dfS)Nr	r	)�namer	r	r�
ident_noden�r�cCsd|fS)Nrr	)rr	r	r�range_list_noderr�r�cCr�)N�notr	)r�r	r	r�negatevrWr�c@sbeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r6u�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 instanciation into an attribute
    called `ast`.
    cCsDt|�|_|js
d|_dS|��|_|jr td|jdd��dS)NzExpected end of rule, got %rr�r�)r�r�r7�	conditionr�)r9�stringr	r	rr>�s

��z_Parser.__init__NcCsbt|j||�}|dur
|S|durt|dur|p|�}|js$td|��td||jddf��)Nz#expected %s but end of rule reachedzexpected %s but got %rr�r�)r�r��reprr�)r9r�r��term�tokenr	r	r�expect�sz_Parser.expectcC�8|��}t|jdd�rd||��ff}t|jdd�s|S)Nr��or)�
and_conditionr�r��r9�opr	r	rr���
�z_Parser.conditioncCr�)Nr��and)�relationr�r�r�r	r	rr��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�)r=r�r�r�r��newfangled_relationrr�)r9�left�negated�methodr�r	r	rr��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�rr�)r9r�r�r�r	r	rr��sz_Parser.newfangled_relationcCs(|��}t|jd�r||��fS||fS)Nr�)r�r�r�)r9r�r	r	r�range_or_value�sz_Parser.range_or_valuecCs<|��g}t|jdd�r|�|���t|jdd�st|�S)Nr��,)r�r�r�r8r�)r9rr	r	rr�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�modr	r��%)r�r��_VARSr�r�r�)r9r�r�r	r	rr=�sz_Parser.exprcCstt|�d�d��S)Nr�r�)r�rr�rEr	r	rr��sz
_Parser.value)NN)rDr[r\r]r>r�r�r�r�r�r�rr=r�r	r	r	rr6zs!


r6c��fdd�S)�%Compiler factory for the `_Compiler`.cs�|�|�|�|�fSr�rL)r9�l�r��tmplr	rrQ�rxz"_binary_compiler.<locals>.<lambda>r	r�r	r�r�_binary_compiler��r�cr�)r�cs�|�|�Srr�)r9rPr�r	rrQ�sz!_unary_compiler.<locals>.<lambda>r	r�r	r�r�_unary_compiler�r�r�cC�dS)Nrr	rOr	r	rrQ��rQc@s�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zd	d�Z	d
d�Z
dd�Zed�Z
ed
�Zed�Zed�Zed�Zed�Zdd�ZdS)�	_CompilerzZThe compilers are able to transform the expressions into multiple
    output formats.
    cCs|\}}t|d|�|�S)N�compile_)�getattr)r9�argr��argsr	r	rrLsz_Compiler.compilecCr�)Nrr	rOr	r	rrQr�z_Compiler.<lambda>cCr�)Nr r	rOr	r	rrQr�cCr�)Nr&r	rOr	r	rrQ
r�cCr�)Nr'r	rOr	r	rrQr�cCr�)Nr(r	rOr	r	rrQr�cCr�)Nr)r	rOr	r	rrQr�cCst|�Srr)rPr&r	r	rrQsz
(%s && %s)z
(%s || %s)z(!%s)z
(%s %% %s)�
(%s == %s)z
(%s != %s)cCst��r)�NotImplementedError)r9r�r=rr	r	r�compile_relationrUz_Compiler.compile_relationN)rDr[r\r]rL�	compile_n�	compile_i�	compile_v�	compile_w�	compile_f�	compile_t�
compile_valuer��compile_and�
compile_orr��compile_not�compile_mod�
compile_is�
compile_isnotr�r	r	r	rr�s"r�c@s8eZdZdZed�Zed�Zed�Zed�Z	dd�Z
dS)	rqz!Compiles an expression to Python.z(%s and %s)z
(%s or %s)z(not %s)zMOD(%s, %s)cs8dd��fdd�|dD��}d|����|�|fS)Nz[%s]r�cs g|]}dtt�j|���qS)z(%s, %s))�tuple�maprL)r�range_rEr	rrB's�z4_PythonCompiler.compile_relation.<locals>.<listcomp>r�z
%s(%s, %s))r�upperrL)r9r�r=r�compile_range_listr	rErr�%s
���z _PythonCompiler.compile_relationN)rDr[r\r]r�r�r�r�r�r�r�r	r	r	rrqsrqc@s.eZdZdZejZeZeZ	eZ
eZdd�ZdS)ryz)Compile into a gettext plural expression.c	Cs~g}|�|�}|dD],}|d|dkr$|�d||�|d�f�qt|j|�\}}|�d||||f�qdd�|�S)Nr�rr�z(%s >= %s && %s <= %s)z(%s)z || )rLr8r�r)r9r�r=rr��item�min�maxr	r	rr�6s 

�
�z!_GettextCompiler.compile_relationN)
rDr[r\r]r�r�r��compile_zeror�r�r�r�r�r	r	r	rry-sryc@s0eZdZdZdd�ZeZeZeZeZ	dd�Z
dS)rbz/Compiles the expression to plain of JavaScript.cCr�)NzparseInt(n, 10)r	rOr	r	rrQOr�z_JavaScriptCompiler.<lambda>cCs4t�||||�}|dkr|�|�}d|||f}|S)Nr�z(parseInt(%s, 10) == %s && %s))ryr�rL)r9r�r=rrur	r	rr�Us�
z$_JavaScriptCompiler.compile_relationN)rDr[r\r]r�r�r�r�r�r�r�r	r	r	rrbJsrbc@sJeZdZdZed�Zed�Zed�Zed�Zed�Z	dd�Z
d
d
d�ZdS)rKz+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�)r9r�r	r	rr�ksz_UnicodeCompiler.compile_notFcCsvg}|dD]"}|d|dkr|�|�|d��q|�dtt|j|���qd|�|�|r2dp3d|d�|�fS)Nr�rz%s..%sz
%s%s %s %sz notr
r�)r8rLr�r�r)r9r�r=rr��rangesr�r	r	rr�ns
�z!_UnicodeCompiler.compile_relationN)F)rDr[r\r]r�r�r�r�r�r�r�r�r	r	r	rrK^srKr)&r]�re�
babel._compatrr3rcr*�objectr+rgrYr|rnrorp�	Exceptionr�r�rL�UNICODE�formatr�r�r�r�r�r�r�r�r6r�r�r�r�rqryrbrKr	r	r	r�<module>sN	8](��


{
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY