dbfdg 3 da@sdZddlZddlZddlZddlZddlmZddlmZddlZddl m Z m Z ddZ iZ ejZejje dZejd ejZd d Zd d ZddZddZdddZddZGdddeZGdddeZdS)aB 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 by the Babel Team. :license: BSD, see LICENSE for more details. N)MutableMapping)chain)pickle string_typescCs0ttddr ttddr tj}n tjjt}|S)NfrozenF_MEIPASS)getattrsysrospathdirname__file__)Zbasedirr /usr/lib/python3.6/localedata.py get_base_dirs rz locale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$cCsP| st|t rdS|jj}x(tjttgD]}||jkr4|Sq4WdS)zNormalize 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) isinstancerstriplowerr from_iterable_cachelocale_identifiers)nameZ locale_idrrrnormalize_locale)s   rcCsJtjj|}tjdkr8tjtjj|dr8td|tjj t d|S)z? Resolve a locale identifier to a `.dat` path on disk. Zwin32rzName %s is invalid on Windowsz%s.dat) r r basenamer platform_windows_reserved_name_rematchsplitext ValueErrorjoin_dirname)rrrrresolve_locale_filename7s   r!cCsF| st|t rdS|tkr"dStjjt|}|r:dStt|S)zCheck whether locale data is available for the given locale. Returns `True` if it exists, `False` otherwise. :param name: the locale identifier string FT) rrrr r existsr!boolr)rZ file_foundrrrr"Gs r"cCsddddtjtDDS)zReturn a list of all locale identifiers for which locale data is available. .. versionadded:: 0.8.1 :return: a list of locale identifiers (strings) cSs$g|]\}}|dkr|dkr|qS)z.datrootr).0Zstem extensionrrr ^sz&locale_identifiers..cSsg|]}tjj|qSr)r r r)r%filenamerrrr'_s)r listdirr rrrrrVsrTcCstjj|}tjztj|}|s|dks2| r8i}nXddlm}|dj|}|s|j d}t |dkrrd}ndj |dd }t |j }t|}t|d.}|dkr|rt|tj |n tj |}WdQRX|t|<|StjXdS) 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 r$r) get_globalZparent_exceptions_Nrb)r r r _cache_lockacquirergetZ babel.corer*splitlenrloadcopyr!openmergerrelease)rZmerge_inheriteddatar*parentpartsr(Zfileobjrrrr4cs.        r4cCsx|jD]\}}|dk r |j|}t|tr|dkr:i}t|trN||f}qt|tr||\}}|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)itemsr1rdictAliastupler5r7)Zdict1Zdict2keyZval2Zval1aliasothersrrrr7s"         r7c@s(eZdZdZddZddZddZdS) r>zRepresentation 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)selfrCrrr__init__szAlias.__init__cCsdt|j|jfS)Nz<%s %r>)type__name__rC)rDrrr__repr__szAlias.__repr__cCsR|}x|jD] }||}q Wt|tr2|j|}nt|trN|\}}|j|}|S)zResolve 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` )rCrr>resolver?)rDr9baser@rArBrrrrIs       z Alias.resolveN)rG __module__ __qualname____doc__rErHrIrrrrr>sr>c@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual values. NcCs||_|dkr|}||_dS)N)_datarJ)rDr9rJrrrrEszLocaleDataDict.__init__cCs t|jS)N)r3rO)rDrrr__len__szLocaleDataDict.__len__cCs t|jS)N)iterrO)rDrrr__iter__szLocaleDataDict.__iter__cCs|j|}}t|tr$|j|j}t|trP|\}}|j|jj}t||t|t krjt ||jd}||k r|||j|<|S)N)rJ) rOrr>rIrJr?r5r7rFr=rN)rDr@ZorigvalrArBrrr __getitem__s      zLocaleDataDict.__getitem__cCs||j|<dS)N)rO)rDr@valuerrr __setitem__szLocaleDataDict.__setitem__cCs |j|=dS)N)rO)rDr@rrr __delitem__szLocaleDataDict.__delitem__cCst|jj|jdS)N)rJ)rNrOr5rJ)rDrrrr5szLocaleDataDict.copy)N) rGrKrLrMrErPrRrTrVrWr5rrrrrNs rN)T)rMr rer Z threading collectionsr itertoolsrZ babel._compatrrrrRLockr/r rr compileIrrr!r"rr4r7objectr>rNrrrr s*    7!!