
    ƪb                     v   d 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	 i Z
 ej                         Zej                  j                  ej                  j                  e      d      Z ej$                  dej&                        Zd Zd Zd	 Zd
 ZddZd Z G d d      Z G d dej8                        Zy)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-2022 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    N)abc)chainzlocale-dataz%^(con|prn|aux|nul|com[0-9]|lpt[0-9])$c                     | rt        | t              sy| j                         j                         } t	        j
                  t        t               g      D ]  }| |j                         k(  s|c S  y)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)
isinstancestrstriplowerr   from_iterable_cachelocale_identifiers)name	locale_ids     2/usr/lib/python3/dist-packages/babel/localedata.pynormalize_localer      s_     z$,::<D((&2D2F)GH 	9??$$    c                 :   t         j                  j                  |       } t        j                  dk(  rCt
        j                  t         j                  j                  |       d         rt        d| z        t         j                  j                  t        d| z        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   s    r   resolve_locale_filenamer   +   sv     77D!D ||w#<#B#B277CSCSTXCYZ[C\#]84?@@ 77<<(T/22r   c                     | rt        | t              sy| t        v ryt        j                  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_founds     r   r!   r!   ;   sM     z$,v~ 7 =>J4?4(8(>#??r   c                      t        t        dd      } | Hd t        j                  t              D        D cg c]  \  }}|dk(  r|dk7  r| c}}xt        _        } | S c c}}w )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              3   Z   K   | ]#  }t         j                  j                  |       % y wN)r   r   r   ).0filenames     r   	<genexpr>z%locale_identifiers.<locals>.<genexpr>\   s     MHRWWh'Ms   )+z.datroot)getattrr   r   listdirr   r%   )datastem	extensions      r   r   r   J   sj     %w5D| N

88LM+
iF"tv~ +
 	
 4 K+
s   Ac                    t         j                  j                  |       } t        j	                          	 t
        j                  |       }|s| dk(  s|si }nnddlm}  |d      j                  |       }|s6| j                  d      }t        |      dk(  rd}ndj                  |dd       }t        |      j                         }t        |       }t        |d	      5 }| dk7  r"|r t!        |t#        j                  |             nt#        j                  |      }ddd       |t
        | <   |t        j%                          S # 1 sw Y   (xY w# t        j%                          w xY 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.corer2   splitlenr   loadcopyr   openmergepicklerelease)r   merge_inheritedr.   r2   parentpartsr)   fileobjs           r   r>   r>   b   s%   2 77D!Dzz$v~_1#$78<<TB JJsOE5zQ!'!$%*!5F|((*.t4Hh% 06>o$G 45!;;w/D	0
  F4L0 0 	s$   B&E =D?E ?EE E!c                 b   |j                         D ]  \  }}|	| j                  |      }t        |t              rl|i }t        |t              r||f}nUt        |t
              r&|\  }}|j                         }t        ||       ||f}n|j                         }t        ||       n|}|| |<    y)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?   rA   )dict1dict2keyval2val1aliasotherss          r   rA   rA      s     [[] 	T99S>D$%<DdE* $<De,$(ME6#[[]F&$'!6?D99;D$%E#J%r   c                   "    e Zd ZdZd Zd Zd Zy)rK   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                 $    t        |      | _        y r'   )rL   keys)selfrV   s     r   __init__zAlias.__init__   s    $K	r   c                 N    dt        |       j                  d| j                  dS )N< >)type__name__rV   rW   s    r   __repr__zAlias.__repr__   s     J//;;r   c                     |}| j                   D ]  }||   }	 t        |t              r|j                  |      }|S t        |t              r|\  }}|j                  |      }|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`
        )rV   r   rK   resolverL   )rW   r.   baserO   rR   rS   s         r   rb   zAlias.resolve   sl     99 	C9D	dE"<<%D  e$ ME6==&Dr   N)r^   
__module____qualname____doc__rX   r`   rb    r   r   rK   rK      s     <r   rK   c                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	 Z
y)LocaleDataDictzUDictionary wrapper that automatically resolves aliases to the actual
    values.
    Nc                 (    || _         ||}|| _        y r'   )_datarc   )rW   r.   rc   s      r   rX   zLocaleDataDict.__init__   s    
<D	r   c                 ,    t        | j                        S r'   )r=   rk   r_   s    r   __len__zLocaleDataDict.__len__   s    4::r   c                 ,    t        | j                        S r'   )iterrk   r_   s    r   __iter__zLocaleDataDict.__iter__   s    DJJr   c                    | j                   |   x}}t        |t              r|j                  | j                        }t        |t
              r:|\  }}|j                  | j                        j                         }t        ||       t        |      t        u rt        || j                        }||ur|| j                   |<   |S N)rc   )rk   r   rK   rb   rc   rL   r?   rA   r]   rJ   ri   )rW   rO   origvalrR   rS   s         r   __getitem__zLocaleDataDict.__getitem__   s    ZZ_$sc5!++dii(Cc5!ME6--		*//1C#v9 4995Cd?!DJJsO
r   c                 "    || j                   |<   y r'   rk   )rW   rO   values      r   __setitem__zLocaleDataDict.__setitem__   s    

3r   c                     | j                   |= y r'   rw   )rW   rO   s     r   __delitem__zLocaleDataDict.__delitem__   s    JJsOr   c                 `    t        | j                  j                         | j                        S rr   )ri   rk   r?   rc   r_   s    r   r?   zLocaleDataDict.copy   s    djjoo/dii@@r   r'   )r^   rd   re   rf   rX   rm   rp   ru   ry   r{   r?   rg   r   r   ri   ri      s+      Ar   ri   )T)rf   rB   r   rer   	threadingcollectionsr   	itertoolsr   r   RLockr8   r   r   dirname__file__r   compileIr   r   r   r!   r   r>   rA   rK   MutableMappingri   rg   r   r   <module>r      s     	 	 
    
ioo77<<1=A&BJJ'NPRPTPTU 3 @04nB B&AS'' &Ar   