File: //lib/python3.6/site-packages/babel/__pycache__/plural.cpython-36.opt-1.pyc
3
H��X@S � @ s� d Z ddlZddlmZ dFZd Zd
d� ZG dd
� d
e�Zdd� Z dd� Z
dd� Zdd� Zdd� Z
dd� ZG dd� de�ZdZdejdej�fdejdje��fd ejd!�fd"ejd#�fd$ejd%ej�fgZd&d'� ZdGd(d)�ZdHd*d+�Zd,d-� Zd.d/� Zd0d1� Zd2d3� ZG d4d5� d5e�Zd6d7� Zd8d9� Zd:d;� Z G d<d=� d=e�Z!G d>d?� d?e!�Z"G d@dA� dAe!�Z#G dBdC� dCe#�Z$G dDdE� dEe!�Z%dS )Iz�
babel.numbers
~~~~~~~~~~~~~
CLDR Plural support. See UTS #35.
:copyright: (c) 2013 by the Babel Team.
:license: BSD, see LICENSE for more details.
� N)�decimal�zero�one�two�few�many�otherc C s� t | �}t|�}t|t�r6||kr(|}ntjt|��}t|tj�r�|j� }|j}|dk rf|j |d� nf }dj
dd� |D ��}|jd�}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`: http://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�d� r
�/usr/lib/python3.6/plural.py� <genexpr>A s z#extract_operands.<locals>.<genexpr>�0)
�abs�int�
isinstance�floatr ZDecimalr
Zas_tupleZexponentZdigits�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
� dd�Zdd� Zdd� Z
dd� ZdS )�
PluralRuleae 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`: http://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#Language_Plural_Rules
�abstract�_funcc C s� t |t�r|j� }t� }g | _xjtt|��D ]Z\}}|tkrJtd| ��n||kr^td| ��|j |� t
|�j}|r,| jj||f� q,W 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! �sorted�list�_plural_tags�
ValueError�add�_Parser�ast�append)�self�rules�found�key�exprr, r
r
r �__init__c s
zPluralRule.__init__c s, | j � dt| �jdj� fdd�tD ��f S )Nz<%s %r>z, c s$ g | ]}|� krd |� | f �qS )z%s: %sr
)r �tag)r/ r
r �
<listcomp>} s z'PluralRule.__repr__.<locals>.<listcomp>)r/ �type�__name__r r( )r. r
)r/ 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 r4 r, )�_compiler
r r5 � s z$PluralRule.rules.<locals>.<listcomp>)�_UnicodeCompiler�compiler# r! )r. r
)r; r r/ � s zPluralRule.rulesc C s t dd� | jD ��S )Nc S s g | ]}|d �qS )r r
)r r r
r
r r5 � s z'PluralRule.<lambda>.<locals>.<listcomp>)� frozensetr! )�xr
r
r �<lambda>� s 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 )N)r! )r. r
r
r �__getstate__� s zPluralRule.__getstate__c C s
|| _ d S )N)r! )r. r! r
r
r �__setstate__� s zPluralRule.__setstate__c C s t | d�st| �| _| j|�S )Nr"