o
    V\+                     @   s  d Z ddlZddlmZ ddlmZmZ ddlmZ g dZ	da
ei Zdd Zd	d
 Zi dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,i d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTZG dUdV dVeZG dWdX dXeZdefdYdZZd[efd\d]Zdbd^d_Zdbd`daZdS )cz
    babel.core
    ~~~~~~~~~~

    Core locale representation and locale data access.

    :copyright: (c) 2013-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)
localedata)picklestring_types)
PluralRule)UnknownLocaleErrorLocaledefault_localenegotiate_localeparse_localec                   C   s   t d)NzThe babel data files are not available. This usually happens because you are using a source checkout from Babel and you did not build the data files.  Just make sure to run "python setup.py import_cldr" before installing the library.)RuntimeError r   r   ,/usr/lib/python3/dist-packages/babel/core.py_raise_no_data_error   s   r   c                 C   s|   t du r8tjtjt}tj|d}tj|st  t|d}t	
|a W d   n1 s3w   Y  t | i S )a_  Return the dictionary for the given key in the global data.

    The global data is stored in the ``babel/global.dat`` file and contains
    information independent of individual locales.

    >>> get_global('zone_aliases')['UTC']
    u'Etc/UTC'
    >>> get_global('zone_territories')['Europe/Berlin']
    u'DE'

    The keys available are:

    - ``all_currencies``
    - ``currency_fractions``
    - ``language_aliases``
    - ``likely_subtags``
    - ``parent_exceptions``
    - ``script_aliases``
    - ``territory_aliases``
    - ``territory_currencies``
    - ``territory_languages``
    - ``territory_zones``
    - ``variant_aliases``
    - ``windows_zone_mapping``
    - ``zone_aliases``
    - ``zone_territories``

    .. note:: The internal structure of the data may change between versions.

    .. versionadded:: 0.9

    :param key: the data key
    Nz
global.datrb)_global_dataospathjoindirname__file__isfiler   openr   loadget)keyr   filenamefileobjr   r   r   
get_global#   s   #r   arar_SYbgbg_BGbsbs_BAcaca_EScscs_CZdada_DKdede_DEelel_GRenen_USeses_ESetet_EEfafa_IRfifi_FIfrfr_FRglgl_EShehe_ILhuhu_HUidid_IDisis_ISitit_ITjaja_JPkmkm_KHkoko_KRltlt_LTlvlv_LVmkmk_MKnlnl_NLnnnn_NOnonb_NOplpl_PLptpt_PTroro_ROruru_RUsksk_SKsl_SIsv_SEth_THtr_TRuk_UA)slsvthtrukc                   @   s   e Zd ZdZdd ZdS )r   z[Exception thrown when a locale is requested for which no locale data
    is available.
    c                 C   s   t | d|  || _dS )zjCreate the exception.

        :param identifier: the identifier string of the unsupported locale
        zunknown locale %rN)	Exception__init__
identifier)selfrn   r   r   r   rm   a   s   
zUnknownLocaleError.__init__N)__name__
__module____qualname____doc__rm   r   r   r   r   r   \   s    r   c                   @   s  e Zd ZdZdrddZedefddZedefdd	ZedsddZ	dd Z
dd Zdd Zdd Zdd Zedd ZdtddZeeddZdtddZeeddZdtd d!Zeed"dZdtd#d$Zeed%dZed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Z ed6d7 Z!ed8d9 Z"ed:d; Z#ed<d= Z$ed>d? Z%ed@dA Z&edBdC Z'edDdE Z(edFdG Z)edHdI Z*edJdK Z+edLdM Z,edNdO Z-edPdQ Z.edRdS Z/edTdU Z0edVdW Z1edXdY Z2edZd[ Z3ed\d] Z4ed^d_ Z5ed`da Z6edbdc Z7eddde Z8edfdg Z9edhdi Z:edjdk Z;edldm Z<edndo Z=edpdq Z>dS )ur   aY  Representation of a specific locale.

    >>> locale = Locale('en', 'US')
    >>> repr(locale)
    "Locale('en', territory='US')"
    >>> locale.display_name
    u'English (United States)'

    A `Locale` object can also be instantiated from a raw locale string:

    >>> locale = Locale.parse('en-US', sep='-')
    >>> repr(locale)
    "Locale('en', territory='US')"

    `Locale` objects provide access to a collection of locale data, such as
    territory and language names, number and date format patterns, and more:

    >>> locale.number_symbols['decimal']
    u'.'

    If a locale is requested for which no locale data is available, an
    `UnknownLocaleError` is raised:

    >>> Locale.parse('en_XX')
    Traceback (most recent call last):
        ...
    UnknownLocaleError: unknown locale 'en_XX'

    For more information see :rfc:`3066`.
    Nc                 C   s<   || _ || _|| _|| _d| _t| }t|st|dS )a  Initialize the locale object from the given identifier components.

        >>> locale = Locale('en', 'US')
        >>> locale.language
        'en'
        >>> locale.territory
        'US'

        :param language: the language code
        :param territory: the territory (country or region) code
        :param script: the script code
        :param variant: the variant code
        :raise `UnknownLocaleError`: if no locale data is available for the
                                     requested locale
        N)	language	territoryscriptvariant_Locale__datastrr   existsr   )ro   rt   ru   rv   rw   rn   r   r   r   rm      s   
zLocale.__init__c                 C   s   t ||d}| |S )af  Return the system default locale for the specified category.

        >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES']:
        ...     os.environ[name] = ''
        >>> os.environ['LANG'] = 'fr_FR.UTF-8'
        >>> Locale.default('LC_MESSAGES')
        Locale('fr', territory='FR')

        The following fallbacks to the variable are always considered:

        - ``LANGUAGE``
        - ``LC_ALL``
        - ``LC_CTYPE``
        - ``LANG``

        :param category: one of the ``LC_XXX`` environment variable names
        :param aliases: a dictionary of aliases for locale identifiers
        )aliases)r   parse)clscategoryr{   locale_stringr   r   r   default   s   
zLocale.default_c                 C   s&   t ||||d}|rtj||dS dS )a\  Find the best match between available and requested locale strings.

        >>> Locale.negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
        Locale('de', territory='DE')
        >>> Locale.negotiate(['de_DE', 'en_US'], ['en', 'de'])
        Locale('de')
        >>> Locale.negotiate(['de_DE', 'de'], ['en_US'])

        You can specify the character used in the locale identifiers to separate
        the differnet components. This separator is applied to both lists. Also,
        case is ignored in the comparison:

        >>> Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-')
        Locale('de', territory='DE')

        :param preferred: the list of locale identifers preferred by the user
        :param available: the list of locale identifiers available
        :param aliases: a dictionary of aliases for locale identifiers
        )sepr{   r   N)r	   r   r|   )r}   	preferred	availabler   r{   rn   r   r   r   	negotiate   s   zLocale.negotiateTc                    st  |du rdS t |tr|S t |tstd|f t||d}t|}fdd  fdd} |}|dur9|S |s?t||\}}	}
}td||}td	|	|	fd
 }	td|
|
}
td||}|	dkrnd}	|
dkrtd}
||	|
|f}t|}td|}|dur|t|}|dur|S td|}|durt|\}}}}|||	||f}|dur|S t|)a6  Create a `Locale` instance for the given locale identifier.

        >>> l = Locale.parse('de-DE', sep='-')
        >>> l.display_name
        u'Deutsch (Deutschland)'

        If the `identifier` parameter is not a string, but actually a `Locale`
        object, that object is returned:

        >>> Locale.parse(l)
        Locale('de', territory='DE')

        This also can perform resolving of likely subtags which it does
        by default.  This is for instance useful to figure out the most
        likely locale for a territory you can use ``'und'`` as the
        language tag:

        >>> Locale.parse('und_AT')
        Locale('de', territory='AT')

        :param identifier: the locale identifier string
        :param sep: optional component separator
        :param resolve_likely_subtags: if this is specified then a locale will
                                       have its likely subtag resolved if the
                                       locale otherwise does not exist.  For
                                       instance ``zh_TW`` by itself is not a
                                       locale that exists but Babel can
                                       automatically expand it to the full
                                       form of ``zh_hant_TW``.  Note that this
                                       expansion is only taking place if no
                                       locale exists otherwise.  For instance
                                       there is a locale ``en`` that can exist
                                       by itself.
        :raise `ValueError`: if the string does not appear to be a valid locale
                             identifier
        :raise `UnknownLocaleError`: if no locale data is available for the
                                     requested locale
        Nz#Unexpected value for identifier: %rr   c                    s    z |  W S  t y   Y d S w N)r   )parts)r}   r   r   	_try_load  s
   
zLocale.parse.<locals>._try_loadc                    s4    | }|d ur
|S  | d d }|d ur|S d S )N   r   )r   locale)r   r   r   _try_load_reducing  s   z(Locale.parse.<locals>._try_load_reducinglanguage_aliasesterritory_aliasesr   script_aliasesvariant_aliasesZZZzzzlikely_subtags)	
isinstancer   r   	TypeErrorr
   get_locale_identifierr   r   r   )r}   rn   r   resolve_likely_subtagsr   input_idr   r   rt   ru   rv   rw   new_idlikely_subtag	language2r   script2variant2r   )r   r}   r   r|      sL   (

	zLocale.parsec                 C   sJ   dD ]
}t ||s dS q| j|jko$| j|jko$| j|jko$| j|jkS )N)rt   ru   rv   rw   F)hasattrrt   ru   rv   rw   )ro   otherr   r   r   r   __eq__M  s   



zLocale.__eq__c                 C   s   |  | S r   )r   )ro   r   r   r   r   __ne__V  s   zLocale.__ne__c                 C      t | j| j| j| jfS r   )hashrt   ru   rv   rw   ro   r   r   r   __hash__Y  s   zLocale.__hash__c                 C   sP   dg}dD ]}t | |}|d ur|d||f  qd| j d| }d| S )N )ru   rv   rw   z%s=%rz%r, z
Locale(%s))getattrappendrt   r   )ro   
parametersr   valueparameter_stringr   r   r   __repr__\  s   
zLocale.__repr__c                 C   r   r   )r   rt   ru   rv   rw   r   r   r   r   __str__e  s   
zLocale.__str__c                 C   s&   | j d u rttt| | _ | j S r   )rx   r   LocaleDataDictr   ry   r   r   r   r   _datai  s   
zLocale._datac                 C   s   |du r| }t |}|j| j}|rV| js| js| jrVg }| jr,||j	| j | jr9||j
| j | jrF||j| j td|}|rV|dd| 7 }|S )aR  Return the display name of the locale using the given locale.

        The display name will include the language, territory, script, and
        variant, if those are specified.

        >>> Locale('zh', 'CN', script='Hans').get_display_name('en')
        u'Chinese (Simplified, China)'

        :param locale: the locale to use
        Nz (%s)r   )r   r|   	languagesr   rt   ru   rv   rw   r   scriptsterritoriesvariantsfilterr   )ro   r   retvaldetailsr   r   r   get_display_nameo  s    

zLocale.get_display_namea          The localized display name of the locale.

        >>> Locale('en').display_name
        u'English'
        >>> Locale('en', 'US').display_name
        u'English (United States)'
        >>> Locale('sv').display_name
        u'svenska'

        :type: `unicode`
        )docc                 C   $   |du r| }t |}|j| jS )zReturn the language of this locale in the given locale.

        >>> Locale('zh', 'CN', script='Hans').get_language_name('de')
        u'Chinesisch'

        .. versionadded:: 1.0

        :param locale: the locale to use
        N)r   r|   r   r   rt   ro   r   r   r   r   get_language_name  s   

zLocale.get_language_namezx        The localized language name of the locale.

        >>> Locale('en', 'US').language_name
        u'English'
    c                 C   r   )z.Return the territory name in the given locale.N)r   r|   r   r   ru   r   r   r   r   get_territory_name     
zLocale.get_territory_namez        The localized territory name of the locale if available.

        >>> Locale('de', 'DE').territory_name
        u'Deutschland'
    c                 C   r   )z+Return the script name in the given locale.N)r   r|   r   r   rv   r   r   r   r   get_script_name  r   zLocale.get_script_namez        The localized script name of the locale if available.

        >>> Locale('sr', 'ME', script='Latn').script_name
        u'latinica'
    c                 C   s   |  tdS )zThe english display name of the locale.

        >>> Locale('de').english_name
        u'German'
        >>> Locale('de', 'DE').english_name
        u'German (Germany)'

        :type: `unicode`r.   )r   r   r   r   r   r   english_name  s   
zLocale.english_namec                 C   
   | j d S )zMapping of language codes to translated language names.

        >>> Locale('de', 'DE').languages['ja']
        u'Japanisch'

        See `ISO 639 <http://www.loc.gov/standards/iso639-2/>`_ for
        more information.
        r   r   r   r   r   r   r        

zLocale.languagesc                 C   r   )zMapping of script codes to translated script names.

        >>> Locale('en', 'US').scripts['Hira']
        u'Hiragana'

        See `ISO 15924 <http://www.evertype.com/standards/iso15924/>`_
        for more information.
        r   r   r   r   r   r   r     r   zLocale.scriptsc                 C   r   )zMapping of script codes to translated script names.

        >>> Locale('es', 'CO').territories['DE']
        u'Alemania'

        See `ISO 3166 <http://www.iso.org/iso/en/prods-services/iso3166ma/>`_
        for more information.
        r   r   r   r   r   r   r     r   zLocale.territoriesc                 C   r   )zMapping of script codes to translated script names.

        >>> Locale('de', 'DE').variants['1901']
        u'Alte deutsche Rechtschreibung'
        r   r   r   r   r   r   r        
zLocale.variantsc                 C   r   )a  Mapping of currency codes to translated currency names.  This
        only returns the generic form of the currency name, not the count
        specific one.  If an actual number is requested use the
        :func:`babel.numbers.get_currency_name` function.

        >>> Locale('en').currencies['COP']
        u'Colombian Peso'
        >>> Locale('de', 'DE').currencies['COP']
        u'Kolumbianischer Peso'
        currency_namesr   r   r   r   r   
currencies     
zLocale.currenciesc                 C   r   )zMapping of currency codes to symbols.

        >>> Locale('en', 'US').currency_symbols['USD']
        u'$'
        >>> Locale('es', 'CO').currency_symbols['USD']
        u'US$'
        currency_symbolsr   r   r   r   r   r        
	zLocale.currency_symbolsc                 C   r   )zSymbols used in number formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('fr', 'FR').number_symbols['decimal']
        u','
        number_symbolsr   r   r   r   r   r      r   zLocale.number_symbolsc                 C   r   )zLocale patterns for decimal number formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').decimal_formats[None]
        <NumberPattern u'#,##0.###'>
        decimal_formatsr   r   r   r   r   r   ,  r   zLocale.decimal_formatsc                 C   r   )a{  Locale patterns for currency number formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').currency_formats['standard']
        <NumberPattern u'\xa4#,##0.00'>
        >>> Locale('en', 'US').currency_formats['accounting']
        <NumberPattern u'\xa4#,##0.00;(\xa4#,##0.00)'>
        currency_formatsr   r   r   r   r   r   8  r   zLocale.currency_formatsc                 C   r   )zLocale patterns for percent number formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').percent_formats[None]
        <NumberPattern u'#,##0%'>
        percent_formatsr   r   r   r   r   r   F  r   zLocale.percent_formatsc                 C   r   )zLocale patterns for scientific number formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').scientific_formats[None]
        <NumberPattern u'#E0'>
        scientific_formatsr   r   r   r   r   r   R  r   zLocale.scientific_formatsc                 C   s,   z
| j d d d W S  ty   i  Y S w )zrLocale display names for day periods (AM/PM).

        >>> Locale('en', 'US').periods['am']
        u'AM'
        day_periodszstand-alonewide)r   KeyErrorr   r   r   r   periods`  s
   zLocale.periodsc                 C   r   )zLocale display names for various day periods (not necessarily only AM/PM).

        These are not meant to be used without the relevant `day_period_rules`.
        r   r   r   r   r   r   r   l  s   
zLocale.day_periodsc                 C   s   | j di S )zCDay period rules for the locale.  Used by `get_period_id`.
        day_period_rules)r   r   r   r   r   r   r   t  s   zLocale.day_period_rulesc                 C   r   )z{Locale display names for weekdays.

        >>> Locale('de', 'DE').days['format']['wide'][3]
        u'Donnerstag'
        daysr   r   r   r   r   r   z  r   zLocale.daysc                 C   r   )zyLocale display names for months.

        >>> Locale('de', 'DE').months['format']['wide'][10]
        u'Oktober'
        monthsr   r   r   r   r   r     r   zLocale.monthsc                 C   r   )zLocale display names for quarters.

        >>> Locale('de', 'DE').quarters['format']['wide'][1]
        u'1. Quartal'
        quartersr   r   r   r   r   r     r   zLocale.quartersc                 C   r   )a  Locale display names for eras.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').eras['wide'][1]
        u'Anno Domini'
        >>> Locale('en', 'US').eras['abbreviated'][0]
        u'BC'
        erasr   r   r   r   r   r     r   zLocale.erasc                 C   r   )uc  Locale display names for time zones.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').time_zones['Europe/London']['long']['daylight']
        u'British Summer Time'
        >>> Locale('en', 'US').time_zones['America/St_Johns']['city']
        u'St. John’s'
        
time_zonesr   r   r   r   r   r     r   zLocale.time_zonesc                 C   r   )a  Locale display names for meta time zones.

        Meta time zones are basically groups of different Olson time zones that
        have the same GMT offset and daylight savings time.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').meta_zones['Europe_Central']['long']['daylight']
        u'Central European Summer Time'

        .. versionadded:: 0.9
        
meta_zonesr   r   r   r   r   r     s   
zLocale.meta_zonesc                 C   r   )ac  Patterns related to the formatting of time zones.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').zone_formats['fallback']
        u'%(1)s (%(0)s)'
        >>> Locale('pt', 'BR').zone_formats['region']
        u'Hor\xe1rio %s'

        .. versionadded:: 0.9
        zone_formatsr   r   r   r   r   r        
zLocale.zone_formatsc                 C      | j d d S )zThe first day of a week, with 0 being Monday.

        >>> Locale('de', 'DE').first_week_day
        0
        >>> Locale('en', 'US').first_week_day
        6
        	week_data	first_dayr   r   r   r   r   first_week_day  s   	zLocale.first_week_dayc                 C   r   )zqThe day the weekend starts, with 0 being Monday.

        >>> Locale('de', 'DE').weekend_start
        5
        r   weekend_startr   r   r   r   r   r        zLocale.weekend_startc                 C   r   )zmThe day the weekend ends, with 0 being Monday.

        >>> Locale('de', 'DE').weekend_end
        6
        r   weekend_endr   r   r   r   r   r     r   zLocale.weekend_endc                 C   r   )zThe minimum number of days in a week so that the week is counted as
        the first week of a year or month.

        >>> Locale('de', 'DE').min_week_days
        4
        r   min_daysr   r   r   r   r   min_week_days  s   zLocale.min_week_daysc                 C   r   )aJ  Locale patterns for date formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').date_formats['short']
        <DateTimePattern u'M/d/yy'>
        >>> Locale('fr', 'FR').date_formats['long']
        <DateTimePattern u'd MMMM y'>
        date_formatsr   r   r   r   r   r     r   zLocale.date_formatsc                 C   r   )aL  Locale patterns for time formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en', 'US').time_formats['short']
        <DateTimePattern u'h:mm a'>
        >>> Locale('fr', 'FR').time_formats['long']
        <DateTimePattern u'HH:mm:ss z'>
        time_formatsr   r   r   r   r   r     r   zLocale.time_formatsc                 C   r   )a,  Locale patterns for datetime formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en').datetime_formats['full']
        u"{1} 'at' {0}"
        >>> Locale('th').datetime_formats['medium']
        u'{1} {0}'
        datetime_formatsr   r   r   r   r   r     r   zLocale.datetime_formatsc                 C   r   )aA  Locale patterns for formatting parts of a datetime.

        >>> Locale('en').datetime_skeletons['MEd']
        <DateTimePattern u'E, M/d'>
        >>> Locale('fr').datetime_skeletons['MEd']
        <DateTimePattern u'E dd/MM'>
        >>> Locale('fr').datetime_skeletons['H']
        <DateTimePattern u"HH 'h'">
        datetime_skeletonsr   r   r   r   r   r   #  s   
zLocale.datetime_skeletonsc                 C   r   )u   Locale patterns for interval formatting.

        .. note:: The format of the value returned may change between
                  Babel versions.

        How to format date intervals in Finnish when the day is the
        smallest changing component:

        >>> Locale('fi_FI').interval_formats['MEd']['d']
        [u'E d. – ', u'E d.M.']

        .. seealso::

           The primary API to use this data is :py:func:`babel.dates.format_interval`.


        :rtype: dict[str, dict[str, list[str]]]
        interval_formatsr   r   r   r   r   r   0  s   
zLocale.interval_formatsc                 C      | j dtS )a  Plural rules for the locale.

        >>> Locale('en').plural_form(1)
        'one'
        >>> Locale('en').plural_form(0)
        'other'
        >>> Locale('fr').plural_form(0)
        'one'
        >>> Locale('ru').plural_form(100)
        'many'
        plural_formr   r   _default_plural_ruler   r   r   r   r   F  s   zLocale.plural_formc                 C   r   )a  Patterns for generating lists

        .. note:: The format of the value returned may change between
                  Babel versions.

        >>> Locale('en').list_patterns['standard']['start']
        u'{0}, {1}'
        >>> Locale('en').list_patterns['standard']['end']
        u'{0}, and {1}'
        >>> Locale('en_GB').list_patterns['standard']['end']
        u'{0} and {1}'
        list_patternsr   r   r   r   r   r   U  r   zLocale.list_patternsc                 C   r   )a?  Plural rules for the locale.

        >>> Locale('en').ordinal_form(1)
        'one'
        >>> Locale('en').ordinal_form(2)
        'two'
        >>> Locale('en').ordinal_form(3)
        'few'
        >>> Locale('fr').ordinal_form(2)
        'other'
        >>> Locale('ru').ordinal_form(100)
        'other'
        ordinal_formr   r   r   r   r   r   e  s   zLocale.ordinal_formc                 C   r   )zLocalized names for various measurement systems.

        >>> Locale('fr', 'FR').measurement_systems['US']
        u'am\xe9ricain'
        >>> Locale('en', 'US').measurement_systems['US']
        u'US'

        measurement_systemsr   r   r   r   r   r   v  r   zLocale.measurement_systemsc                 C   r   )zThe text direction for the language.

        >>> Locale('de', 'DE').character_order
        'left-to-right'
        >>> Locale('ar', 'SA').character_order
        'right-to-left'
        character_orderr   r   r   r   r   r     r   zLocale.character_orderc                 C   s   d dd | jdD S )zThe text direction for the language in CSS short-hand form.

        >>> Locale('de', 'DE').text_direction
        'ltr'
        >>> Locale('ar', 'SA').text_direction
        'rtl'
        r   c                 s   s    | ]}|d  V  qdS )r   Nr   ).0wordr   r   r   	<genexpr>  s    z(Locale.text_direction.<locals>.<genexpr>-)r   r   splitr   r   r   r   text_direction  s   	zLocale.text_directionc                 C   r   )zDisplay names for units of measurement.

        .. seealso::

           You may want to use :py:func:`babel.units.get_unit_name` instead.

        .. note:: The format of the value returned may change between
                  Babel versions.

        unit_display_namesr   r   r   r   r   r     r   zLocale.unit_display_names)NNN)r   Tr   )?rp   rq   rr   rs   rm   classmethodLOCALE_ALIASESr   r   r|   r   r   r   r   r   propertyr   r   display_namer   language_namer   territory_namer   script_namer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   l   s    
o		

































	












r   c              	   C   s   | ddddf}t d|D ]A}t|}|rM|dkr$d|v r$|dd }|dd d	v r0d
}n
|r:||v r:|| }z	tt|W   S  tyL   Y qw qdS )a  Returns the system default locale for a given category, based on
    environment variables.

    >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE']:
    ...     os.environ[name] = ''
    >>> os.environ['LANG'] = 'fr_FR.UTF-8'
    >>> default_locale('LC_MESSAGES')
    'fr_FR'

    The "C" or "POSIX" pseudo-locales are treated as aliases for the
    "en_US_POSIX" locale:

    >>> os.environ['LC_MESSAGES'] = 'POSIX'
    >>> default_locale('LC_MESSAGES')
    'en_US_POSIX'

    The following fallbacks to the variable are always considered:

    - ``LANGUAGE``
    - ``LC_ALL``
    - ``LC_CTYPE``
    - ``LANG``

    :param category: one of the ``LC_XXX`` environment variable names
    :param aliases: a dictionary of aliases for locale identifiers
    LANGUAGELC_ALLLC_CTYPELANGN:r   .)CPOSIXen_US_POSIX)r   r   getenvr   r   r
   
ValueError)r~   r{   varnamesnamer   r   r   r   r     s"   
r   r   c                 C   s   dd |D }| D ]@}|  }||v r|  S |r0||}|r0|d|}|  |v r0|  S ||}t|dkrI|d   |v rI|d   S q	dS )ul  Find the best match between available and requested locale strings.

    >>> negotiate_locale(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
    'de_DE'
    >>> negotiate_locale(['de_DE', 'en_US'], ['en', 'de'])
    'de'

    Case is ignored by the algorithm, the result uses the case of the preferred
    locale identifier:

    >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at'])
    'de_DE'

    >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at'])
    'de_DE'

    By default, some web browsers unfortunately do not include the territory
    in the locale identifier for many locales, and some don't even allow the
    user to easily add the territory. So while you may prefer using qualified
    locale identifiers in your web-application, they would not normally match
    the language-only locale sent by such browsers. To workaround that, this
    function uses a default mapping of commonly used langauge-only locale
    identifiers to identifiers including the territory:

    >>> negotiate_locale(['ja', 'en_US'], ['ja_JP', 'en_US'])
    'ja_JP'

    Some browsers even use an incorrect or outdated language code, such as "no"
    for Norwegian, where the correct locale identifier would actually be "nb_NO"
    (Bokmål) or "nn_NO" (Nynorsk). The aliases are intended to take care of
    such cases, too:

    >>> negotiate_locale(['no', 'sv'], ['nb_NO', 'sv_SE'])
    'nb_NO'

    You can override this default mapping by passing a different `aliases`
    dictionary to this function, or you can bypass the behavior althogher by
    setting the `aliases` parameter to `None`.

    :param preferred: the list of locale strings preferred by the user
    :param available: the list of locale strings available
    :param sep: character that separates the different parts of the locale
                strings
    :param aliases: a dictionary of aliases for locale identifiers
    c                 S   s   g | ]}|r|  qS r   )lower)r   ar   r   r   
<listcomp>  s    z$negotiate_locale.<locals>.<listcomp>r      r   N)r  r   replacer   len)r   r   r   r{   r   llaliasr   r   r   r   r	     s    .

r	   c                 C   sT  d| v r|  ddd } d| v r|  ddd } |  |}|d }| s.td| d } }}|rKt|d dkrK|d  rK|d }|rvt|d dkrc|d  rc|d }nt|d d	krv|d  rv|d}|rt|d dkr|d d  st|d d
kr|d d  r| }|rtd|  ||||fS )a  Parse a locale identifier into a tuple of the form ``(language,
    territory, script, variant)``.

    >>> parse_locale('zh_CN')
    ('zh', 'CN', None, None)
    >>> parse_locale('zh_Hans_CN')
    ('zh', 'CN', 'Hans', None)

    The default component separator is "_", but a different separator can be
    specified using the `sep` parameter:

    >>> parse_locale('zh-CN', sep='-')
    ('zh', 'CN', None, None)

    If the identifier cannot be parsed into a locale, a `ValueError` exception
    is raised:

    >>> parse_locale('not_a_LOCALE_String')
    Traceback (most recent call last):
      ...
    ValueError: 'not_a_LOCALE_String' is not a valid locale identifier

    Encoding information and locale modifiers are removed from the identifier:

    >>> parse_locale('it_IT@euro')
    ('it', 'IT', None, None)
    >>> parse_locale('en_US.UTF-8')
    ('en', 'US', None, None)
    >>> parse_locale('de_DE.iso885915@euro')
    ('de', 'DE', None, None)

    See :rfc:`4646` for more information.

    :param identifier: the locale identifier string
    :param sep: character that separates the different components of the locale
                identifier
    :raise `ValueError`: if the string does not appear to be a valid locale
                         identifier
    r  r  r   @zexpected only letters, got %rN   r         z#%r is not a valid locale identifier)	r   popr  isalphar
  r  titleupperisdigit)rn   r   r   langrv   ru   rw   r   r   r   r
     s6   (

 r
   c                 C   sD   t | dd } | ddt|    \}}}}|td||||fS )a  The reverse of :func:`parse_locale`.  It creates a locale identifier out
    of a ``(language, territory, script, variant)`` tuple.  Items can be set to
    ``None`` and trailing ``None``\s can also be left out of the tuple.

    >>> get_locale_identifier(('de', 'DE', None, '1999'))
    'de_DE_1999'

    .. versionadded:: 1.0

    :param tup: the tuple as returned by :func:`parse_locale`.
    :param sep: the separator for the identifier.
    Nr  r   )tupler  r   r   )tupr   r  ru   rv   rw   r   r   r   r   ^  s   r   )r   )rs   r   babelr   babel._compatr   r   babel.pluralr   __all__r   r   r   r   r   rl   r   objectr   r   r	   r
   r   r   r   r   r   <module>   s   
	-      A-
?K