File: //lib/python3.9/site-packages/babel/__pycache__/plural.cpython-39.pyc
a
�`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%�ZdCd&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 )Dz�
babel.numbers
~~~~~~~~~~~~~
CLDR Plural support. See UTS #35.
:copyright: (c) 2013-2021 by the Babel Team.
:license: BSD, see LICENSE for more details.
� N)�decimal)ZzeroZoneZtwo�few�many�otherr c C s� t | �}t|�}t|t�r6||kr(|}nt�t|��}t|tj�r�|�� }|j}|dk rf|j |d� nd}d�
dd� |D ��}|�d�}t|�}t|�} t|p�d�}
t|p�d�}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 �0/usr/lib/python3.9/site-packages/babel/plural.py� <genexpr>A � z#extract_operands.<locals>.<genexpr>�0)
�abs�int�
isinstance�floatr ZDecimalr
Zas_tupleZexponent�digits�join�rstrip�len)�source�n�iZ dec_tupleZexpZfraction_digitsZtrailingZno_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 ]Z\}}|tvrHtd| ��n||v r\td| ��|� |� t
|�j}|r*| j�||f� q*dS )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"