File: //snap/core22/2133/usr/lib/python3/dist-packages/babel/__pycache__/plural.cpython-310.pyc
o
V��\BS � @ s� d Z ddlZddlmZ dZdZdd� ZG dd � d e�Zd
d� Z dd
� Z
dd� Zdd� Zdd� Z
dd� ZG dd� 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/� ZG d0d1� d1e�Zd2d3� Zd4d5� Zd6d7� Z G d8d9� d9e�Z!G d:d;� d;e!�Z"G d<d=� d=e!�Z#G d>d?� d?e#�Z$G d@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�otherr c C s� t | �}t|�}t|t�r||kr|}nt�t|��}t|tj�rY|�� }|j}|dk r3|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]
r N� � c s s � | ]}t |�V qd S �N��str)�.0�dr r �./usr/lib/python3/dist-packages/babel/plural.py� <genexpr>A s � 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_operands s$
r* c @ sd e Zd ZdZdZdd� Zdd� Zedd� �Ze d d
� �Z
e dd� d
d�Zdd� Zdd� Z
dd� ZdS )�
PluralRuleaf 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.
.. _`CLDR rules`: https://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#Language_Plural_Rules
)�abstract�_funcc C s� t |t�r |�� }t� }g | _tt|��D ],\}}|tvr#td| ��||v r-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�exprr7 r r r �__init__c s
��zPluralRule.__init__c s, | j � dt| �jd�� fdd�tD ��f S )Nz<%s %r>z, c s$ g | ]}|� v rd |� | f �qS )z%s: %sr �r �tag�r: r r �
<listcomp>} s �z'PluralRule.__repr__.<locals>.<listcomp>)r: �type�__name__r r3 �r9 r rA r �__repr__y s
�zPluralRule.__repr__c C s 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 )�clsr: r r r �parse� s
zPluralRule.parsec s 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'}
c s g | ]
\}}|� |�f�qS r r )r r@ r7 ��_compiler r rB � s z$PluralRule.rules.<locals>.<listcomp>)�_UnicodeCompiler�compiler. r, rE r rI r r: � s zPluralRule.rulesc C s t dd� | jD ��S )Nc S s g | ]}|d �qS )r r )r r r r r rB � � z'PluralRule.<lambda>.<locals>.<listcomp>)� frozensetr, ��xr r r �<lambda>� rM zPluralRule.<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.)�docc C s | j S r �r, rE r r r �__getstate__� � zPluralRule.__getstate__c C s
|| _ d S r rS )r9 r, r r r �__setstate__� �
zPluralRule.__setstate__c C s t | d�s
t| �| _| �|�S )Nr- )�hasattr� to_pythonr- )r9 r r r r �__call__� s
zPluralRule.__call__N)rD �
__module__�__qualname__�__doc__� __slots__r>