o
    
p�`Ù  ã                   @   s¦   d Z ddlZddlZddlmZ ddlmZmZmZ i Z	e 
¡ Zej ej e¡d¡Zdd„ Zdd	„ Zd
d„ Zddd„Zdd„ ZG dd„ deƒZG dd„ dejƒZdS )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_typesÚabczlocale-datac                 C   sL   | rt | tƒs	dS |  ¡  ¡ } t ttƒ g¡D ]}| | ¡ kr#|  S qdS )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)Ú
isinstancer   ÚstripÚlowerr   Úfrom_iterableÚ_cacheÚlocale_identifiers)ÚnameÚ	locale_id© r   ú2/usr/lib/python3/dist-packages/babel/localedata.pyÚnormalize_locale   s   ÿÿr   c                 C   sX   | rt | tƒs	dS tj | ¡} | tv rdS tj tj td|  ¡¡}|r&dS t	t
| ƒƒ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ú%s.dat)r   r   ÚosÚpathÚbasenamer
   ÚexistsÚjoinÚ_dirnameÚboolr   )r   Ú
file_foundr   r   r   r   )   s   r   c                  C   s<   t tddƒ} | du rdd„ dd„ t t¡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)
    ÚcacheNc                 S   s$   g | ]\}}|d kr|dkr|‘qS )z.datÚrootr   )Ú.0ÚstemÚ	extensionr   r   r   Ú
<listcomp>H   s
    ýz&locale_identifiers.<locals>.<listcomp>c                 s   s   � | ]	}t j |¡V  qd S ©N)r   r   Úsplitext)r   Úfilenamer   r   r   Ú	<genexpr>K   s   € z%locale_identifiers.<locals>.<genexpr>)Úgetattrr   r   Úlistdirr   r   )Údatar   r   r   r   9   s   ýr   Tc                 C   s  t j | ¡} t ¡  zyt | ¡}|s}| dks|si }n,ddlm} |dƒ | ¡}|sA|  	d¡}t
|ƒdkr8d}n	d |dd… ¡}t|ƒ ¡ }t j td	|  ¡}t|d
ƒ�}| dkre|ret|t |¡ƒ nt |¡}W d  ƒ n1 stw   Y  |t| < |W t ¡  S t ¡  w )ae  Load 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_globalÚparent_exceptionsÚ_é   Néÿÿÿÿr   Úrb)r   r   r   Ú_cache_lockÚacquirer
   ÚgetÚ
babel.corer'   ÚsplitÚlenr   ÚloadÚcopyr   ÚopenÚmerger   Úrelease)r   Úmerge_inheritedr&   r'   ÚparentÚpartsr"   Úfileobjr   r   r   r3   Q   s2   


€ür3   c                 C   s    |  ¡ D ]I\}}|durM|  |¡}t|tƒrG|du ri }t|tƒr&||f}n#t|tƒr=|\}}| ¡ }t||ƒ ||f}n| ¡ }t||ƒ n|}|| |< qdS )an  Merge 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Útupler4   r6   )Údict1Údict2ÚkeyÚval2Úval1ÚaliasÚothersr   r   r   r6   ˆ   s&   






€îr6   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	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`.
    c                 C   s   t |ƒ| _d S r    )r?   Úkeys)ÚselfrG   r   r   r   Ú__init__°   ó   zAlias.__init__c                 C   s   dt | ƒj| jf S )Nz<%s %r>)ÚtypeÚ__name__rG   ©rH   r   r   r   Ú__repr__³   ó   zAlias.__repr__c                 C   sP   |}| j D ]}|| }qt|tƒr| |¡}|S t|tƒr&|\}}| |¡}|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`
        )rG   r   r>   Úresolver?   )rH   r&   ÚbaserB   rE   rF   r   r   r   rP   ¶   s   	




ý
zAlias.resolveN)rL   Ú
__module__Ú__qualname__Ú__doc__rI   rN   rP   r   r   r   r   r>   ©   s
    r>   c                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚLocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual
    values.
    Nc                 C   s   || _ |d u r	|}|| _d S r    )Ú_datarQ   )rH   r&   rQ   r   r   r   rI   Ï   s   
zLocaleDataDict.__init__c                 C   ó
   t | jƒS r    )r2   rV   rM   r   r   r   Ú__len__Õ   ó   
zLocaleDataDict.__len__c                 C   rW   r    )ÚiterrV   rM   r   r   r   Ú__iter__Ø   rY   zLocaleDataDict.__iter__c                 C   s€   | j |  }}t|tƒr| | j¡}t|tƒr(|\}}| | j¡ ¡ }t||ƒ t|ƒt	u r5t
|| jd�}||ur>|| j |< |S ©N)rQ   )rV   r   r>   rP   rQ   r?   r4   r6   rK   r=   rU   )rH   rB   ÚorigÚvalrE   rF   r   r   r   Ú__getitem__Û   s   



zLocaleDataDict.__getitem__c                 C   s   || j |< d S r    ©rV   )rH   rB   Úvaluer   r   r   Ú__setitem__é   rJ   zLocaleDataDict.__setitem__c                 C   s   | j |= d S r    r`   )rH   rB   r   r   r   Ú__delitem__ì   s   zLocaleDataDict.__delitem__c                 C   s   t | j ¡ | jd�S r\   )rU   rV   r4   rQ   rM   r   r   r   r4   ï   rO   zLocaleDataDict.copyr    )rL   rR   rS   rT   rI   rX   r[   r_   rb   rc   r4   r   r   r   r   rU   Ê   s    
rU   )T)rT   r   Ú	threadingÚ	itertoolsr   Úbabel._compatr   r   r   r
   ÚRLockr-   r   r   ÚdirnameÚ__file__r   r   r   r   r3   r6   Úobjectr>   ÚMutableMappingrU   r   r   r   r   Ú<module>   s   
7!!