ó
µ”ù\c           @   sà   d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z m Z i  Z	 e j
 ƒ  Z e j j e j j e ƒ d ƒ Z d „  Z d „  Z d „  Z e d	 „ Z d
 „  Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   sG  
    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-2019 by the Babel Team.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   chain(   t   picklet   string_typest   abcs   locale-datac         C   sj   |  s t  |  t ƒ r d S|  j ƒ  j ƒ  }  x6 t j t t ƒ  g ƒ D] } |  | j ƒ  k rF | SqF Wd S(   sŸ   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(	   t
   isinstanceR   t   Nonet   stript   lowerR    t   from_iterablet   _cachet   locale_identifiers(   t   namet	   locale_id(    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   normalize_locale   s    c         C   sj   |  s t  |  t ƒ r t S|  t k r+ t St j j t j j t	 d |  ƒ ƒ } | rZ t St
 t |  ƒ ƒ S(   s¥   Check whether locale data is available for the given locale.

    Returns `True` if it exists, `False` otherwise.

    :param name: the locale identifier string
    s   %s.dat(   R   R   t   FalseR	   t   Truet   ost   patht   existst   joint   _dirnamet   boolR   (   R   t
   file_found(    (    s/   lib/python2.7/site-packages/babel/localedata.pyR   )   s    %c          C   sv   t  t d d ƒ }  |  d k rr g  d „  t j t ƒ Dƒ D]* \ } } | d k r8 | d k r8 | ^ q8 t _ }  n  |  S(   s„  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)
    t   cachec         s   s!   |  ] } t  j j | ƒ Vq d  S(   N(   R   R   t   splitext(   t   .0t   filename(    (    s/   lib/python2.7/site-packages/babel/localedata.pys	   <genexpr>J   s    s   .datt   rootN(   t   getattrR
   R   R   t   listdirR   R   (   t   datat   stemt	   extension(    (    s/   lib/python2.7/site-packages/babel/localedata.pyR
   8   s    #.c         C   sJ  t  j ƒ  z.t j |  ƒ } | s3|  d k s5 | r> i  } n} d d l m } | d ƒ j |  ƒ } | s© |  j d ƒ } t | ƒ d k r“ d } q© d j | d  ƒ } n  t	 | ƒ j
 ƒ  } t j j t d |  ƒ } t | d ƒ A } |  d k r| rt | t j	 | ƒ ƒ n t j	 | ƒ } Wd	 QX| t |  <n  | SWd	 t  j ƒ  Xd	 S(
   se  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   iÿÿÿÿ(   t
   get_globalt   parent_exceptionst   _i   s   %s.datt   rbN(   t   _cache_lockt   acquireR	   t   gett
   babel.coreR!   t   splitt   lenR   t   loadt   copyR   R   R   t   opent   mergeR   t   release(   R   t   merge_inheritedR   R!   t   parentt   partsR   t   fileobj(    (    s/   lib/python2.7/site-packages/babel/localedata.pyR+   P   s,    
		c         C   sð   xé | j  ƒ  D]Û \ } } | d k	 r |  j | ƒ } t | t ƒ rÕ | d k rX i  } n  t | t ƒ rv | | f } qÛ t | t ƒ r¹ | \ } } | j ƒ  } t | | ƒ | | f } qÛ | j ƒ  } t | | ƒ n | } | |  | <q q Wd S(   sn  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(	   t   itemsR   R'   R   t   dictt   Aliast   tupleR,   R.   (   t   dict1t   dict2t   keyt   val2t   val1t   aliast   others(    (    s/   lib/python2.7/site-packages/babel/localedata.pyR.   †   s"    	R6   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sŸ   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`.
    c         C   s   t  | ƒ |  _ d  S(   N(   R7   t   keys(   t   selfR?   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __init__®   s    c         C   s   d t  |  ƒ j |  j f S(   Ns   <%s %r>(   t   typet   __name__R?   (   R@   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __repr__±   s    c         C   sv   | } x |  j  D] } | | } q Wt | t ƒ rE | j | ƒ } n- t | t ƒ rr | \ } } | j | ƒ } n  | S(   sô   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   R6   t   resolveR7   (   R@   R   t   baseR:   R=   R>   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyRE   ´   s    	(   RC   t
   __module__t   __doc__RA   RD   RE   (    (    (    s/   lib/python2.7/site-packages/babel/localedata.pyR6   §   s   		t   LocaleDataDictc           B   sP   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sU   Dictionary wrapper that automatically resolves aliases to the actual
    values.
    c         C   s+   | |  _  | d  k r | } n  | |  _ d  S(   N(   t   _dataR   RF   (   R@   R   RF   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyRA   Í   s    		c         C   s   t  |  j ƒ S(   N(   R*   RJ   (   R@   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __len__Ó   s    c         C   s   t  |  j ƒ S(   N(   t   iterRJ   (   R@   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __iter__Ö   s    c         C   sÂ   |  j  | } } t | t ƒ r5 | j |  j ƒ } n  t | t ƒ rx | \ } } | j |  j ƒ j ƒ  } t | | ƒ n  t | ƒ t	 k r¢ t
 | d |  j ƒ} n  | | k	 r¾ | |  j  | <n  | S(   NRF   (   RJ   R   R6   RE   RF   R7   R,   R.   RB   R5   RI   (   R@   R:   t   origt   valR=   R>   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __getitem__Ù   s    c         C   s   | |  j  | <d  S(   N(   RJ   (   R@   R:   t   value(    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __setitem__ç   s    c         C   s   |  j  | =d  S(   N(   RJ   (   R@   R:   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   __delitem__ê   s    c         C   s   t  |  j j ƒ  d |  j ƒS(   NRF   (   RI   RJ   R,   RF   (   R@   (    (    s/   lib/python2.7/site-packages/babel/localedata.pyR,   í   s    N(   RC   RG   RH   R   RA   RK   RM   RP   RR   RS   R,   (    (    (    s/   lib/python2.7/site-packages/babel/localedata.pyRI   È   s   					(   RH   R   t	   threadingt	   itertoolsR    t   babel._compatR   R   R   R	   t   RLockR%   R   R   t   dirnamet   __file__R   R   R   R
   R   R+   R.   t   objectR6   t   MutableMappingRI   (    (    (    s/   lib/python2.7/site-packages/babel/localedata.pyt   <module>   s   !			6	!!