o
    mi#                     @  s,  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Z d/ddZ!d0ddZ"eddd1ddZ#d0ddZ$d2d3d!d"Z%d4d(d)Z&G d*d+ d+Z'G d,d- d-e	jZ(dS )5a+  
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-2026 by the Babel Team.
:license: BSD, see LICENSE for more details.
    )annotationsN)abc)IteratorMappingMutableMapping)	lru_cache)chain)Anydict[str, Any]_cachezlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$namestrreturn
str | Nonec                 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   J/home/kim/smarthome/.venv/lib/python3.10/site-packages/babel/localedata.pynormalize_locale!   s   r   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| }|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&   r'   r   )r   Z
file_foundr   r   r   r(   ?   s   r(   )maxsize	list[str]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  sz   ddl m}m} z|| ^}}}}}W n
 ty   Y dS w |r;|r;|s;|s;|s;|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.corer4   r5   r#   get)r   r4   r5   lang	territoryscriptvariantrestZlikely_subtag_Zlikely_scriptr   r   r   _is_non_likely_scriptc   s   r>   Tmerge_inheritedc                 C  s  t j| } t  zzt| }|s~| dks|si }n2ddlm} |d| }|sGt	| r1d}n| 
d}t|dkr>dnd|dd }t| }t| }t|d	}| dkrf|rft|t| nt|}W d   n1 suw   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']
    '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   )r4   Zparent_exceptionsr=      Nrb)r   r   r   _cache_lockacquirer   r7   r6   r4   r>   splitlenr$   loadcopyr&   openmergepicklerelease)r   r?   datar4   parentpartsr1   fileobjr   r   r   rG   x   s2   

"
rG   dict1MutableMapping[Any, Any]dict2Mapping[Any, Any]Nonec                 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)itemsr7   r   dictAliastuplerH   rJ   )rQ   rS   keyZval2Zval1aliasothersr   r   r   rJ      s&   






rJ   c                   @  s.   e Zd ZdZdddZdd	d
ZdddZdS )rX   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`.
    keystuple[str, ...]r   rU   c                 C  s   t || _d S r0   )rY   r]   )selfr]   r   r   r   __init__      zAlias.__init__r   c                 C  s   dt | j d| jdS )N< >)type__name__r]   r_   r   r   r   __repr__   s   zAlias.__repr__rM   Mapping[str | int | None, Any]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`
        )r]   r   rX   resolverY   )r_   rM   baserZ   r[   r\   r   r   r   rj      s   	





zAlias.resolveN)r]   r^   r   rU   )r   r   )rM   ri   r   ri   )rf   
__module____qualname____doc__r`   rh   rj   r   r   r   r   rX      s
    

rX   c                   @  sZ   e Zd ZdZ	ddddZdddZd ddZd!ddZd"ddZd#ddZ	d$ddZ
dS )%LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual
    values.
    NrM   %MutableMapping[str | int | None, Any]rk   %Mapping[str | int | None, Any] | Nonec                 C  s   || _ |d u r	|}|| _d S r0   )_datark   )r_   rM   rk   r   r   r   r`      s   
zLocaleDataDict.__init__r   intc                 C  
   t | jS r0   )rF   rr   rg   r   r   r   __len__     
zLocaleDataDict.__len__Iterator[str | int | None]c                 C  rt   r0   )iterrr   rg   r   r   r   __iter__  rv   zLocaleDataDict.__iter__rZ   str | int | Noner	   c                 C  s~   | j |  }}t|tr|| j}t|tr(|\}}|| j }t|| t|tr4t	|| jd}||ur=|| j |< |S N)rk   )
rr   r   rX   rj   rk   rY   rH   rJ   rW   ro   )r_   rZ   origvalr[   r\   r   r   r   __getitem__  s   




zLocaleDataDict.__getitem__valuerU   c                 C  s   || j |< d S r0   rr   )r_   rZ   r   r   r   r   __setitem__  ra   zLocaleDataDict.__setitem__c                 C  s   | j |= d S r0   r   )r_   rZ   r   r   r   __delitem__  s   zLocaleDataDict.__delitem__c                 C  s   t | j | jdS r{   )ro   rr   rH   rk   rg   r   r   r   rH     s   zLocaleDataDict.copyr0   )rM   rp   rk   rq   )r   rs   )r   rw   )rZ   rz   r   r	   )rZ   rz   r   r	   r   rU   )rZ   rz   r   rU   )r   ro   )rf   rl   rm   rn   r`   ru   ry   r~   r   r   rH   r   r   r   r   ro      s    





ro   )r   r   r   r   )r   r   r   r   )r   r   r   r'   )r   r*   )T)r   r   r?   r'   r   r
   )rQ   rR   rS   rT   r   rU   ))rn   
__future__r   r   rK   rer   	threadingcollectionsr   collections.abcr   r   r   	functoolsr   	itertoolsr   typingr	   r   __annotations__RLockrC   r   r$   dirname__file__r%   compileIr    r   r&   r(   r   r>   rG   rJ   rX   ro   r   r   r   r   <module>   s4    




8!!