U
    [Sh#                     @  sX  U d Z ddlmZ ddl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 ddlmZ ddlmZ ddlmZ i Zd	ed
< e ZejejedZedejZdddddZ dddddZ!dddddZ"eddddddZ#dddddZ$d-ddd	d d!d"Z%d#d$d%d&d'd(Z&G d)d* d*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-2025 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    )annotationsN)abc)IteratorMappingMutableMapping)	lru_cache)chain)Anyzdict[str, Any]_cachezlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$strz
str | None)namereturnc                 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_iterabler
   locale_identifiers)r   Z	locale_id r   C/root/rtd-docs/venv/lib/python3.8/site-packages/babel/localedata.pynormalize_locale!   s    r   zos.PathLike[str] | strc                 C  sP   t j| } tjdkr<tt j| d r<td|  dt j	t
|  dS )z?
    Resolve a locale identifier to a `.dat` path on disk.
    win32r   zName z is invalid on Windows.dat)ospathbasenamesysplatform_windows_reserved_name_rematchsplitext
ValueErrorjoin_dirname)r   r   r   r   resolve_locale_filename/   s     r#   boolc                 C  sB   | rt | tsdS | tkrdS tjt| }|r6d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#   r$   r   )r   Z
file_foundr   r   r   r%   ?   s    r%   )maxsizez	list[str]r   c                   C  s   dd dd t tD D S )a&  Return a list of all locale identifiers for which locale data is
    available.

    This data is cached after the first invocation.
    You can clear the cache by calling `locale_identifiers.cache_clear()`.

    .. versionadded:: 0.8.1

    :return: a list of locale identifiers (strings)
    c                 S  s$   g | ]\}}|d kr|dkr|qS )r   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>)r   listdirr"   r   r   r   r   r   N   s    r   c                 C  s|   ddl m}m} z|| ^}}}}}W n tk
r<   Y dS X |rx|rx|sx|sx|sx|d|}||^}	}	}
}	||
kS dS )a  Return whether the locale is of the form ``lang_Script``,
    and the script is not the likely script for the language.

    This implements the behavior of the ``nonlikelyScript`` value of the
    ``localRules`` attribute for parent locales added in CLDR 45.
    r   )
get_globalparse_localeFZlikely_subtags)
babel.corer1   r2   r    get)r   r1   r2   lang	territoryscriptvariantrestZlikely_subtag_Zlikely_scriptr   r   r   _is_non_likely_scriptb   s    r;   T)r   merge_inheritedr   c              	   C  s   t j| } t  zt| }|s| dks0|s6i }ndddlm	} |d| }|st
| rbd}n,| d}t|dkr|dnd|dd }t| }t| }t|d	.}| dkr|rt|t| n
t|}W 5 Q R X |t| < |W S t  X dS )
af  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
                      identifier, or one of the locales it inherits from
    r(   r   )r1   Zparent_exceptionsr:      Nrb)r   r   r   _cache_lockacquirereleaser
   r4   r3   r1   r;   splitlenr!   loadcopyr#   openmergepickle)r   r<   datar1   parentpartsr.   fileobjr   r   r   rE   w   s.    

"rE   zMutableMapping[Any, Any]zMapping[Any, Any]None)dict1dict2r   c                 C  s   |  D ]\}}|dk	r| |}t|tr|dkr8i }t|trL||f}qt|trz|\}}| }t|| ||f}q| }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)itemsr4   r   dictAliastuplerF   rH   )rO   rP   keyZval2Zval1aliasothersr   r   r   rH      s"    






rH   c                   @  s>   e Zd ZdZdddddZddd	d
ZdddddZdS )rS   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`.
    ztuple[str, ...]rN   )keysr   c                 C  s   t || _d S r-   )rT   rX   )selfrX   r   r   r   __init__   s    zAlias.__init__r   r'   c                 C  s   dt | j d| jdS )N< >)type__name__rX   rY   r   r   r   __repr__   s    zAlias.__repr__zMapping[str | int | None, Any])rJ   r   c                 C  sN   |}| j D ]}|| }q
t|tr.||}nt|trJ|\}}||}|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`
        )rX   r   rS   resolverT   )rY   rJ   baserU   rV   rW   r   r   r   rb      s    	




zAlias.resolveN)r_   
__module____qualname____doc__rZ   ra   rb   r   r   r   r   rS      s   rS   c                   @  s~   e Zd ZdZddddddZdd	d
dZdd	ddZdddddZddddddZdddddZ	d d	ddZ
dS )LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual
    values.
    Nz%MutableMapping[str | int | None, Any]z%Mapping[str | int | None, Any] | None)rJ   rc   c                 C  s   || _ |d kr|}|| _d S r-   )_datarc   )rY   rJ   rc   r   r   r   rZ      s    zLocaleDataDict.__init__intr'   c                 C  s
   t | jS r-   )rD   rh   r`   r   r   r   __len__   s    zLocaleDataDict.__len__zIterator[str | int | None]c                 C  s
   t | jS r-   )iterrh   r`   r   r   r   __iter__   s    zLocaleDataDict.__iter__zstr | int | Noner	   )rU   r   c                 C  s~   | j |  }}t|tr$|| j}t|trP|\}}|| j }t|| t|trht	|| jd}||k	rz|| j |< |S N)rc   )
rh   r   rS   rb   rc   rT   rF   rH   rR   rg   )rY   rU   origvalrV   rW   r   r   r   __getitem__  s    




zLocaleDataDict.__getitem__rN   )rU   valuer   c                 C  s   || j |< d S r-   rh   )rY   rU   rq   r   r   r   __setitem__  s    zLocaleDataDict.__setitem__c                 C  s   | j |= d S r-   rr   )rY   rU   r   r   r   __delitem__  s    zLocaleDataDict.__delitem__c                 C  s   t | j | jdS rm   )rg   rh   rF   rc   r`   r   r   r   rF     s    zLocaleDataDict.copy)N)r_   rd   re   rf   rZ   rj   rl   rp   rs   rt   rF   r   r   r   r   rg      s   rg   )T))rf   
__future__r   r   rI   rer   	threadingcollectionsr   collections.abcr   r   r   	functoolsr   	itertoolsr   typingr	   r
   __annotations__RLockr@   r   r!   dirname__file__r"   compileIr   r   r#   r%   r   r;   rE   rH   rS   rg   r   r   r   r   <module>   s2   7!!