o p`@sdZddlZddlZddlmZddlmZmZmZiZ e Z ej ej edZddZdd Zd d Zdd dZddZGdddeZGdddejZdS)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-2019 by the Babel Team. :license: BSD, see LICENSE for more details. N)chain)pickle string_typesabcz locale-datacCsL|rt|ts dS|}tttgD] }||kr#|SqdS)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)name locale_idr2/usr/lib/python3/dist-packages/babel/localedata.pynormalize_locales  rcCsX|rt|ts dStj|}|tvrdStjtjtd|}|r&dSt t |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%s.dat) rrospathbasenamer existsjoin_dirnameboolr)r file_foundrrrr)s rcCs<ttdd}|durddddttDDt_}|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 extensionrrr Hs z&locale_identifiers..css|] }tj|VqdSN)rrsplitext)rfilenamerrr Ksz%locale_identifiers..)getattrr rlistdirrr)datarrrr 9s  r TcCstj|}tzyt|}|s}|dks|si}n,ddlm}|d|}|sA| d}t |dkr8d}n d |dd}t | }tj td |}t|d }|dkre|ret|t |nt |}Wdn1stwY|t|<|WtStw) 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_globalparent_exceptions_Nrrb)rrr _cache_lockacquirer get babel.corer'splitlenrloadcopyropenmergerrelease)r merge_inheritedr&r'parentpartsr"fileobjrrrr3Qs2          r3cCs|D]I\}}|durM||}t|trG|duri}t|tr&||f}n#t|tr=|\}}|}t||||f}n |}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)itemsr/rdictAliastupler4r6)dict1dict2keyval2val1aliasothersrrrr6s&         r6c@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)selfrGrrr__init__zAlias.__init__cCsdt|j|jfS)Nz<%s %r>)type__name__rGrHrrr__repr__zAlias.__repr__cCsP|}|jD]}||}qt|tr||}|St|tr&|\}}||}|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` )rGrr>resolver?)rHr&baserBrErFrrrrPs      z Alias.resolveN)rL __module__ __qualname____doc__rIrNrPrrrrr>s  r>c@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual values. NcCs||_|dur |}||_dSr )_datarQ)rHr&rQrrrrIs zLocaleDataDict.__init__cC t|jSr )r2rVrMrrr__len__ zLocaleDataDict.__len__cCrWr )iterrVrMrrr__iter__rYzLocaleDataDict.__iter__cCs|j|}}t|tr||j}t|tr(|\}}||j}t||t|t ur5t ||jd}||ur>||j|<|SN)rQ) rVrr>rPrQr?r4r6rKr=rU)rHrBorigvalrErFrrr __getitem__s      zLocaleDataDict.__getitem__cCs||j|<dSr rV)rHrBvaluerrr __setitem__rJzLocaleDataDict.__setitem__cCs |j|=dSr r`)rHrBrrr __delitem__s zLocaleDataDict.__delitem__cCst|j|jdSr\)rUrVr4rQrMrrrr4rOzLocaleDataDict.copyr ) rLrRrSrTrIrXr[r_rbrcr4rrrrrUs  rU)T)rTr threading itertoolsr babel._compatrrrr RLockr-rrdirname__file__rrrr r3r6objectr>MutableMappingrUrrrrs   7!!