
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
da                 @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlZddl	m
Z
mZ dd Zi Zej Zejje dZejd	ejZd
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 )aB  
    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 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)MutableMapping)chain)picklestring_typesc              C   s0   t tddr t tdd r tj} ntjjt} | S )NfrozenF_MEIPASS)getattrsysr   ospathdirname__file__)Zbasedir r    /usr/lib/python3.6/localedata.pyget_base_dir   s    r   zlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$c             C   sP   |  st | t rdS | j j } x(tjtt gD ]}| |j kr4|S q4W 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_idr   r   r   normalize_locale)   s    r   c             C   sJ   t jj| } tjdkr8tjt jj| d r8td|  t jj	t
d|  S )z?
    Resolve a locale identifier to a `.dat` path on disk.
    Zwin32r   zName %s is invalid on Windowsz%s.dat)r
   r   basenamer	   platform_windows_reserved_name_rematchsplitext
ValueErrorjoin_dirname)r   r   r   r   resolve_locale_filename7   s     r!   c             C   sF   |  st | t rdS | tkr"dS tjjt| }|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
    FT)	r   r   r   r
   r   existsr!   boolr   )r   Z
file_foundr   r   r   r"   G   s    r"   c               C   s   dd dd t j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>^   s    z&locale_identifiers.<locals>.<listcomp>c             S   s   g | ]}t jj|qS r   )r
   r   r   )r%   filenamer   r   r   r'   _   s    )r
   listdirr    r   r   r   r   r   V   s    r   Tc             C   s   t jj| } tj  ztj| }|s| dks2| r8i }nXddlm} |dj| }|s| j	d}t
|dkrrd}ndj|dd	 }t|j }t| }t|d.}| dkr|rt|tj| n
tj|}W dQ R X |t| < |S tj  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_   Nrb)r
   r   r   _cache_lockacquirer   getZ
babel.corer*   splitlenr   loadcopyr!   openmerger   release)r   Zmerge_inheriteddatar*   parentpartsr(   Zfileobjr   r   r   r4   c   s.    

r4   c             C   s   x|j  D ]\}}|dk	r
| j|}t|tr|dkr:i }t|trN||f}qt|tr||\}}|j }t|| ||f}q|j }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)itemsr1   r   dictAliastupler5   r7   )Zdict1Zdict2keyZval2Zval1aliasothersr   r   r   r7      s"    






r7   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	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`.
    c             C   s   t || _d S )N)r?   keys)selfrC   r   r   r   __init__   s    zAlias.__init__c             C   s   dt | j| jf S )Nz<%s %r>)type__name__rC   )rD   r   r   r   __repr__   s    zAlias.__repr__c             C   sR   |}x| j D ]}|| }qW t|tr2|j|}nt|trN|\}}|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`
        )rC   r   r>   resolver?   )rD   r9   baser@   rA   rB   r   r   r   rI      s    	


zAlias.resolveN)rG   
__module____qualname____doc__rE   rH   rI   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 kr|}|| _d S )N)_datarJ   )rD   r9   rJ   r   r   r   rE      s    zLocaleDataDict.__init__c             C   s
   t | jS )N)r3   rO   )rD   r   r   r   __len__   s    zLocaleDataDict.__len__c             C   s
   t | jS )N)iterrO   )rD   r   r   r   __iter__   s    zLocaleDataDict.__iter__c             C   s   | j |  }}t|tr$|j| j}t|trP|\}}|j| jj }t|| t|t	krjt
|| jd}||k	r||| j |< |S )N)rJ   )rO   r   r>   rI   rJ   r?   r5   r7   rF   r=   rN   )rD   r@   ZorigvalrA   rB   r   r   r   __getitem__   s    



zLocaleDataDict.__getitem__c             C   s   || j |< d S )N)rO   )rD   r@   valuer   r   r   __setitem__   s    zLocaleDataDict.__setitem__c             C   s   | j |= d S )N)rO   )rD   r@   r   r   r   __delitem__   s    zLocaleDataDict.__delitem__c             C   s   t | jj | jdS )N)rJ   )rN   rO   r5   rJ   )rD   r   r   r   r5     s    zLocaleDataDict.copy)N)rG   rK   rL   rM   rE   rP   rR   rT   rV   rW   r5   r   r   r   r   rN      s   
rN   )T)rM   r
   rer	   Z	threadingcollectionsr   	itertoolsr   Zbabel._compatr   r   r   r   RLockr/   r   r   r    compileIr   r   r!   r"   r   r4   r7   objectr>   rN   r   r   r   r   <module>   s*   	
7!!