a
    ¦Q•hœ#  ã                   @  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-2024 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   úI/var/www/sistema_ama/venv/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   c                 C  sz   ddl m}m} z|| ƒ^}}}}}W n ty:   Y dS 0 |rv|rv|sv|sv|sv|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_localeFÚlikely_subtags)Ú
babel.corer2   r3   r    Úget)r   r2   r3   ÚlangÚ	territoryÚscriptÚvariantÚrestÚlikely_subtagÚ_Zlikely_scriptr   r   r   Ú_is_non_likely_scriptb   s    r>   T)r   Úmerge_inheritedr   c                 C  s  t j | ¡} t ¡  � zôt | ¡}|sþ| dks2|s8i }ndddlm} |dƒ | ¡}|s�t	| ƒrdd}n,|  
d¡}t|ƒdkr~d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   )r2   Úparent_exceptionsr=   é   NéÿÿÿÿÚrb)r   r   r   Ú_cache_lockÚacquirer
   r6   r5   r2   r>   ÚsplitÚlenr!   ÚloadÚcopyr#   ÚopenÚmergeÚpickleÚrelease)r   r?   Údatar2   ÚparentÚpartsr.   Úfileobjr   r   r   rH   w   s2    

"(þrH   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)Úitemsr6   r   ÚdictÚAliasÚtuplerI   rK   )rS   rT   ÚkeyÚval2Úval1ÚaliasÚothersr   r   r   rK   ®   s"    






rK   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 )rW   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, ...]rR   )Úkeysr   c                 C  s   t |ƒ| _d S r-   )rX   r^   )Úselfr^   r   r   r   Ú__init__Ö   s    zAlias.__init__r   r'   c                 C  s   dt | ƒj› d| j›d�S )Nú<ú ú>)ÚtypeÚ__name__r^   ©r_   r   r   r   Ú__repr__Ù   s    zAlias.__repr__zMapping[str | int | None, Any])rN   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`
        )r^   r   rW   ÚresolverX   )r_   rN   ÚbaserY   r\   r]   r   r   r   rh   Ü   s    	




zAlias.resolveN)re   Ú
__module__Ú__qualname__Ú__doc__r`   rg   rh   r   r   r   r   rW   Ï   s   rW   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)rN   ri   c                 C  s   || _ |d u r|}|| _d S r-   )Ú_datari   )r_   rN   ri   r   r   r   r`   õ   s    zLocaleDataDict.__init__Úintr'   c                 C  s
   t | jƒS r-   )rG   rn   rf   r   r   r   Ú__len__û   s    zLocaleDataDict.__len__zIterator[str | int | None]c                 C  s
   t | jƒS r-   )Úiterrn   rf   r   r   r   Ú__iter__þ   s    zLocaleDataDict.__iter__zstr | int | Noner	   )rY   r   c                 C  s~   | j |  }}t|tƒr$| | j¡}t|tƒrP|\}}| | j¡ ¡ }t||ƒ t|tƒrht	|| jd�}||urz|| j |< |S ©N)ri   )
rn   r   rW   rh   ri   rX   rI   rK   rV   rm   )r_   rY   ÚorigÚvalr\   r]   r   r   r   Ú__getitem__  s    




zLocaleDataDict.__getitem__rR   )rY   Úvaluer   c                 C  s   || j |< d S r-   ©rn   )r_   rY   rw   r   r   r   Ú__setitem__  s    zLocaleDataDict.__setitem__c                 C  s   | j |= d S r-   rx   )r_   rY   r   r   r   Ú__delitem__  s    zLocaleDataDict.__delitem__c                 C  s   t | j ¡ | jd�S rs   )rm   rn   rI   ri   rf   r   r   r   rI     s    zLocaleDataDict.copy)N)re   rj   rk   rl   r`   rp   rr   rv   ry   rz   rI   r   r   r   r   rm   ð   s   rm   )T))rl   Ú
__future__r   r   rL   Úrer   Ú	threadingÚcollectionsr   Úcollections.abcr   r   r   Ú	functoolsr   Ú	itertoolsr   Útypingr	   r
   Ú__annotations__ÚRLockrD   r   r!   ÚdirnameÚ__file__r"   ÚcompileÚIr   r   r#   r%   r   r>   rH   rK   rW   rm   r   r   r   r   Ú<module>   s2   7!!