a
    ÷£Be/   ã                   @  sH  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œ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-2023 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 )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_iterabler
   Úlocale_identifiers)r   Z	locale_id© r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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v rdS tj t| ƒ¡}|r6d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)	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>]   ó    z%locale_identifiers.<locals>.<genexpr>)r   Úlistdirr"   r   r   r   r   r   N   s    ýr   T)r   Úmerge_inheritedr   c                 C  s
  t j | ¡} t ¡  zæt | ¡}|sî| dks0|s6i }nVddlm} |dƒ | ¡}|s€|  	d¡}t
|ƒdkrndnd |dd… ¡}t|ƒ ¡ }t| ƒ}t|d	ƒ�8}| dkr¾|r¾t|t |¡ƒ n
t |¡}W d  ƒ n1 sÜ0    Y  |t| < |W t ¡  S t ¡  0 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   )Ú
get_globalZparent_exceptionsÚ_é   NéÿÿÿÿÚrb)r   r   r   Ú_cache_lockÚacquirer
   ÚgetZ
babel.corer3   ÚsplitÚlenr!   ÚloadÚcopyr#   ÚopenÚmergeÚpickleÚrelease)r   r2   Údatar3   ÚparentÚpartsr.   Úfileobjr   r   r   r=   b   s.    

"(þr=   zMutableMapping[Any, Any]zMapping[Any, Any]ÚNone)Údict1Údict2r   c                 C  s    |  ¡ D ]’\}}|dur|  |¡}t|tƒrŽ|du r8i }t|tƒrL||f}q’t|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)Úitemsr:   r   ÚdictÚAliasÚtupler>   r@   )rH   rI   ÚkeyZval2Zval1ÚaliasÚothersr   r   r   r@   –   s"    






r@   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 )rL   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`.
    ztuple[str, ...]rG   )Úkeysr   c                 C  s   t |ƒ| _d S r-   )rM   rQ   )ÚselfrQ   r   r   r   Ú__init__¾   s    zAlias.__init__r   r'   c                 C  s   dt | ƒj› d| j›d�S )Nú<ú ú>)ÚtypeÚ__name__rQ   ©rR   r   r   r   Ú__repr__Á   s    zAlias.__repr__zMapping[str | int | None, Any])rC   r   c                 C  sN   |}| j D ]}|| }q
t|tƒr.| |¡}nt|tƒrJ|\}}| |¡}|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`
        )rQ   r   rL   ÚresolverM   )rR   rC   ÚbaserN   rO   rP   r   r   r   r[   Ä   s    	




zAlias.resolveN)rX   Ú
__module__Ú__qualname__Ú__doc__rS   rZ   r[   r   r   r   r   rL   ·   s   rL   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)rC   r\   c                 C  s   || _ |d u r|}|| _d S r-   )Ú_datar\   )rR   rC   r\   r   r   r   rS   Ý   s    zLocaleDataDict.__init__Úintr'   c                 C  s
   t | jƒS r-   )r<   ra   rY   r   r   r   Ú__len__ã   s    zLocaleDataDict.__len__zIterator[str | int | None]c                 C  s
   t | jƒS r-   )Úiterra   rY   r   r   r   Ú__iter__æ   s    zLocaleDataDict.__iter__zstr | int | Noner	   )rN   r   c                 C  s~   | j |  }}t|tƒr$| | j¡}t|tƒrP|\}}| | j¡ ¡ }t||ƒ t|tƒrht	|| jd�}||urz|| j |< |S ©N)r\   )
ra   r   rL   r[   r\   rM   r>   r@   rK   r`   )rR   rN   ÚorigÚvalrO   rP   r   r   r   Ú__getitem__é   s    




zLocaleDataDict.__getitem__rG   )rN   Úvaluer   c                 C  s   || j |< d S r-   ©ra   )rR   rN   rj   r   r   r   Ú__setitem__÷   s    zLocaleDataDict.__setitem__c                 C  s   | j |= d S r-   rk   )rR   rN   r   r   r   Ú__delitem__ú   s    zLocaleDataDict.__delitem__c                 C  s   t | j ¡ | jd�S rf   )r`   ra   r>   r\   rY   r   r   r   r>   ý   s    zLocaleDataDict.copy)N)rX   r]   r^   r_   rS   rc   re   ri   rl   rm   r>   r   r   r   r   r`   Ø   s   r`   )T)(r_   Ú
__future__r   r   rA   Úrer   Ú	threadingÚcollectionsr   Úcollections.abcr   r   r   Ú	functoolsr   Ú	itertoolsr   Útypingr	   r
   Ú__annotations__ÚRLockr8   r   r!   ÚdirnameÚ__file__r"   ÚcompileÚIr   r   r#   r%   r   r=   r@   rL   r`   r   r   r   r   Ú<module>   s0   4!!