a `@sdZddlZddlZddlZddlZddlmZddlmZm Z m Z iZ e Z ejejedZedejZddZd d Zd d Zd dZdddZddZGdddeZGddde jZdS)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-2021 by the Babel Team. :license: BSD, see LICENSE for more details. N)chain)pickle string_typesabcz locale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$cCsL|rt|tsdS|}tttgD]}||kr.|Sq.dS)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_idr 4/usr/lib/python3.9/site-packages/babel/localedata.pynormalize_locales   rcCsJtj|}tjdkr8ttj|dr8td|tj t d|S)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 r r rresolve_locale_filename,s   rcCsB|rt|tsdS|tvrdStjt|}|r6dStt|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 Z file_foundr r rr<s rcCs<ttdd}|dur8ddddttDDt_}|S)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) cacheNcSs$g|]\}}|dkr|dkr|qS)z.datrootr ).0stem extensionr r r Zsz&locale_identifiers..css|]}tj|VqdSN)rrr)r!filenamer r r ]z%locale_identifiers..)getattrr rlistdirrr)datar r rr Ks  r TcCs tj|}tzt|}|s|dks0|s6i}nXddlm}|d|}|s| d}t |dkrpd}nd |dd}t | }t|}t|d 8}|dkr|rt|t |n t |}Wdn1s0Y|t|<|WtSt0dS) 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)rrr _cache_lockacquirer getZ babel.corer,splitlenrloadcopyropenmergerrelease)r Zmerge_inheritedr+r,parentpartsr&Zfileobjr r rr6cs2         (r6cCs|D]\}}|dur||}t|tr|dur8i}t|trL||f}qt|trz|\}}|}t||||f}q|}t||n|}|||<qdS)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)itemsr3rdictAliastupler7r9)Zdict1Zdict2keyZval2Zval1aliasothersr r rr9s"         r9c@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||_dSr%)r@keys)selfrDr r r__init__szAlias.__init__cCsdt|j|jfS)Nz<%s %r>)type__name__rDrEr r r__repr__szAlias.__repr__cCsN|}|jD] }||}q t|tr.||}nt|trJ|\}}||}|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` )rDrr?resolver@)rEr+baserArBrCr r rrKs       z Alias.resolveN)rH __module__ __qualname____doc__rFrJrKr r r rr?sr?c@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual values. NcCs||_|dur|}||_dSr%)_datarL)rEr+rLr r rrFszLocaleDataDict.__init__cCs t|jSr%)r5rQrIr r r__len__szLocaleDataDict.__len__cCs t|jSr%)iterrQrIr r r__iter__szLocaleDataDict.__iter__cCs|j|}}t|tr$||j}t|trP|\}}||j}t||t|t urjt ||jd}||ur|||j|<|SN)rL) rQrr?rKrLr@r7r9rGr>rP)rErAZorigvalrBrCr r r __getitem__s      zLocaleDataDict.__getitem__cCs||j|<dSr%rQ)rErAvaluer r r __setitem__szLocaleDataDict.__setitem__cCs |j|=dSr%rX)rErAr r r __delitem__szLocaleDataDict.__delitem__cCst|j|jdSrU)rPrQr7rLrIr r rr7szLocaleDataDict.copy)N) rHrMrNrOrFrRrTrWrZr[r7r r r rrPs rP)T) rOrrer threading itertoolsrZ babel._compatrrrr RLockr1rrdirname__file__rcompileIrrrrr r6r9objectr?MutableMappingrPr r r rs$   7!!