o
    GEDi                     @   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m	Z	m
Z
 i Ze ZejejedZe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
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-2021 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)chain)picklestring_typesabczlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$c                 C   sL   | rt | ts	dS |   } ttt gD ]}| | kr#|  S q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)name	locale_id r   _/var/www/www-root/data/www/ovozai.pdev.uz/venv/lib/python3.10/site-packages/babel/localedata.pynormalize_locale   s   r   c                 C   sJ   t j| } tjdkrtt j| d rtd|  t j	t
d|  S )z?
    Resolve a locale identifier to a `.dat` path on disk.
    win32r   zName %s is invalid on Windowsz%s.dat)ospathbasenamesysplatform_windows_reserved_name_rematchsplitext
ValueErrorjoin_dirname)r   r   r   r   resolve_locale_filename,   s    r   c                 C   sB   | rt | ts	dS | tv rdS t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   
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>Z   s
    z&locale_identifiers.<locals>.<listcomp>c                 s   s    | ]	}t j|V  qd S N)r   r   r   )r#   filenamer   r   r   	<genexpr>]   s    z%locale_identifiers.<locals>.<genexpr>)getattrr   r   listdirr   r!   )datar   r   r   r   K   s   r   Tc                 C   s  t j| } t  ztt| }|sx| dks|si }n,ddlm} |d| }|sA| 	d}t
|dkr8d}n	d|dd }t| }t| }t|d	}| dkr`|r`t|t| nt|}W d   n1 sow   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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   r9   c   s2   


r9   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)itemsr5   r   dictAliastupler:   r<   )dict1dict2keyval2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 )	rD   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 r'   )rE   keys)selfrM   r   r   r   __init__      zAlias.__init__c                 C   s   dt | j| jf S )Nz<%s %r>)type__name__rM   rN   r   r   r   __repr__      zAlias.__repr__c                 C   sP   |}| j D ]}|| }qt|tr||}|S t|tr&|\}}||}|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`
        )rM   r   rD   resolverE   )rN   r,   baserH   rK   rL   r   r   r   rV      s   	





zAlias.resolveN)rR   
__module____qualname____doc__rO   rT   rV   r   r   r   r   rD      s
    rD   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'   )_datarW   )rN   r,   rW   r   r   r   rO      s   
zLocaleDataDict.__init__c                 C   
   t | jS r'   )r8   r\   rS   r   r   r   __len__      
zLocaleDataDict.__len__c                 C   r]   r'   )iterr\   rS   r   r   r   __iter__   r_   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)rW   )r\   r   rD   rV   rW   rE   r:   r<   rQ   rC   r[   )rN   rH   origvalrK   rL   r   r   r   __getitem__   s   



zLocaleDataDict.__getitem__c                 C   s   || j |< d S r'   r\   )rN   rH   valuer   r   r   __setitem__   rP   zLocaleDataDict.__setitem__c                 C   s   | j |= d S r'   rf   )rN   rH   r   r   r   __delitem__   s   zLocaleDataDict.__delitem__c                 C   s   t | j | jdS rb   )r[   r\   r:   rW   rS   r   r   r   r:     rU   zLocaleDataDict.copyr'   )rR   rX   rY   rZ   rO   r^   ra   re   rh   ri   r:   r   r   r   r   r[      s    
r[   )T) rZ   r   rer   	threading	itertoolsr   babel._compatr   r   r   r
   RLockr3   r   r   dirname__file__r   compileIr   r   r   r   r   r9   r<   objectrD   MutableMappingr[   r   r   r   r   <module>   s&   
7!!