o
    l:^                     @   s&  d Z ddlZddlmZmZ ddlZddlmZm	Z	m
Z
 ddlmZmZ ze W n ey3   eZY nw edZG dd deZdLd	d
ZdLddZdLddZdLddZdefddZefddZdd ZdefddZ			dMddZefddZefdd Zefd!d"Zefd#d$Z efd%d&Z!efd'd(Z"d)d* Z#d+d, Z$dedfd-d.Z%G d/d0 d0e&Z'dedd1dfd2d3Z(dedd1dfd4d5Z)dedfd6d7Z*dedfd8d9Z+G d:d; d;e,Z-efd<d=Z.edfd>d?Z/d@Z0dAZ1dBe0 Z2dCe1 Z3dDZ4e5dEe2e3e4f Z6dFdG Z7dHdI Z8G dJdK dKe9Z:dS )Na  
    babel.numbers
    ~~~~~~~~~~~~~

    Locale dependent formatting and parsing of numeric data.

    The default locale for the functions in this module is determined by the
    following environment variables, in that order:

     * ``LC_NUMERIC``,
     * ``LC_ALL``, and
     * ``LANG``

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)datedatetime)default_localeLocale
get_global)decimalstring_types
LC_NUMERICc                   @   s   e Zd ZdZdd ZdS )UnknownCurrencyErrorzRException thrown when a currency is requested for which no data is available.
    c                 C   s   t | d|  || _dS )zkCreate the exception.
        :param identifier: the identifier string of the unsupported currency
        zUnknown currency %r.N)	Exception__init__
identifier)selfr    r   //usr/lib/python3/dist-packages/babel/numbers.pyr   +   s   
zUnknownCurrencyError.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r
   '   s    r
   c                 C   s,   | rt | j }t|S td}t|S )aM   Return a `set` of normalized currency codes.

    .. versionadded:: 2.5.0

    :param locale: filters returned currency codes by the provided locale.
                   Expected to be a locale instance or code. If no locale is
                   provided, returns the list of all currencies from all
                   locales.
    all_currencies)r   parse
currencieskeysr   set)localer   r   r   r   list_currencies5   s
   r   c                 C   s   | t |vr
t| dS )a   Check the currency code is recognized by Babel.

    Accepts a ``locale`` parameter for fined-grained validation, working as
    the one defined above in ``list_currencies()`` method.

    Raises a `UnknownCurrencyError` exception if the currency is unknown to Babel.
    N)r   r
   currencyr   r   r   r   validate_currencyG   s   r   c                 C   s8   | rt | ts	dS zt| | W dS  ty   Y dS w )zy Returns `True` only if a currency is recognized by Babel.

    This method always return a Boolean and never raise.
    FT)
isinstancer   r   r
   r   r   r   r   is_currencyS   s   r    c                 C   s$   t | tr	|  } t| |sdS | S )zReturns the normalized sting of any currency code.

    Accepts a ``locale`` parameter for fined-grained validation, working as
    the one defined above in ``list_currencies()`` method.

    Returns None if the currency is unknown to Babel.
    N)r   r   upperr    r   r   r   r   normalize_currencya   s
   

r"   c                 C   sH   t |}|dur||}|jd }| |v r||  | S |j| | S )a  Return the name used by the locale for the specified currency.

    >>> get_currency_name('USD', locale='en_US')
    u'US Dollar'

    .. versionadded:: 0.9.4

    :param currency: the currency code.
    :param count: the optional count.  If provided the currency name
                  will be pluralized to that number if possible.
    :param locale: the `Locale` object or locale identifier.
    Ncurrency_names_plural)r   r   plural_form_datar   get)r   countr   locr$   plural_namesr   r   r   get_currency_namep   s   


r*   c                 C   s   t |j| | S )zReturn the symbol used by the locale for the specified currency.

    >>> get_currency_symbol('USD', locale='en_US')
    u'$'

    :param currency: the currency code.
    :param locale: the `Locale` object or locale identifier.
    )r   r   currency_symbolsr&   r   r   r   r   get_currency_symbol   s   	r,   c                 C   s   t d}|| |d d S )zReturn currency's precision.

    Precision is the number of decimals found after the decimal point in the
    currency's format pattern.

    .. versionadded:: 2.5.0

    :param currency: the currency code.
    currency_fractionsDEFAULTr   )r   r&   )r   
precisionsr   r   r   get_currency_precision   s   
r0   c                 C   sN   t |}|dur ||}z|jd | W S  ty   Y nw |jd d S )aV  
    Return the unit pattern used for long display of a currency value
    for a given locale.
    This is a string containing ``{0}`` where the numeric part
    should be substituted and ``{1}`` where the currency long display
    name should be substituted.

    >>> get_currency_unit_pattern('USD', locale='en_US', count=10)
    u'{0} {1}'

    .. versionadded:: 2.7.0

    :param currency: the currency code.
    :param count: the optional count.  If provided the unit
                  pattern for that number will be returned.
    :param locale: the `Locale` object or locale identifier.
    Ncurrency_unit_patternsother)r   r   r$   r%   LookupError)r   r'   r   r(   r$   r   r   r   get_currency_unit_pattern   s   

r4   TFc                    s   t d}du rt n	ttr  du r n	t tr&   ||  d} fdd}g }	|D ]1\}
}}}|rEt| }|rKt| }|rO|sS|sj|rj|||rj|re|	|
|||d q9|	|
 q9|	S )as  Returns the list of currencies for the given territory that are valid for
    the given date range.  In addition to that the currency database
    distinguishes between tender and non-tender currencies.  By default only
    tender currencies are returned.

    The return value is a list of all currencies roughly ordered by the time
    of when the currency became active.  The longer the currency is being in
    use the more to the left of the list it will be.

    The start date defaults to today.  If no end date is given it will be the
    same as the start date.  Otherwise a range can be defined.  For instance
    this can be used to find the currencies in use in Austria between 1995 and
    2011:

    >>> from datetime import date
    >>> get_territory_currencies('AT', date(1995, 1, 1), date(2011, 1, 1))
    ['ATS', 'EUR']

    Likewise it's also possible to find all the currencies in use on a
    single date:

    >>> get_territory_currencies('AT', date(1995, 1, 1))
    ['ATS']
    >>> get_territory_currencies('AT', date(2011, 1, 1))
    ['EUR']

    By default the return value only includes tender currencies.  This
    however can be changed:

    >>> get_territory_currencies('US')
    ['USD']
    >>> get_territory_currencies('US', tender=False, non_tender=True,
    ...                          start_date=date(2014, 1, 1))
    ['USN', 'USS']

    .. versionadded:: 2.0

    :param territory: the name of the territory to find the currency for.
    :param start_date: the start date.  If not given today is assumed.
    :param end_date: the end date.  If not given the start date is assumed.
    :param tender: controls whether tender currencies should be included.
    :param non_tender: controls whether non-tender currencies should be
                       included.
    :param include_details: if set to `True`, instead of returning currency
                            codes the return value will be dictionaries
                            with detail information.  In that case each
                            dictionary will have the keys ``'currency'``,
                            ``'from'``, ``'to'``, and ``'tender'``.
    territory_currenciesNr   c                    s    | d u s|  ko|d u p|kS Nr   )startendend_date
start_dater   r   
_is_active   s   z,get_territory_currencies.<locals>._is_active)r   fromtotender)	r   date_todayr   	datetime_r   r&   r!   append)	territoryr;   r:   r?   
non_tenderinclude_detailsr   cursr<   resultcurrency_coder7   r8   	is_tenderr   r9   r   get_territory_currencies   sD   4




rK   c                 C      t | jddS )zReturn the symbol used by the locale to separate decimal fractions.

    >>> get_decimal_symbol('en_US')
    u'.'

    :param locale: the `Locale` object or locale identifier
    r   .r   r   number_symbolsr&   r   r   r   r   get_decimal_symbol     rQ   c                 C   rL   )zReturn the plus sign symbol used by the current locale.

    >>> get_plus_sign_symbol('en_US')
    u'+'

    :param locale: the `Locale` object or locale identifier
    plusSign+rN   rP   r   r   r   get_plus_sign_symbol#  rR   rU   c                 C   rL   )zReturn the plus sign symbol used by the current locale.

    >>> get_minus_sign_symbol('en_US')
    u'-'

    :param locale: the `Locale` object or locale identifier
    	minusSign-rN   rP   r   r   r   get_minus_sign_symbol.  rR   rX   c                 C   rL   )zReturn the symbol used by the locale to separate mantissa and exponent.

    >>> get_exponential_symbol('en_US')
    u'E'

    :param locale: the `Locale` object or locale identifier
    exponentialErN   rP   r   r   r   get_exponential_symbol9  rR   r[   c                 C   rL   )zReturn the symbol used by the locale to separate groups of thousands.

    >>> get_group_symbol('en_US')
    u','

    :param locale: the `Locale` object or locale identifier
    group,rN   rP   r   r   r   get_group_symbolD  rR   r^   c                 C   s   t dt t| |dS )af  Return the given number formatted for a specific locale.

    >>> format_number(1099, locale='en_US')
    u'1,099'
    >>> format_number(1099, locale='de_DE')
    u'1.099'

    .. deprecated:: 2.6.0

       Use babel.numbers.format_decimal() instead.

    :param number: the number to format
    :param locale: the `Locale` object or locale identifier


    z+Use babel.numbers.format_decimal() instead.rP   )warningswarnDeprecationWarningformat_decimal)numberr   r   r   r   format_numberO  s   rd   c                 C   s4   t | tjsJ |   }|jdkrdS t|jS )zReturn maximum precision of a decimal instance's fractional part.

    Precision is extracted from the fractional part only.
    r   )r   r   Decimal	normalizeas_tupleexponentabs)rc   decimal_tupler   r   r   get_decimal_precisiond  s
   

rk   c                 C   s&   t | tttjfsJ td|   S )z<Return minimal quantum of a number, as defined by precision.
   )r   intlongr   re   )	precisionr   r   r   get_decimal_quantumq  s   rp   c                 C   2   t |}|s|j|}t|}|j| ||dS )a  Return the given decimal number formatted for a specific locale.

    >>> format_decimal(1.2345, locale='en_US')
    u'1.234'
    >>> format_decimal(1.2346, locale='en_US')
    u'1.235'
    >>> format_decimal(-1.2346, locale='en_US')
    u'-1.235'
    >>> format_decimal(1.2345, locale='sv_SE')
    u'1,234'
    >>> format_decimal(1.2345, locale='de')
    u'1,234'

    The appropriate thousands grouping and the decimal separator are used for
    each locale:

    >>> format_decimal(12345.5, locale='en_US')
    u'12,345.5'

    By default the locale is allowed to truncate and round a high-precision
    number by forcing its format pattern onto the decimal part. You can bypass
    this behavior with the `decimal_quantization` parameter:

    >>> format_decimal(1.2346, locale='en_US')
    u'1.235'
    >>> format_decimal(1.2346, locale='en_US', decimal_quantization=False)
    u'1.2346'

    :param number: the number to format
    :param format:
    :param locale: the `Locale` object or locale identifier
    :param decimal_quantization: Truncate and round high-precision numbers to
                                 the format pattern. Defaults to `True`.
    decimal_quantization)r   r   decimal_formatsr&   parse_patternapplyrc   formatr   rs   patternr   r   r   rb   w  s   
$rb   c                   @   s   e Zd ZdZdS )UnknownCurrencyFormatErrorz>Exception raised when an unknown currency format is requested.N)r   r   r   r   r   r   r   r   rz     s    rz   standardc                 C   sr   |dkrt | |||||dS t|}|rt|}nz|j| }W n ty.   td| w |j| ||||dS )u  Return formatted currency value.

    >>> format_currency(1099.98, 'USD', locale='en_US')
    u'$1,099.98'
    >>> format_currency(1099.98, 'USD', locale='es_CO')
    u'US$\xa01.099,98'
    >>> format_currency(1099.98, 'EUR', locale='de_DE')
    u'1.099,98\xa0\u20ac'

    The format can also be specified explicitly.  The currency is
    placed with the '¤' sign.  As the sign gets repeated the format
    expands (¤ being the symbol, ¤¤ is the currency abbreviation and
    ¤¤¤ is the full name of the currency):

    >>> format_currency(1099.98, 'EUR', u'¤¤ #,##0.00', locale='en_US')
    u'EUR 1,099.98'
    >>> format_currency(1099.98, 'EUR', u'#,##0.00 ¤¤¤', locale='en_US')
    u'1,099.98 euros'

    Currencies usually have a specific number of decimal digits. This function
    favours that information over the given format:

    >>> format_currency(1099.98, 'JPY', locale='en_US')
    u'\xa51,100'
    >>> format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES')
    u'1.099,98'

    However, the number of decimal digits can be overriden from the currency
    information, by setting the last parameter to ``False``:

    >>> format_currency(1099.98, 'JPY', locale='en_US', currency_digits=False)
    u'\xa51,099.98'
    >>> format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES', currency_digits=False)
    u'1.099,98'

    If a format is not specified the type of currency format to use
    from the locale can be specified:

    >>> format_currency(1099.98, 'EUR', locale='en_US', format_type='standard')
    u'\u20ac1,099.98'

    When the given currency format type is not available, an exception is
    raised:

    >>> format_currency('1099.98', 'EUR', locale='root', format_type='unknown')
    Traceback (most recent call last):
        ...
    UnknownCurrencyFormatError: "'unknown' is not a known currency format type"

    You can also pass format_type='name' to use long display names. The order of
    the number and currency name, along with the correct localized plural form
    of the currency name, is chosen according to locale:

    >>> format_currency(1, 'USD', locale='en_US', format_type='name')
    u'1.00 US dollar'
    >>> format_currency(1099.98, 'USD', locale='en_US', format_type='name')
    u'1,099.98 US dollars'
    >>> format_currency(1099.98, 'USD', locale='ee', format_type='name')
    u'us ga dollar 1,099.98'

    By default the locale is allowed to truncate and round a high-precision
    number by forcing its format pattern onto the decimal part. You can bypass
    this behavior with the `decimal_quantization` parameter:

    >>> format_currency(1099.9876, 'USD', locale='en_US')
    u'$1,099.99'
    >>> format_currency(1099.9876, 'USD', locale='en_US', decimal_quantization=False)
    u'$1,099.9876'

    :param number: the number to format
    :param currency: the currency code
    :param format: the format string to use
    :param locale: the `Locale` object or locale identifier
    :param currency_digits: use the currency's natural number of decimal digits
    :param format_type: the currency format type to use
    :param decimal_quantization: Truncate and round high-precision numbers to
                                 the format pattern. Defaults to `True`.

    name)rx   r   currency_digitsrs   z&%r is not a known currency format typer   r}   rs   )_format_currency_long_namer   r   ru   currency_formatsKeyErrorrz   rv   )rc   r   rx   r   r}   format_typers   ry   r   r   r   format_currency  s&   R

r   c                 C   sv   t |}t| trt| }n| }t|||d}t|||d}	|s'|j|}t	|}
|
j
| ||||d}|||	S )N)r'   r   r~   )r   r   r   r   floatr4   r*   rt   r&   ru   rv   rx   )rc   r   rx   r   r}   r   rs   number_nunit_patterndisplay_namery   number_partr   r   r   r     s   


r   c                 C   rq   )u  Return formatted percent value for a specific locale.

    >>> format_percent(0.34, locale='en_US')
    u'34%'
    >>> format_percent(25.1234, locale='en_US')
    u'2,512%'
    >>> format_percent(25.1234, locale='sv_SE')
    u'2\xa0512\xa0%'

    The format pattern can also be specified explicitly:

    >>> format_percent(25.1234, u'#,##0‰', locale='en_US')
    u'25,123‰'

    By default the locale is allowed to truncate and round a high-precision
    number by forcing its format pattern onto the decimal part. You can bypass
    this behavior with the `decimal_quantization` parameter:

    >>> format_percent(23.9876, locale='en_US')
    u'2,399%'
    >>> format_percent(23.9876, locale='en_US', decimal_quantization=False)
    u'2,398.76%'

    :param number: the percent number to format
    :param format:
    :param locale: the `Locale` object or locale identifier
    :param decimal_quantization: Truncate and round high-precision numbers to
                                 the format pattern. Defaults to `True`.
    rr   )r   r   percent_formatsr&   ru   rv   rw   r   r   r   format_percent0  s   
r   c                 C   rq   )a  Return value formatted in scientific notation for a specific locale.

    >>> format_scientific(10000, locale='en_US')
    u'1E4'

    The format pattern can also be specified explicitly:

    >>> format_scientific(1234567, u'##0.##E00', locale='en_US')
    u'1.23E06'

    By default the locale is allowed to truncate and round a high-precision
    number by forcing its format pattern onto the decimal part. You can bypass
    this behavior with the `decimal_quantization` parameter:

    >>> format_scientific(1234.9876, u'#.##E0', locale='en_US')
    u'1.23E3'
    >>> format_scientific(1234.9876, u'#.##E0', locale='en_US', decimal_quantization=False)
    u'1.2349876E3'

    :param number: the number to format
    :param format:
    :param locale: the `Locale` object or locale identifier
    :param decimal_quantization: Truncate and round high-precision numbers to
                                 the format pattern. Defaults to `True`.
    rr   )r   r   scientific_formatsr&   ru   rv   rw   r   r   r   format_scientificW  s   
r   c                       s"   e Zd ZdZd fdd	Z  ZS )NumberFormatErrorz>Exception raised when a string cannot be parsed into a number.Nc                    s   t t| | || _d S r6   )superr   r   suggestions)r   messager   	__class__r   r   r   }  s   
zNumberFormatError.__init__r6   )r   r   r   r   r   __classcell__r   r   r   r   r   z  s    r   c                 C   s2   zt | t|dW S  ty   td|  w )aS  Parse localized number string into an integer.

    >>> parse_number('1,099', locale='en_US')
    1099
    >>> parse_number('1.099', locale='de_DE')
    1099

    When the given string cannot be parsed, an exception is raised:

    >>> parse_number('1.099,98', locale='de')
    Traceback (most recent call last):
        ...
    NumberFormatError: '1.099,98' is not a valid number

    :param string: the string to parse
    :param locale: the `Locale` object or locale identifier
    :return: the parsed number
    :raise `NumberFormatError`: if the string can not be converted to a number
     z%r is not a valid number)rm   replacer^   
ValueErrorr   )stringr   r   r   r   parse_number  s
   r   c           	      C   sB  t |}t|}t|}|s!|dkr!|| vr!d| v r!| d|} zt| |d|d}W n tjy>   td|  w |r|| v rt	||dd}| |kr| 
d|| krzt| |d|d}W n tjy{   td	| |f |gd
w t	||dd}||krtd	| |f |gd
td| ||f ||gd
|S )ak  Parse localized decimal string into a decimal.

    >>> parse_decimal('1,099.98', locale='en_US')
    Decimal('1099.98')
    >>> parse_decimal('1.099,98', locale='de')
    Decimal('1099.98')
    >>> parse_decimal('12 345,123', locale='ru')
    Decimal('12345.123')

    When the given string cannot be parsed, an exception is raised:

    >>> parse_decimal('2,109,998', locale='de')
    Traceback (most recent call last):
        ...
    NumberFormatError: '2,109,998' is not a valid decimal number

    If `strict` is set to `True` and the given string contains a number
    formatted in an irregular way, an exception is raised:

    >>> parse_decimal('30.00', locale='de', strict=True)
    Traceback (most recent call last):
        ...
    NumberFormatError: '30.00' is not a properly formatted decimal number. Did you mean '3.000'? Or maybe '30,00'?

    >>> parse_decimal('0.00', locale='de', strict=True)
    Traceback (most recent call last):
        ...
    NumberFormatError: '0.00' is not a properly formatted decimal number. Did you mean '0'?

    :param string: the string to parse
    :param locale: the `Locale` object or locale identifier
    :param strict: controls whether numbers formatted in a weird way are
                   accepted or rejected
    :raise NumberFormatError: if the string can not be converted to a
                              decimal number
         r   rM   z %r is not a valid decimal numberF)r   rs   0z?%r is not a properly formatted decimal number. Did you mean %r?)r   zL%r is not a properly formatted decimal number. Did you mean %r? Or maybe %r?)r   r   r^   rQ   r   r   re   InvalidOperationr   rb   rstrip)	r   r   strictgroup_symboldecimal_symbolparsedproper
parsed_alt
proper_altr   r   r   parse_decimal  s`   
%r   z
[^0-9@#.,]z[0-9@#.,E+]z(?P<prefix>(?:'[^']*'|%s)*)z(?P<number>%s*)z(?P<suffix>.*)z%s%s%sc                 C   sj   t | }| d}|dkrdS || d }| d| d  d}|dkr)||fS || | d }||fS )zParse primary and secondary digit grouping

    >>> parse_grouping('##')
    (1000, 1000)
    >>> parse_grouping('#,###')
    (3, 3)
    >>> parse_grouping('#,####,###')
    (3, 4)
    r]   )  r      N   )lenrfind)pwidthg1g2r   r   r   parse_grouping  s   

r   c              	   C   s2  t | tr| S dd }| }d| v r(| dd\}}||\}}}||\}}}	n||\}}}d| }|}	d|v rB|dd\}}
nd}
d|v rTd	|v rTd
|v rTtdd	|v ra|d	d\}}n|}d}dd }||}||}|
r|
d}|
d}
||
}nd}d}t|}t| ||f||	f|||||S )zParse number format patternsc                 S   s&   t | }|d u rtd|  | S )NzInvalid number pattern %r)	number_researchr   groups)ry   rvr   r   r   _match_number  s   
z$parse_pattern.<locals>._match_number;r   rW   rZ   N@rM   r   z5Significant digit patterns can not contain "@" or "0"r   c                 S   sX   d }}| D ]!}|dv r|d7 }|d7 }q|dkr|d7 }q|dkr#q ||fS ||fS )z(Calculate the min and max allowed digitsr   z@0r   #r]   r   )r   minmaxcr   r   r   parse_precision2  s   

z&parse_pattern.<locals>.parse_precisionrT   )r   NumberPatternsplitr   rsplit
startswithlstripr   )ry   r   pos_patternneg_pattern
pos_prefixrc   
pos_suffix
neg_prefix_
neg_suffixexpintegerfractionr   int_prec	frac_precexp_plusexp_precgroupingr   r   r   ru     sH   




ru   c                   @   s`   e Zd Zdd Zdd Zdd Zdd Z			
	
		dddZdd Zdd Z	dd Z
dddZd	S )r   c	           	      C   s>   || _ || _|| _|| _|| _|| _|| _|| _|  | _	d S r6   )
ry   prefixsuffixr   r   r   r   r   compute_scalescale)	r   ry   r   r   r   r   r   r   r   r   r   r   r   S  s   zNumberPattern.__init__c                 C   s   dt | j| jf S )Nz<%s %r>)typer   ry   )r   r   r   r   __repr__`  s   zNumberPattern.__repr__c                 C   s@   d}dd | j| j v rd}|S dd | j| j v rd}|S )u  Return the scaling factor to apply to the number before rendering.

        Auto-set to a factor of 2 or 3 if presence of a ``%`` or ``‰`` sign is
        detected in the prefix or suffix of the pattern. Default is to not mess
        with the scale at all and keep it to 0.
        r   %r   r   u   ‰   )joinr   r   )r   r   r   r   r   r   c  s   zNumberPattern.compute_scalec                 C   s   |  }|t| }|  dksJ tdt| jgd }|| }|t|  }d}|dk r3t|}n| jr:t|}t|}|||fS )zG Returns normalized scientific notation components of a value.
        r   r   r   )	adjustedrp   r   r   r   rX   r   rU   ri   )r   valuer   r   
lead_shiftexp_signr   r   r   scientific_notation_elementsq  s   

z*NumberPattern.scientific_notation_elementsNTc                 C   s  t |tjstt|}|| j}t| }t|	 }| j
r+| ||\}}}	|r6tdt |}
n|rB|rBt|fd }
n| j}
|rN| j
r\|
dkr\|
d t|
d t|gf}
| j
r~d| |||
t||	| t|| j
d | j
d |g}n4d| jv r| || jd | jd }|d\}}}| |dd	|}|r|t|| 7 }n| |||
}d| j| || j| g}d
|v r|dt|||}|d|  }|d
t!||}|S )a  Renders into a string a number following the defined pattern.

        Forced decimal quantization is active by default so we'll produce a
        number string that is strictly following CLDR pattern definitions.

        :param value: The value to format. If this is not a Decimal object,
                      it will be cast to one.
        :type value: decimal.Decimal|float|int
        :param locale: The locale to use for formatting.
        :type locale: str|babel.core.Locale
        :param currency: Which currency, if any, to format as.
        :type currency: str|None
        :param currency_digits: Whether or not to use the currency's precision.
                                If false, the pattern's precision is used.
        :type currency_digits: bool
        :param decimal_quantization: Whether decimal numbers should be forcibly
                                     quantized to produce a formatted output
                                     strictly matching the CLDR definition for
                                     the locale.
        :type decimal_quantization: bool
        :param force_frac: DEPRECATED - a forced override for `self.frac_prec`
                           for a single formatting invocation.
        :return: Formatted decimal string.
        :rtype: str
        z@The force_frac parameter to NumberPattern.apply() is deprecated.r   )r   r   r   r   r   r   rM   r      ¤u   ¤¤¤u   ¤¤)"r   r   re   strscalebr   rm   	is_signedri   rf   r   r   r_   r`   ra   r0   r   r   rk   r   _quantize_valuer[   _format_intry   _format_significantr   	partitionrQ   r   r   r   r*   r!   r,   )r   r   r   r   r}   rs   
force_fracis_negativer   r   r   rc   textasepbretvalr   r   r   rv     s^   "

zNumberPattern.applyc                 C   s   |  }|d | }t||td}|dkr$|d|   }|S |d |  }t|}	|	t||	 d }
dj|p=ddt	|d d ||	|
 ||
d  
dd
d}|S )Nr   r   r   z-{intpart}.{pad:0<{fill}}{fracpart}{fracextra}r   )intpartpadfillfracpart	fracextrarM   )r   r   r   quantizer   re   r   r   rx   r   r   )r   r   minimummaximumr   r   digitsrH   r   ijr   r   r   r     s&   
z!NumberPattern._format_significantc           	      C   s   t |}||k rd||  | }| jd }d}t|}t ||kr>||| d   | }|d |  }| jd }t ||ks!|| S )Nr   r   r   r   )r   r   r^   )	r   r   r   r   r   r   gsizeretsymbolr   r   r   r     s   

zNumberPattern._format_intc           
      C   s^   t |d }||}d|d\}}}| || jd | jd || |p(d|| }	|	S )Nr   z{:f}rM   r   r   )rp   r   rx   r   r   r   _format_frac)
r   r   r   r   quantumroundedr   r   r   rc   r   r   r   r   '  s   

zNumberPattern._quantize_valuec                 C   s   |p| j \}}t||k r|d|t|  7 }|dks%|dkr't|dkr'dS t||krE|d dkrE|d d }t||krE|d dks3t|| S )Nr   r   r   r   )r   r   rm   rQ   )r   r   r   r   r   r   r   r   r   r   0  s   zNumberPattern._format_frac)NTTNr6   )r   r   r   r   r   r   r   rv   r   r   r   r   r   r   r   r   r   Q  s    
{	r   r6   )NNTFF);r   rer   r   r@   rB   r_   
babel.corer   r   r   babel._compatr   r   rn   	NameErrorrm   r	   r   r
   r   r   r    r"   r*   r,   r0   r4   rK   rQ   rU   rX   r[   r^   rd   rk   rp   rb   r   rz   r   r   r   r   r   r   r   r   
PREFIX_ENDNUMBER_TOKENPREFIX_PATTERNNUMBER_PATTERNSUFFIX_PATTERNcompiler   r   ru   objectr   r   r   r   r   <module>   sx   




Z
,
f
%
(
#	P
C