
Mc           @   s  d  Z  d d l Z d d l Z d d l m Z d d d d d g Z d	 Z e a d
   Z	 i' d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6dC dD 6dE dF 6dG dH 6dI dJ 6dK dL 6dM dN 6dO dP 6dQ dR 6dS dT 6dU dV 6dW dX 6Z
 d e f dY     YZ d e f dZ     YZ e e
 d[  Z d\ e
 d]  Z d\ d^  Z d S(_   s2   Core locale representation and locale data access.iN(   t
   localedatat   UnknownLocaleErrort   Localet   default_localet   negotiate_localet   parse_locales   restructuredtext enc         C   s   t  d k rr t j j t j j t   } t j j | d  } t | d  } z t j	 |  a  Wd | j
   Xn  t  j |  i   S(   s  Return the dictionary for the given key in the global data.
    
    The global data is stored in the ``babel/global.dat`` file and contains
    information independent of individual locales.
    
    >>> get_global('zone_aliases')['UTC']
    'Etc/GMT'
    >>> get_global('zone_territories')['Europe/Berlin']
    'DE'
    
    :param key: the data key
    :return: the dictionary found in the global data under the given key
    :rtype: `dict`
    :since: version 0.9
    s
   global.datt   rbN(   t   _global_datat   Nonet   ost   patht   joint   dirnamet   __file__t   opent   picklet   loadt   closet   get(   t   keyR   t   filenamet   fileobj(    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt
   get_global   s    t   ar_SYt   art   bg_BGt   bgt   bs_BAt   bst   ca_ESt   cat   cs_CZt   cst   da_DKt   dat   de_DEt   det   el_GRt   elt   en_USt   ent   es_ESt   est   et_EEt   ett   fa_IRt   fat   fi_FIt   fit   fr_FRt   frt   gl_ESt   glt   he_ILt   het   hu_HUt   hut   id_IDt   idt   is_ISt   ist   it_ITt   itt   ja_JPt   jat   km_KHt   kmt   ko_KRt   kot   lt_LTt   ltt   lv_LVt   lvt   mk_MKt   mkt   nl_NLt   nlt   nn_NOt   nnt   nb_NOt   not   pl_PLt   plt   pt_PTt   ptt   ro_ROt   rot   ru_RUt   rut   sk_SKt   skt   sl_SIt   slt   sv_SEt   svt   th_THt   tht   tr_TRt   trt   uk_UAt   ukc           B   s   e  Z d  Z d   Z RS(   s[   Exception thrown when a locale is requested for which no locale data
    is available.
    c         C   s!   t  j |  d |  | |  _ d S(   sr   Create the exception.
        
        :param identifier: the identifier string of the unsupported locale
        s   unknown locale %rN(   t	   Exceptiont   __init__t
   identifier(   t   selfRg   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyRf   H   s    (   t   __name__t
   __module__t   __doc__Rf   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   C   s   c           B   s  e  Z d  Z dD dD dD d  Z dD e d  Z e e  Z d e d  Z e e  Z d d  Z	 e e	  Z	 d   Z
 d   Z d   Z d	   Z d
   Z e e  Z dD d  Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d   Z e e d d Z d    Z e e d d! Z d"   Z e e d d# Z d$   Z e e d d% Z d&   Z e e d d' Z d(   Z e e d d) Z d*   Z  e e  d d+ Z  d,   Z! e e! d d- Z! d.   Z" e e" d d/ Z" d0   Z# e e# d d1 Z# d2   Z$ e e$ d d3 Z$ d4   Z% e e% d d5 Z% d6   Z& e e& d d7 Z& d8   Z' e e' d d9 Z' d:   Z( e e( d d; Z( d<   Z) e e) d d= Z) d>   Z* e e* d d? Z* d@   Z+ e e+ d dA Z+ dB   Z, e e, d dC Z, RS(E   sx  Representation of a specific locale.
    
    >>> locale = Locale('en', 'US')
    >>> repr(locale)
    '<Locale "en_US">'
    >>> locale.display_name
    u'English (United States)'
    
    A `Locale` object can also be instantiated from a raw locale string:
    
    >>> locale = Locale.parse('en-US', sep='-')
    >>> repr(locale)
    '<Locale "en_US">'
    
    `Locale` objects provide access to a collection of locale data, such as
    territory and language names, number and date format patterns, and more:
    
    >>> locale.number_symbols['decimal']
    u'.'
    
    If a locale is requested for which no locale data is available, an
    `UnknownLocaleError` is raised:
    
    >>> Locale.parse('en_DE')
    Traceback (most recent call last):
        ...
    UnknownLocaleError: unknown locale 'en_DE'
    
    :see: `IETF RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>`_
    c         C   s[   | |  _  | |  _ | |  _ | |  _ d |  _ t |   } t j |  sW t	 |   n  d S(   s  Initialize the locale object from the given identifier components.
        
        >>> locale = Locale('en', 'US')
        >>> locale.language
        'en'
        >>> locale.territory
        'US'
        
        :param language: the language code
        :param territory: the territory (country or region) code
        :param script: the script code
        :param variant: the variant code
        :raise `UnknownLocaleError`: if no locale data is available for the
                                     requested locale
        N(
   t   languaget	   territoryt   scriptt   variantR   t   _Locale__datat   strR    t   existsR   (   Rh   Rl   Rm   Rn   Ro   Rg   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyRf   q   s    					c         C   s   |  t  | d |  S(   sx  Return the system default locale for the specified category.
        
        >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE']:
        ...     os.environ[name] = ''
        >>> os.environ['LANG'] = 'fr_FR.UTF-8'
        >>> Locale.default('LC_MESSAGES')
        <Locale "fr_FR">

        :param category: one of the ``LC_XXX`` environment variable names
        :param aliases: a dictionary of aliases for locale identifiers
        :return: the value of the variable, or any of the fallbacks
                 (``LANGUAGE``, ``LC_ALL``, ``LC_CTYPE``, and ``LANG``)
        :rtype: `Locale`
        :see: `default_locale`
        t   aliases(   R   (   t   clst   categoryRs   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   default   s    t   _c         C   s8   t  | | d | d | } | r4 t j | d | Sd S(   s	  Find the best match between available and requested locale strings.
        
        >>> Locale.negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
        <Locale "de_DE">
        >>> Locale.negotiate(['de_DE', 'en_US'], ['en', 'de'])
        <Locale "de">
        >>> Locale.negotiate(['de_DE', 'de'], ['en_US'])
        
        You can specify the character used in the locale identifiers to separate
        the differnet components. This separator is applied to both lists. Also,
        case is ignored in the comparison:
        
        >>> Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-')
        <Locale "de_DE">
        
        :param preferred: the list of locale identifers preferred by the user
        :param available: the list of locale identifiers available
        :param aliases: a dictionary of aliases for locale identifiers
        :return: the `Locale` object for the best match, or `None` if no match
                 was found
        :rtype: `Locale`
        :see: `negotiate_locale`
        t   sepRs   N(   R   R   t   parse(   Rt   t	   preferredt	   availableRx   Rs   Rg   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt	   negotiate   s    	c         C   s)   t  | t  r% |  t | d |   S| S(   sL  Create a `Locale` instance for the given locale identifier.
        
        >>> l = Locale.parse('de-DE', sep='-')
        >>> l.display_name
        u'Deutsch (Deutschland)'
        
        If the `identifier` parameter is not a string, but actually a `Locale`
        object, that object is returned:
        
        >>> Locale.parse(l)
        <Locale "de_DE">
        
        :param identifier: the locale identifier string
        :param sep: optional component separator
        :return: a corresponding `Locale` instance
        :rtype: `Locale`
        :raise `ValueError`: if the string does not appear to be a valid locale
                             identifier
        :raise `UnknownLocaleError`: if no locale data is available for the
                                     requested locale
        :see: `parse_locale`
        Rx   (   t
   isinstancet
   basestringR   (   Rt   Rg   Rx   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyRy      s    c         C   s   t  |   t  |  k S(   N(   Rq   (   Rh   t   other(    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   __eq__   s    c         C   s   |  j  |  S(   N(   R   (   Rh   R   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   __ne__   s    c         C   s   d t  |   S(   Ns   <Locale "%s">(   Rq   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   __repr__   s    c         C   s.   d j  t d  |  j |  j |  j |  j g   S(   NRw   (   R   t   filterR   Rl   Rn   Rm   Ro   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   __str__   s    c         C   s:   |  j  d  k r3 t j t j t |     |  _  n  |  j  S(   N(   Rp   R   R    t   LocaleDataDictR   Rq   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   _data   s    $c         C   s  | d k r |  } n  t j |  } | j j |  j  } |  j sT |  j sT |  j rg  } |  j r | j	 | j
 j |  j   n  |  j r | j	 | j j |  j   n  |  j r | j	 | j j |  j   n  t d |  } | r| d d j |  7} qn  | S(   s  Return the display name of the locale using the given locale.
        
        The display name will include the language, territory, script, and
        variant, if those are specified.
        
        >>> Locale('zh', 'CN', script='Hans').get_display_name('en')
        u'Chinese (Simplified Han, China)'
        
        :param locale: the locale to use
        :return: the display name
        s    (%s)u   , N(   R   R   Ry   t	   languagesR   Rl   Rm   Rn   Ro   t   appendt   scriptst   territoriest   variantsR   R   (   Rh   t   localet   retvalt   details(    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   get_display_name   s     				t   docs&          The localized display name of the locale.
        
        >>> Locale('en').display_name
        u'English'
        >>> Locale('en', 'US').display_name
        u'English (United States)'
        >>> Locale('sv').display_name
        u'svenska'
        
        :type: `unicode`
        c         C   s   |  j  t d   S(   NR(   (   R   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   english_name  s    s           The english display name of the locale.
        
        >>> Locale('de').english_name
        u'German'
        >>> Locale('de', 'DE').english_name
        u'German (Germany)'
        
        :type: `unicode`
        c         C   s   |  j  d S(   NR   (   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   $  s    s           Mapping of language codes to translated language names.
        
        >>> Locale('de', 'DE').languages['ja']
        u'Japanisch'
        
        :type: `dict`
        :see: `ISO 639 <http://www.loc.gov/standards/iso639-2/>`_
        c         C   s   |  j  d S(   NR   (   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   0  s    s           Mapping of script codes to translated script names.
        
        >>> Locale('en', 'US').scripts['Hira']
        u'Hiragana'
        
        :type: `dict`
        :see: `ISO 15924 <http://www.evertype.com/standards/iso15924/>`_
        c         C   s   |  j  d S(   NR   (   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   <  s    s          Mapping of script codes to translated script names.
        
        >>> Locale('es', 'CO').territories['DE']
        u'Alemania'
        
        :type: `dict`
        :see: `ISO 3166 <http://www.iso.org/iso/en/prods-services/iso3166ma/>`_
        c         C   s   |  j  d S(   NR   (   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   H  s    s           Mapping of script codes to translated script names.
        
        >>> Locale('de', 'DE').variants['1901']
        u'Alte deutsche Rechtschreibung'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   currency_names(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt
   currenciesU  s    s          Mapping of currency codes to translated currency names.
        
        >>> Locale('en').currencies['COP']
        u'Colombian Peso'
        >>> Locale('de', 'DE').currencies['COP']
        u'Kolumbianischer Peso'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   currency_symbols(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   b  s    s           Mapping of currency codes to symbols.
        
        >>> Locale('en', 'US').currency_symbols['USD']
        u'$'
        >>> Locale('es', 'CO').currency_symbols['USD']
        u'US$'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   number_symbols(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   o  s    s           Symbols used in number formatting.
        
        >>> Locale('fr', 'FR').number_symbols['decimal']
        u','
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   decimal_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   z  s    s           Locale patterns for decimal number formatting.
        
        >>> Locale('en', 'US').decimal_formats[None]
        <NumberPattern u'#,##0.###'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   currency_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s   \
        Locale patterns for currency number formatting.
        
        >>> print Locale('en', 'US').currency_formats[None]
        <NumberPattern u'\xa4#,##0.00'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   percent_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale patterns for percent number formatting.
        
        >>> Locale('en', 'US').percent_formats[None]
        <NumberPattern u'#,##0%'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   scientific_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale patterns for scientific number formatting.
        
        >>> Locale('en', 'US').scientific_formats[None]
        <NumberPattern u'#E0'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   periods(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale display names for day periods (AM/PM).
        
        >>> Locale('en', 'US').periods['am']
        u'AM'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   days(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale display names for weekdays.
        
        >>> Locale('de', 'DE').days['format']['wide'][3]
        u'Donnerstag'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   months(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale display names for months.
        
        >>> Locale('de', 'DE').months['format']['wide'][10]
        u'Oktober'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   quarters(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale display names for quarters.
        
        >>> Locale('de', 'DE').quarters['format']['wide'][1]
        u'1. Quartal'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   eras(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           Locale display names for eras.
        
        >>> Locale('en', 'US').eras['wide'][1]
        u'Anno Domini'
        >>> Locale('en', 'US').eras['abbreviated'][0]
        u'BC'
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt
   time_zones(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s'          Locale display names for time zones.
        
        >>> Locale('en', 'US').time_zones['Europe/London']['long']['daylight']
        u'British Summer Time'
        >>> Locale('en', 'US').time_zones['America/St_Johns']['city']
        u"St. John's"
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt
   meta_zones(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s          Locale display names for meta time zones.
        
        Meta time zones are basically groups of different Olson time zones that
        have the same GMT offset and daylight savings time.
        
        >>> Locale('en', 'US').meta_zones['Europe_Central']['long']['daylight']
        u'Central European Summer Time'
        
        :type: `dict`
        :since: version 0.9
        c         C   s   |  j  d S(   Nt   zone_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s(  \
        Patterns related to the formatting of time zones.
        
        >>> Locale('en', 'US').zone_formats['fallback']
        u'%(1)s (%(0)s)'
        >>> Locale('pt', 'BR').zone_formats['region']
        u'Hor\xe1rio %s'
        
        :type: `dict`
        :since: version 0.9
        c         C   s   |  j  d d S(   Nt	   week_datat	   first_day(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   first_week_day  s    s           The first day of a week, with 0 being Monday.
        
        >>> Locale('de', 'DE').first_week_day
        0
        >>> Locale('en', 'US').first_week_day
        6
        
        :type: `int`
        c         C   s   |  j  d d S(   NR   t   weekend_start(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    s           The day the weekend starts, with 0 being Monday.
        
        >>> Locale('de', 'DE').weekend_start
        5
        
        :type: `int`
        c         C   s   |  j  d d S(   NR   t   weekend_end(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   #  s    s           The day the weekend ends, with 0 being Monday.
        
        >>> Locale('de', 'DE').weekend_end
        6
        
        :type: `int`
        c         C   s   |  j  d d S(   NR   t   min_days(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   min_week_days.  s    s           The minimum number of days in a week so that the week is counted as the
        first week of a year or month.
        
        >>> Locale('de', 'DE').min_week_days
        4
        
        :type: `int`
        c         C   s   |  j  d S(   Nt   date_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   :  s    s          Locale patterns for date formatting.
        
        >>> Locale('en', 'US').date_formats['short']
        <DateTimePattern u'M/d/yy'>
        >>> Locale('fr', 'FR').date_formats['long']
        <DateTimePattern u'd MMMM yyyy'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   time_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   G  s    s          Locale patterns for time formatting.
        
        >>> Locale('en', 'US').time_formats['short']
        <DateTimePattern u'h:mm a'>
        >>> Locale('fr', 'FR').time_formats['long']
        <DateTimePattern u'HH:mm:ss z'>
        
        :type: `dict`
        c         C   s   |  j  d S(   Nt   datetime_formats(   R   (   Rh   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   T  s    s           Locale patterns for datetime formatting.
        
        >>> Locale('en').datetime_formats[None]
        u'{1} {0}'
        >>> Locale('th').datetime_formats[None]
        u'{1}, {0}'
        
        :type: `dict`
        N(-   Ri   Rj   Rk   R   Rf   t   LOCALE_ALIASESRv   t   classmethodR|   Ry   R   R   R   R   R   t   propertyR   t   display_nameR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   Q   s   																																																																							
																									c         C   s   |  d d d d f } x t  d |  D] } t j |  } | r% | d k rn d | k rn | j d  d } n  | d k r d	 } n | r | | k r | | } n  y  d
 j t  d t |    SWq t k
 r q Xq% q% Wd S(   s  Returns the system default locale for a given category, based on
    environment variables.
    
    >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE']:
    ...     os.environ[name] = ''
    >>> os.environ['LANG'] = 'fr_FR.UTF-8'
    >>> default_locale('LC_MESSAGES')
    'fr_FR'

    The "C" or "POSIX" pseudo-locales are treated as aliases for the
    "en_US_POSIX" locale:

    >>> os.environ['LC_MESSAGES'] = 'POSIX'
    >>> default_locale('LC_MESSAGES')
    'en_US_POSIX'

    :param category: one of the ``LC_XXX`` environment variable names
    :param aliases: a dictionary of aliases for locale identifiers
    :return: the value of the variable, or any of the fallbacks (``LANGUAGE``,
             ``LC_ALL``, ``LC_CTYPE``, and ``LANG``)
    :rtype: `str`
    t   LANGUAGEt   LC_ALLt   LC_CTYPEt   LANGt   :i    t   Ct   POSIXt   en_US_POSIXRw   N(   R   R   (   R   R   R	   t   getenvt   splitR   R   t
   ValueError(   Ru   Rs   t   varnamest   nameR   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR   b  s    	 Rw   c   	      C   s   g  | D] } | r | j    ^ q } x |  D] } | j    } | | k rN | S| r | j |  } | r | j d |  } | j    | k r | Sq n  | j |  } t |  d k r, | d j    | k r, | d Sq, Wd S(   s
  Find the best match between available and requested locale strings.
    
    >>> negotiate_locale(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
    'de_DE'
    >>> negotiate_locale(['de_DE', 'en_US'], ['en', 'de'])
    'de'
    
    Case is ignored by the algorithm, the result uses the case of the preferred
    locale identifier:
    
    >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at'])
    'de_DE'
    
    >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at'])
    'de_DE'
    
    By default, some web browsers unfortunately do not include the territory
    in the locale identifier for many locales, and some don't even allow the
    user to easily add the territory. So while you may prefer using qualified
    locale identifiers in your web-application, they would not normally match
    the language-only locale sent by such browsers. To workaround that, this
    function uses a default mapping of commonly used langauge-only locale
    identifiers to identifiers including the territory:
    
    >>> negotiate_locale(['ja', 'en_US'], ['ja_JP', 'en_US'])
    'ja_JP'
    
    Some browsers even use an incorrect or outdated language code, such as "no"
    for Norwegian, where the correct locale identifier would actually be "nb_NO"
    (Bokmål) or "nn_NO" (Nynorsk). The aliases are intended to take care of
    such cases, too:
    
    >>> negotiate_locale(['no', 'sv'], ['nb_NO', 'sv_SE'])
    'nb_NO'
    
    You can override this default mapping by passing a different `aliases`
    dictionary to this function, or you can bypass the behavior althogher by
    setting the `aliases` parameter to `None`.
    
    :param preferred: the list of locale strings preferred by the user
    :param available: the list of locale strings available
    :param sep: character that separates the different parts of the locale
                strings
    :param aliases: a dictionary of aliases for locale identifiers
    :return: the locale identifier for the best match, or `None` if no match
             was found
    :rtype: `str`
    Rw   i   i    N(   t   lowerR   t   replaceR   t   lenR   (	   Rz   R{   Rx   Rs   t   aR   t   llt   aliast   parts(    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s    1%
(c      
   C   s  d |  k r% |  j  d d  d }  n  d |  k rJ |  j  d d  d }  n  |  j  |  } | j d  j   } | j   s t d |   n  d } } } | r t | d  d k r | d j   r | j d  j   } q n  | rat | d  d k r&| d j   r&| j d  j   } qat | d  d k ra| d j	   ra| j d  } qan  | rt | d  d k r| d d j	   st | d  d	 k r| d d j   r| j   } qn  | rt d
 |    n  | | | | f S(   s  Parse a locale identifier into a tuple of the form::
    
      ``(language, territory, script, variant)``
    
    >>> parse_locale('zh_CN')
    ('zh', 'CN', None, None)
    >>> parse_locale('zh_Hans_CN')
    ('zh', 'CN', 'Hans', None)
    
    The default component separator is "_", but a different separator can be
    specified using the `sep` parameter:
    
    >>> parse_locale('zh-CN', sep='-')
    ('zh', 'CN', None, None)
    
    If the identifier cannot be parsed into a locale, a `ValueError` exception
    is raised:
    
    >>> parse_locale('not_a_LOCALE_String')
    Traceback (most recent call last):
      ...
    ValueError: 'not_a_LOCALE_String' is not a valid locale identifier
    
    Encoding information and locale modifiers are removed from the identifier:
    
    >>> parse_locale('it_IT@euro')
    ('it', 'IT', None, None)
    >>> parse_locale('en_US.UTF-8')
    ('en', 'US', None, None)
    >>> parse_locale('de_DE.iso885915@euro')
    ('de', 'DE', None, None)
    
    :param identifier: the locale identifier string
    :param sep: character that separates the different components of the locale
                identifier
    :return: the ``(language, territory, script, variant)`` tuple
    :rtype: `tuple`
    :raise `ValueError`: if the string does not appear to be a valid locale
                         identifier
    
    :see: `IETF RFC 4646 <http://www.ietf.org/rfc/rfc4646.txt>`_
    t   .i   i    t   @s   expected only letters, got %ri   i   i   i   s#   %r is not a valid locale identifierN(
   R   t   popR   t   isalphaR   R   R   t   titlet   uppert   isdigit(   Rg   Rx   R   t   langRn   Rm   Ro   (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyR     s0    +&&&**(   Rk   R	   R   t   babelR    t   __all__t   __docformat__R   R   R   R   Re   R   t   objectR   R   R   R   (    (    (    s.   /usr/lib/python2.7/site-packages/babel/core.pyt   <module>   s0   		#######  (A