B
    }<[/                 @   s   d Z ddlZddlZddlmZ ddlmZ ddl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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-2018 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)MutableMapping)chain)picklestring_typeszlocale-datac             C   sL   | rt | tsdS |   } x(ttt gD ]}| | kr0|S q0W dS )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)
isinstancer   striplowerr   from_iterable_cachelocale_identifiers)nameZ	locale_id r   Elib/python3.7/site-packages/Babel-2.6.0-py3.7.egg/babel/localedata.pynormalize_locale   s    r   c             C   sL   | rt | tsdS | tkrdS tjtjtd|  }|r@dS t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
    FTz%s.dat)
r   r   r
   ospathexistsjoin_dirnameboolr   )r   Z
file_foundr   r   r   r   *   s    r   c               C   s   dd dd t tD D S )zReturn a list of all locale identifiers for which locale data is
    available.

    .. versionadded:: 0.8.1

    :return: a list of locale identifiers (strings)
    c             S   s$   g | ]\}}|d kr|dkr|qS )z.datrootr   ).0Zstem	extensionr   r   r   
<listcomp>A   s    z&locale_identifiers.<locals>.<listcomp>c             S   s   g | ]}t j|qS r   )r   r   splitext)r   filenamer   r   r   r   B   s    )r   listdirr   r   r   r   r   r   9   s    r   Tc          	   C   s   t   zt| }|s| dks$|s*i }nXddlm} |d| }|sv| d}t|dkrdd}nd|dd }t	|
 }tjtd	|  }t|d
.}| dkr|rt|t	| n
t	|}W dQ R X |t| < |S t   X dS )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_globalZparent_exceptions_   Nz%s.datrb)_cache_lockacquirer
   getZ
babel.corer   splitlenr   loadcopyr   r   r   openmerger   release)r   Zmerge_inheriteddatar   parentpartsr   Zfileobjr   r   r   r'   F   s,    

r'   c             C   s   x|  D ]\}}|dk	r
| |}t|tr|dkr:i }t|trN||f}qt|tr||\}}| }t|| ||f}q| }t|| n|}|| |< q
W 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tupler(   r*   )Zdict1Zdict2keyZval2Zval1aliasothersr   r   r   r*   |   s"    






r*   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r1   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`.
    c             C   s   t || _d S )N)r2   keys)selfr6   r   r   r   __init__   s    zAlias.__init__c             C   s   dt | j| jf S )Nz<%s %r>)type__name__r6   )r7   r   r   r   __repr__   s    zAlias.__repr__c             C   sR   |}x| j D ]}|| }qW t|tr2||}nt|trN|\}}||}|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`
        )r6   r   r1   resolver2   )r7   r,   baser3   r4   r5   r   r   r   r<      s    	


zAlias.resolveN)r:   
__module____qualname____doc__r8   r;   r<   r   r   r   r   r1      s   r1   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 kr|}|| _d S )N)_datar=   )r7   r,   r=   r   r   r   r8      s    zLocaleDataDict.__init__c             C   s
   t | jS )N)r&   rB   )r7   r   r   r   __len__   s    zLocaleDataDict.__len__c             C   s
   t | jS )N)iterrB   )r7   r   r   r   __iter__   s    zLocaleDataDict.__iter__c             C   s   | j |  }}t|tr$|| j}t|trP|\}}|| j }t|| t|t	krjt
|| jd}||k	r||| j |< |S )N)r=   )rB   r   r1   r<   r=   r2   r(   r*   r9   r0   rA   )r7   r3   Zorigvalr4   r5   r   r   r   __getitem__   s    



zLocaleDataDict.__getitem__c             C   s   || j |< d S )N)rB   )r7   r3   valuer   r   r   __setitem__   s    zLocaleDataDict.__setitem__c             C   s   | j |= d S )N)rB   )r7   r3   r   r   r   __delitem__   s    zLocaleDataDict.__delitem__c             C   s   t | j | jdS )N)r=   )rA   rB   r(   r=   )r7   r   r   r   r(      s    zLocaleDataDict.copy)N)r:   r>   r?   r@   r8   rC   rE   rG   rI   rJ   r(   r   r   r   r   rA      s   
rA   )T)r@   r   Z	threadingcollectionsr   	itertoolsr   Zbabel._compatr   r   r
   RLockr"   r   r   dirname__file__r   r   r   r   r'   r*   objectr1   rA   r   r   r   r   <module>   s   
6!!