ó
™‚Mc           @   s   d  Z  d d l Z d d l Z y d d l Z Wn e k
 rM d d l Z n Xd d l m Z d d d g Z d Z	 i  Z
 e j ƒ  Z e j j e j j e ƒ d ƒ Z d	 „  Z d
 „  Z e d „ Z d „  Z d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   s¬   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.
iÿÿÿÿN(   t	   DictMixint   existst   listt   loads   restructuredtext ent
   localedatac         C   s3   |  t  k r t St j j t j j t d |  ƒ ƒ S(   sÈ   Check whether locale data is available for the given locale.
    
    :param name: the locale identifier string
    :return: `True` if the locale data exists, `False` otherwise
    :rtype: `bool`
    s   %s.dat(   t   _cachet   Truet   ost   pathR   t   joint   _dirname(   t   name(    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR   $   s    c          C   s]   g  g  t  j t ƒ D] }  t  j j |  ƒ ^ q D]* \ } } | d k r/ | d k r/ | ^ q/ S(   sº   Return a list of all locale identifiers for which locale data is
    available.
    
    :return: a list of locale identifiers (strings)
    :rtype: `list`
    :since: version 0.8.1
    s   .datt   root(   R   t   listdirR
   R   t   splitext(   t   filenamet   stemt	   extension(    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR   0   s    8c         C   s%  t  j ƒ  z	t j |  ƒ } | s|  d k s5 | r> i  } nO |  j d ƒ } t | ƒ d k rh d } n d j | d  ƒ } t | ƒ j ƒ  } t	 j
 j t d |  ƒ } t | d ƒ } zH |  d k rã | rã t | t j | ƒ ƒ n t j | ƒ } | t |  <Wd | j ƒ  Xn  | SWd t  j ƒ  Xd S(   s©  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
    :return: the locale data
    :rtype: `dict`
    :raise `IOError`: if no locale data file is found for the given locale
                      identifer, or one of the locales it inherits from
    R   t   _i   iÿÿÿÿs   %s.datt   rbN(   t   _cache_lockt   acquireR   t   gett   splitt   lenR	   R   t   copyR   R   R
   t   opent   merget   picklet   closet   release(   R   t   merge_inheritedt   datat   partst   parentR   t   fileobj(    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR   =   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(   s‹  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'})
    >>> items = d.items(); items.sort(); 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   itemst   NoneR   t
   isinstancet   dictt   Aliast   tupleR   R   (   t   dict1t   dict2t   keyt   val2t   val1t   aliast   others(    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR   u   s"    	R(   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(   R)   t   keys(   t   selfR1   (    (    s4   /usr/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__R1   (   R2   (    (    s4   /usr/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`
        (   R1   R&   R(   t   resolveR)   (   R2   R    t   baseR,   R/   R0   (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR7   £   s    	(   R5   t
   __module__t   __doc__R3   R6   R7   (    (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR(   –   s   		t   LocaleDataDictc           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   sU   Dictionary wrapper that automatically resolves aliases to the actual
    values.
    c         C   s2   t  j |  | ƒ | d  k r% | } n  | |  _ d  S(   N(   R'   R3   R%   R8   (   R2   R    R8   (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR3   ¼   s    	c         C   sÄ   t  j |  | ƒ } } t | t ƒ r: | j |  j ƒ } n  t | t ƒ r} | \ } } | j |  j ƒ j ƒ  } t | | ƒ n  t	 | ƒ t  k r§ t
 | d |  j ƒ} n  | | k	 rÀ | |  | <n  | S(   NR8   (   R'   t   __getitem__R&   R(   R7   R8   R)   R   R   R4   R;   (   R2   R,   t   origt   valR/   R0   (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR<   Â   s    c         C   s   t  t j |  ƒ d |  j ƒS(   NR8   (   R;   R'   R   R8   (   R2   (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR   Ð   s    N(   R5   R9   R:   R%   R3   R<   R   (    (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyR;   ·   s   	(   R:   R   R   t	   threadingt   ImportErrort   dummy_threadingt   UserDictR    t   __all__t   __docformat__R   t   RLockR   R   R	   t   dirnamet   __file__R
   R   R   R   R   R   t   objectR(   R'   R;   (    (    (    s4   /usr/lib/python2.7/site-packages/babel/localedata.pyt   <module>   s$   !		8	!!