3

X'íc¾ã@sÊdZddlZddlZddlZddlZddlZddlmZddlm	Z	iZ
ejƒZej
jej
jeƒdƒZejdejƒZdd„Zd	d
„Zdd„Zd
d„Zddd„Zdd„ZGdd„dƒZGdd„dejƒZdS)aG
    babel.localedata
    ~~~~~~~~~~~~~~~~

    Low-level locale data access.

    :note: The `Locale` class, which uses this module under the hood, provides a
           more convenient interface for accessing the locale data.

    :copyright: (c) 2013-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
éN)Úabc)Úchainzlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$cCsP|st|tƒrdS|jƒjƒ}x(tjttƒgƒD]}||jƒkr4|Sq4WdS)zŸNormalize a locale ID by stripping spaces and apply proper casing.

    Returns the normalized locale ID string or `None` if the ID is not
    recognized.
    N)Ú
isinstanceÚstrÚstripÚlowerrÚ
from_iterableÚ_cacheÚlocale_identifiers)ÚnameZ	locale_id©rú1/tmp/pip-build-gk9425m9/babel/babel/localedata.pyÚnormalize_localesrcCsJtjj|ƒ}tjdkr8tjtjj|ƒdƒr8td|ƒ‚tjj	t
d|ƒS)z?
    Resolve a locale identifier to a `.dat` path on disk.
    Úwin32rzName %s is invalid on Windowsz%s.dat)ÚosÚpathÚbasenameÚsysÚplatformÚ_windows_reserved_name_reÚmatchÚsplitextÚ
ValueErrorÚjoinÚ_dirname)rrrr
Úresolve_locale_filename+s rcCsF|st|tƒrdS|tkr"dStjjt|ƒƒ}|r:dStt|ƒƒS)z¥Check whether locale data is available for the given locale.

    Returns `True` if it exists, `False` otherwise.

    :param name: the locale identifier string
    FT)	rrr	rrÚexistsrÚboolr)rZ
file_foundrrr
r;srcCs<ttddƒ}|dkr8dd„dd„tjtƒDƒDƒt_}|S)a„Return a list of all locale identifiers for which locale data is
    available.

    This data is cached after the first invocation in `locale_identifiers.cache`.

    Removing the `locale_identifiers.cache` attribute or setting it to `None`
    will cause this function to re-read the list from disk.

    .. versionadded:: 0.8.1

    :return: a list of locale identifiers (strings)
    ÚcacheNcSs$g|]\}}|dkr|dkr|‘qS)z.datÚrootr)Ú.0ZstemÚ	extensionrrr
ú
<listcomp>Zsz&locale_identifiers.<locals>.<listcomp>css|]}tjj|ƒVqdS)N)rrr)r Úfilenamerrr
ú	<genexpr>\sz%locale_identifiers.<locals>.<genexpr>)Úgetattrr
rÚlistdirrr)Údatarrr
r
Js

r
TcCsðtjj|ƒ}tjƒzÌtj|ƒ}|sÞ|dks2|r8i}nXddlm}|dƒj|ƒ}|s„|j	dƒ}t
|ƒdkrrd}ndj|dd	…ƒ}t|ƒj
ƒ}t|ƒ}t|dƒ.}|dkrÂ|rÂt|tj|ƒƒn
tj|ƒ}WdQRX|t|<|StjƒXdS)
aeLoad the locale data for the given locale.

    The locale data is a dictionary that contains much of the data defined by
    the Common Locale Data Repository (CLDR). This data is stored as a
    collection of pickle files inside the ``babel`` package.

    >>> d = load('en_US')
    >>> d['languages']['sv']
    u'Swedish'

    Note that the results are cached, and subsequent requests for the same
    locale return the same dictionary:

    >>> d1 = load('en_US')
    >>> d2 = load('en_US')
    >>> d1 is d2
    True

    :param name: the locale identifier string (or "root")
    :param merge_inherited: whether the inherited data should be merged into
                            the data of the requested locale
    :raise `IOError`: if no locale data file is found for the given locale
                      identifer, or one of the locales it inherits from
    rr)Ú
get_globalZparent_exceptionsÚ_éNÚrbéÿÿÿÿ)rrrÚ_cache_lockÚacquirer	ÚgetZ
babel.corer(ÚsplitÚlenrÚloadÚcopyrÚopenÚmergeÚpickleÚrelease)rZmerge_inheritedr'r(ÚparentÚpartsr#Úfileobjrrr
r2bs.

r2cCs¤xž|jƒD]’\}}|dk	r
|j|ƒ}t|tƒr|dkr:i}t|tƒrN||f}q”t|tƒr||\}}|jƒ}t||ƒ||f}q”|jƒ}t||ƒn|}|||<q
WdS)anMerge the data from `dict2` into the `dict1` dictionary, making copies
    of nested dictionaries.

    >>> d = {1: 'foo', 3: 'baz'}
    >>> merge(d, {1: 'Foo', 2: 'Bar'})
    >>> sorted(d.items())
    [(1, 'Foo'), (2, 'Bar'), (3, 'baz')]

    :param dict1: the dictionary to merge into
    :param dict2: the dictionary containing the data that should be merged
    N)Úitemsr/rÚdictÚAliasÚtupler3r5)Zdict1Zdict2ÚkeyZval2Zval1ÚaliasÚothersrrr
r5™s"






r5c@s(eZdZdZdd„Zdd„Zdd„ZdS)	r=zŸRepresentation of an alias in the locale data.

    An alias is a value that refers to some other part of the locale data,
    as specified by the `keys`.
    cCst|ƒ|_dS)N)r>Úkeys)ÚselfrBrrr
Ú__init__ÁszAlias.__init__cCsdt|ƒj|jfS)Nz<%s %r>)ÚtypeÚ__name__rB)rCrrr
Ú__repr__ÄszAlias.__repr__cCsR|}x|jD]}||}qWt|tƒr2|j|ƒ}nt|tƒrN|\}}|j|ƒ}|S)zôResolve the alias based on the given data.

        This is done recursively, so if one alias resolves to a second alias,
        that second alias will also be resolved.

        :param data: the locale data
        :type data: `dict`
        )rBrr=Úresolver>)rCr'Úbaser?r@rArrr
rHÇs	


z
Alias.resolveN)rFÚ
__module__Ú__qualname__Ú__doc__rDrGrHrrrr
r=ºsr=c@sJeZdZdZddd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
dS)ÚLocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual
    values.
    NcCs||_|dkr|}||_dS)N)Ú_datarI)rCr'rIrrr
rDàszLocaleDataDict.__init__cCs
t|jƒS)N)r1rN)rCrrr
Ú__len__æszLocaleDataDict.__len__cCs
t|jƒS)N)ÚiterrN)rCrrr
Ú__iter__észLocaleDataDict.__iter__cCs€|j|}}t|tƒr$|j|jƒ}t|tƒrP|\}}|j|jƒjƒ}t||ƒt|ƒt	krjt
||jd}||k	r|||j|<|S)N)rI)rNrr=rHrIr>r3r5rEr<rM)rCr?ÚorigÚvalr@rArrr
Ú__getitem__ìs



zLocaleDataDict.__getitem__cCs||j|<dS)N)rN)rCr?Úvaluerrr
Ú__setitem__úszLocaleDataDict.__setitem__cCs|j|=dS)N)rN)rCr?rrr
Ú__delitem__ýszLocaleDataDict.__delitem__cCst|jjƒ|jdS)N)rI)rMrNr3rI)rCrrr
r3szLocaleDataDict.copy)N)rFrJrKrLrDrOrQrTrVrWr3rrrr
rMÛs
rM)T)rLr6rÚrerÚ	threadingÚcollectionsrÚ	itertoolsrr	ÚRLockr-rrÚdirnameÚ__file__rÚcompileÚIrrrrr
r2r5r=ÚMutableMappingrMrrrr
Ú<module>s&
7!!