live
  B   çˆl–ß=¿JÅ2ÛR‚ „ ¸Û—Ê˜´o�þ_ �Y²…á´A<Ô¤óð„e÷Ýoï_ŠI|¥�+Wé3ž¯Êî ?÷     ç"""
    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-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
"""
# TODO:
#  Padding and rounding increments in pattern:
#  - https://www.unicode.org/reports/tr35/ (Appendix G.6)
import decimal
import re
from datetime import date as date_, datetime as datetime_
import warnings

from babel.core import default_locale, Locale, get_global

try:
    # Python 2
    long
except NameError:
    # Python 3
    long = int


LC_NUMERIC = default_locale('LC_NUMERIC')


class UnknownCurrencyError(Exception):
    """Exception thrown when a currency is requested for which no data is available.
    """

    def __init__(self, identifier):
        """Create the exception.
        :param identifier: the identifier string of the unsupported currency
        """
        Exception.__init__(self, 'Unknown currency %r.' % identifier)

        #: The identifier of the locale that could not be found.
        self.identifier = identifier


def list_currencies(locale=None):
    """ 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.
    """
    # Get locale-scoped currencies.
    if locale:
        currencies = Locale.parse(locale).currencies.keys()
    else:
        currencies = get_global('all_currencies')
    return set(currencies)


def validate_currency(currency, locale=None):
    """ 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.
    """
    if currency not in list_currencies(locale):
        raise UnknownCurrencyError(currency)


def is_currency(currency, locale=None):
    """ Returns `True` only if a currency is recognized by Babel.

    This method always return a Boolean and never raise.
    """
    if not currency or not isinstance(currency, str):
        return False
    try:
        validate_currency(currency, locale)
    except UnknownCurrencyError:
        return False
    return True


def normalize_currency(currency, locale=None):
    """Returns 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.
    """
    if isinstance(currency, str):
        currency = currency.upper()
    if not is_currency(currency, locale):
        return
    return currency


def get_currency_name(currency, count=None, locale=LC_NUMERIC):
    """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.
    """
    loc = Locale.parse(locale)
    if count is not None:
        plural_form = loc.plural_form(count)
        plural_names = loc._data['currency_names_plural']
        if currency in plural_names:
            currency_plural_names = plural_names[currency]
            if plural_form in currency_plural_names:
                return currency_plural_names[plural_form]
            if 'other' in currency_plural_names:
                return currenc