�
ƪbQV � �b � d Z ddlZddlZdZdZd� Z G d� d� � Zd� Zd � Zd
� Z d� Z
d� Zd
� Z G d� de
� � Zh d�Zd ej dej � � fd ej dd� e� � � d�� � fd ej d� � fd ej d� � fd ej dej � � fgZd� Zd2d�Zd2d�Zd� Zd � Zd!� Zd"� Z G d#� d$� � Zd%� Zd&� Zd'� Z G d(� d)� � Z G d*� d+e� � Z G d,� d-e� � Z! G d.� d/e!� � Z" G d0� d1e� � Z#dS )3z�
babel.numbers
~~~~~~~~~~~~~
CLDR Plural support. See UTS #35.
:copyright: (c) 2013-2022 by the Babel Team.
:license: BSD, see LICENSE for more details.
� N)�zero�one�two�few�many�otherr c �j � t | � � }t |� � }t |t � � r*||k r|}n!t j t
|� � � � }t |t j � � r�|� � � }|j }|dk r|j |d� nd}d�
d� |D � � � � }|� d� � }t |� � }t |� � } t |pd� � }
t |pd� � }ndx}x} x}
}dx}}
|||| |
|||
fS )u� Extract 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]
r N� � c 3 �4 K � | ]}t |� � V � �d S �N��str)�.0�ds �./usr/lib/python3/dist-packages/babel/plural.py� <genexpr>z#extract_operands.<locals>.<genexpr>A s( � � � �;�;�a�3�q�6�6�;�;�;�;�;�;� �0)
�abs�int�
isinstance�float�decimal�Decimalr �as_tuple�exponent�digits�join�rstrip�len)�source�n�i� dec_tuple�exp�fraction_digits�trailing�no_trailing�v�w�f�t�c�es r �extract_operandsr0 s< � �2 �F���A��A���A��!�U��� (���6�6��A�A� ���A���'�'�A��!�W�_�%�%� ��J�J�L�L� �� ��47�!�G�G�)�*�3�4�4�0�0����7�7�;�;�?�;�;�;�;�;���o�o�c�*�*����M�M���������
�A������ �q�!�!�������A���A�
�I�A���a��A�q�!�Q��!�!r c �| � e Zd ZdZdZd� Zd� Zed� � � Ze d� � � Z
e d� d� � � Zd
� Zd� Z
d� Zd
S )�
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 � � t |t � � r|� � � }t � � }g | _ t t
|� � � � D ]}\ }}|t vrt d|z � � �||v rt d|z � � �|� |� � t |� � j }|r| j � ||f� � �~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�setr3 �sorted�list�_plural_tags�
ValueError�add�_Parser�ast�append)�self�rules�found�key�exprr? s r �__init__zPluralRule.__init__d s� � � �e�T�"�"� "��K�K�M�M�E�������
���U���,�,� 1� 1�I�C���,�&�&� �!1�C�!7�8�8�8����� �!7�#�!=�>�>�>��I�I�c�N�N�N��$�-�-�#�C��
1��
�$�$�c�3�Z�0�0�0�� 1� 1r c � �� | j �dt | � � j �dd� �fd�t D � � � � �d�S )N�<� �, c �2 �� g | ]}|�v �|�d �| ����S )z: r
)r �tagrB s �r �
<listcomp>z'PluralRule.__repr__.<locals>.<listcomp>~ s8 �� � (� (� (����,�,� $'�3�3��c�
�
�3�&�,�,r �>)rB �type�__name__r r; )rA rB s @r �__repr__zPluralRule.__repr__z sh �� ��
�����J�J�����I�I� (� (� (� (�|� (� (� (�
)�
)�
)�
)�
�
r c �< |