ƪbvdZddlZddlZddlZddlZddlZddlmZddlm Z iZ ejZ ejjejjedZej$dej&ZdZdZd Zd Zdd Zd ZGd dZGddej8Zy)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)chainz locale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$c|rt|tsy|jj}t j t tgD]}||jk(s|cSy)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) isinstancestrstriplowerr from_iterable_cachelocale_identifiers)name locale_ids 2/usr/lib/python3/dist-packages/babel/localedata.pynormalize_localers_ z$, ::<   D((&2D2F)GH 9??$ $ c:tjj|}tjdk(rCt j tjj|drtd|ztjjtd|zS)z? Resolve a locale identifier to a `.dat` path on disk. win32rzName %s is invalid on Windowsz%s.dat) ospathbasenamesysplatform_windows_reserved_name_rematchsplitext ValueErrorjoin_dirname)r s rresolve_locale_filenamer+sv 77  D !D ||w#<#B#B277CSCSTXCYZ[C\#]84?@@ 77<<(T/ 22rc|rt|tsy|tvrytjj t |}|rdStt|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) rrr rrexistsrboolr)r file_founds rr!r!;sM z$, v~ 7 =>J4?4(8(>#??rcttdd}|HdtjtDDcgc]\}}|dk(r|dk7r|c}}xt_}|Scc}}w)aReturn 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) cacheNc3ZK|]#}tjj|%ywN)rrr).0filenames r z%locale_identifiers..\s MHRWW  h ' Ms)+z.datroot)getattrr rlistdirrr%)datastem extensions rr r Jsj %w 5D | N 88L M+ iF"tv~ +   4 K + sActjj|}tj  t j |}|s|dk(s|si}nnddlm}|dj |}|s6|jd}t|dk(rd}ndj|dd}t|j}t|}t|d 5}|dk7r"|r t!|t#j|nt#j|}ddd|t |<|tj%S#1swY(xYw#tj%wxYw) 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_globalparent_exceptions_Nrb)rrr _cache_lockacquirer get babel.corer2splitlenrloadcopyropenmergepicklerelease)r merge_inheritedr.r2parentpartsr)fileobjs rr>r>bs%2 77  D !Dzz$v~_1#$78<o$ G 45!;;w/D  0  F4L 0 0 s$B&E =D?E ?EE E!cb|jD]\}}| |j|}t|trl|i}t|tr||f}nUt|t r&|\}}|j }t||||f}n|j }t||n|}|||<y)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:rdictAliastupler?rA)dict1dict2keyval2val1aliasotherss rrArAs[[] T  99S>D$%<DdE* $)type__name__rVrWs r__repr__zAlias.__repr__s J//;;rc|}|jD]}||} t|tr|j|}|St|tr|\}}|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` )rVrrKresolverL)rWr.baserOrRrSs rrbz Alias.resolvesl99 C9D  dE "<<%D e $ ME6==&D rN)r^ __module__ __qualname____doc__rXr`rbrrrKrKs  <rrKc<eZdZdZd dZdZdZdZdZdZ d Z y) LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual values. Nc(||_||}||_yr')_datarc)rWr.rcs rrXzLocaleDataDict.__init__s <D rc,t|jSr')r=rkr_s r__len__zLocaleDataDict.__len__s4::rc,t|jSr')iterrkr_s r__iter__zLocaleDataDict.__iter__sDJJrc|j|x}}t|tr|j|j}t|t r:|\}}|j|jj }t||t|turt||j}||ur||j|<|SN)rc) rkrrKrbrcrLr?rAr]rJri)rWrOorigvalrRrSs r __getitem__zLocaleDataDict.__getitem__sZZ_$s c5 !++dii(C c5 !ME6-- *//1C #v  9  4995C d?!DJJsO rc"||j|<yr'rk)rWrOvalues r __setitem__zLocaleDataDict.__setitem__s 3rc|j|=yr'rw)rWrOs r __delitem__zLocaleDataDict.__delitem__s JJsOrc`t|jj|jSrr)rirkr?rcr_s rr?zLocaleDataDict.copysdjjoo/dii@@rr') r^rdrerfrXrmrpruryr{r?rgrrriris+    Arri)T)rfrBrrer threading collectionsr itertoolsrr RLockr8rrdirname__file__rcompileIrrrr!r r>rArKMutableMappingrirgrrrs   ioo 77<<1= A&BJJ'NPRPTPTU  3 @04nBB&AS''&Ar