ó
™‚Mc           @   sì  d  Z  d d l Z d d l Z y d d l m Z e Z Wn e k
 rQ e Z n Xd d l	 m
 Z
 m Z d d l m Z d d d d	 d
 d d d g Z d Z e
 d ƒ Z e d „ Z e d „ Z e d „ Z e d „ Z e d „ Z e d „ Z e d „ Z e d „ Z d e d „ Z d e d „ Z d e d „ Z d e d „ Z d e f d „  ƒ  YZ e d „ Z  e d „ Z! d Z" d  Z# d! e" Z$ d" e# Z% d# Z& e j' d$ e$ e% e& f ƒ Z( d% „  Z) d& d' „ Z* d( „  Z+ d) e, f d* „  ƒ  YZ- d S(+   sæ   Locale dependent formatting and parsing of numeric data.

The default locale for the functions in this module is determined by the
following environment variables, in that order:

 * ``LC_NUMERIC``,
 * ``LC_ALL``, and
 * ``LANG``
iÿÿÿÿN(   t   Decimal(   t   default_localet   Locale(   t   rsplitt   format_numbert   format_decimalt   format_currencyt   format_percentt   format_scientifict   parse_numbert   parse_decimalt   NumberFormatErrors   restructuredtext ent
   LC_NUMERICc         C   s   t  j | ƒ j j |  |  ƒ S(   s<  Return the name used by the locale for the specified currency.
    
    >>> get_currency_name('USD', 'en_US')
    u'US Dollar'
    
    :param currency: the currency code
    :param locale: the `Locale` object or locale identifier
    :return: the currency symbol
    :rtype: `unicode`
    :since: version 0.9.4
    (   R   t   parset
   currenciest   get(   t   currencyt   locale(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_currency_name,   s    c         C   s   t  j | ƒ j j |  |  ƒ S(   s  Return the symbol used by the locale for the specified currency.
    
    >>> get_currency_symbol('USD', 'en_US')
    u'$'
    
    :param currency: the currency code
    :param locale: the `Locale` object or locale identifier
    :return: the currency symbol
    :rtype: `unicode`
    (   R   R   t   currency_symbolsR   (   R   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_currency_symbol:   s    c         C   s   t  j |  ƒ j j d d ƒ S(   sñ   Return the symbol used by the locale to separate decimal fractions.
    
    >>> get_decimal_symbol('en_US')
    u'.'
    
    :param locale: the `Locale` object or locale identifier
    :return: the decimal symbol
    :rtype: `unicode`
    t   decimalu   .(   R   R   t   number_symbolsR   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_decimal_symbolG   s    
c         C   s   t  j |  ƒ j j d d ƒ S(   sé   Return the plus sign symbol used by the current locale.
    
    >>> get_plus_sign_symbol('en_US')
    u'+'
    
    :param locale: the `Locale` object or locale identifier
    :return: the plus sign symbol
    :rtype: `unicode`
    t   plusSignu   +(   R   R   R   R   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_plus_sign_symbolS   s    
c         C   s   t  j |  ƒ j j d d ƒ S(   sê   Return the plus sign symbol used by the current locale.
    
    >>> get_minus_sign_symbol('en_US')
    u'-'
    
    :param locale: the `Locale` object or locale identifier
    :return: the plus sign symbol
    :rtype: `unicode`
    t	   minusSignu   -(   R   R   R   R   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_minus_sign_symbol_   s    
c         C   s   t  j |  ƒ j j d d ƒ S(   sý   Return the symbol used by the locale to separate mantissa and exponent.
    
    >>> get_exponential_symbol('en_US')
    u'E'
    
    :param locale: the `Locale` object or locale identifier
    :return: the exponential symbol
    :rtype: `unicode`
    t   exponentialu   E(   R   R   R   R   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_exponential_symbolk   s    
c         C   s   t  j |  ƒ j j d d ƒ S(   sï   Return the symbol used by the locale to separate groups of thousands.
    
    >>> get_group_symbol('en_US')
    u','
    
    :param locale: the `Locale` object or locale identifier
    :return: the group symbol
    :rtype: `unicode`
    t   groupu   ,(   R   R   R   R   (   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   get_group_symbolw   s    
c         C   s   t  |  d | ƒS(   s  Return the given number formatted for a specific locale.
    
    >>> format_number(1099, locale='en_US')
    u'1,099'
    
    :param number: the number to format
    :param locale: the `Locale` object or locale identifier
    :return: the formatted number
    :rtype: `unicode`
    R   (   R   (   t   numberR   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ƒ   s    c         C   sF   t  j | ƒ } | s* | j j | ƒ } n  t | ƒ } | j |  | ƒ S(   sÓ  Return the given decimal number formatted for a specific locale.
    
    >>> format_decimal(1.2345, locale='en_US')
    u'1.234'
    >>> format_decimal(1.2346, locale='en_US')
    u'1.235'
    >>> format_decimal(-1.2346, locale='en_US')
    u'-1.235'
    >>> format_decimal(1.2345, locale='sv_SE')
    u'1,234'
    >>> format_decimal(12345, locale='de')
    u'12.345'

    The appropriate thousands grouping and the decimal separator are used for
    each locale:
    
    >>> format_decimal(12345.5, locale='en_US')
    u'12,345.5'

    :param number: the number to format
    :param format: 
    :param locale: the `Locale` object or locale identifier
    :return: the formatted decimal number
    :rtype: `unicode`
    (   R   R   t   decimal_formatsR   t   parse_patternt   apply(   R    t   formatR   t   pattern(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ‘   s
    c         C   sL   t  j | ƒ } | s* | j j | ƒ } n  t | ƒ } | j |  | d | ƒS(   u~  Return formatted currency value.
    
    >>> format_currency(1099.98, 'USD', locale='en_US')
    u'$1,099.98'
    >>> format_currency(1099.98, 'USD', locale='es_CO')
    u'US$\xa01.099,98'
    >>> format_currency(1099.98, 'EUR', locale='de_DE')
    u'1.099,98\xa0\u20ac'
    
    The pattern can also be specified explicitly:
    
    >>> format_currency(1099.98, 'EUR', u'Â¤Â¤ #,##0.00', locale='en_US')
    u'EUR 1,099.98'
    
    :param number: the number to format
    :param currency: the currency code
    :param locale: the `Locale` object or locale identifier
    :return: the formatted currency value
    :rtype: `unicode`
    R   (   R   R   t   currency_formatsR   R"   R#   (   R    R   R$   R   R%   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ±   s
    c         C   sF   t  j | ƒ } | s* | j j | ƒ } n  t | ƒ } | j |  | ƒ S(   sN  Return formatted percent value for a specific locale.
    
    >>> format_percent(0.34, locale='en_US')
    u'34%'
    >>> format_percent(25.1234, locale='en_US')
    u'2,512%'
    >>> format_percent(25.1234, locale='sv_SE')
    u'2\xa0512\xa0%'

    The format pattern can also be specified explicitly:
    
    >>> format_percent(25.1234, u'#,##0\u2030', locale='en_US')
    u'25,123\u2030'

    :param number: the percent number to format
    :param format: 
    :param locale: the `Locale` object or locale identifier
    :return: the formatted percent number
    :rtype: `unicode`
    (   R   R   t   percent_formatsR   R"   R#   (   R    R$   R   R%   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   Ì   s
    c         C   sF   t  j | ƒ } | s* | j j | ƒ } n  t | ƒ } | j |  | ƒ S(   sÚ  Return value formatted in scientific notation for a specific locale.
    
    >>> format_scientific(10000, locale='en_US')
    u'1E4'

    The format pattern can also be specified explicitly:
    
    >>> format_scientific(1234567, u'##0E00', locale='en_US')
    u'1.23E06'

    :param number: the number to format
    :param format: 
    :param locale: the `Locale` object or locale identifier
    :return: value formatted in scientific notation.
    :rtype: `unicode`
    (   R   R   t   scientific_formatsR   R"   R#   (   R    R$   R   R%   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ç   s
    c           B   s   e  Z d  Z RS(   s>   Exception raised when a string cannot be parsed into a number.(   t   __name__t
   __module__t   __doc__(    (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ÿ   s   c         C   sH   y  t  |  j t | ƒ d ƒ ƒ SWn! t k
 rC t d |  ƒ ‚ n Xd S(   s|  Parse localized number string into a long integer.
    
    >>> parse_number('1,099', locale='en_US')
    1099L
    >>> parse_number('1.099', locale='de_DE')
    1099L
    
    When the given string cannot be parsed, an exception is raised:
    
    >>> parse_number('1.099,98', locale='de')
    Traceback (most recent call last):
        ...
    NumberFormatError: '1.099,98' is not a valid number
    
    :param string: the string to parse
    :param locale: the `Locale` object or locale identifier
    :return: the parsed number
    :rtype: `long`
    :raise `NumberFormatError`: if the string can not be converted to a number
    t    s   %r is not a valid numberN(   t   longt   replaceR   t
   ValueErrorR   (   t   stringR   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR	     s     c         C   si   t  j | ƒ } y2 t |  j t | ƒ d ƒ j t | ƒ d ƒ ƒ SWn! t k
 rd t d |  ƒ ‚ n Xd S(   s»  Parse localized decimal string into a float.
    
    >>> parse_decimal('1,099.98', locale='en_US')
    1099.98
    >>> parse_decimal('1.099,98', locale='de')
    1099.98
    
    When the given string cannot be parsed, an exception is raised:
    
    >>> parse_decimal('2,109,998', locale='de')
    Traceback (most recent call last):
        ...
    NumberFormatError: '2,109,998' is not a valid decimal number
    
    :param string: the string to parse
    :param locale: the `Locale` object or locale identifier
    :return: the parsed decimal number
    :rtype: `float`
    :raise `NumberFormatError`: if the string can not be converted to a
                                decimal number
    R,   t   .s    %r is not a valid decimal numberN(   R   R   t   floatR.   R   R   R/   R   (   R0   R   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR
     s    s
   [^0-9@#.,]s   [0-9@#.\-,E+]s   (?P<prefix>(?:'[^']*'|%s)*)s   (?P<number>%s+)s   (?P<suffix>.*)s   %s%s%sc         C   sŠ   t  r$ t |  t ƒ r$ t |  ƒ } n d |  j d ƒ } d | k rs | j d d ƒ \ } } | d k r€ d } q€ n | d } } | | f S(   s=   Convert a number into a (intasstring, fractionasstring) tuples   %.9ft   0R1   i   R,   (   t   have_decimalt
   isinstanceR    t   strt   rstript   split(   t   valuet   textt   at   b(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   split_numberE  s    i    c   	   	   C   s&  t  |  d k  ƒ r d p d } t |  ƒ }  t |  ƒ \ } } | | } d } t | ƒ | } | d k  sÃ | t | ƒ k r} nF | | d k r– d } n- | | d k rÃ | | d d k rÃ d } n  d | } t rt |  t ƒ rt t  |  | | ƒ ƒ | | St t  |  | | ƒ ƒ | | Sd S(   sC  Round a number to a given precision.

    Works like round() except that the round-half-even (banker's rounding)
    algorithm is used instead of round-half-up.

    >>> bankersround(5.5, 0)
    6.0
    >>> bankersround(6.5, 0)
    6.0
    >>> bankersround(-6.5, 0)
    -6.0
    >>> bankersround(1234.0, -2)
    1200.0
    i    iÿÿÿÿi   t   5t   13579i
   N(   t   intt   absR=   t   lenR4   R5   R    R2   (	   R9   t   ndigitst   signR;   R<   t   digitst   addt   it   scale(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   bankersroundS  s     
	$	
 c      
   C   sô  t  |  t ƒ r |  Sd |  k rv |  j d d ƒ \ }  } t j |  ƒ j ƒ  \ } } } t j | ƒ j ƒ  \ } } } n. t j |  ƒ j ƒ  \ } } } d | } | } d | k rË | j d d ƒ \ } } n d } d | k rd | k rd | k rt d ƒ ‚ qn  d | k r.t | d d ƒ \ }	 }
 n | }	 d	 }
 d
 } } d „  } d „  } | |	 ƒ } | |
 ƒ } | r±| |	 |
 ƒ } | j	 d ƒ } | j
 d ƒ } | | ƒ } n d } d } | |	 ƒ } t |  | | f | | f | | | | | ƒ S(   s   Parse number format patternst   ;i   t   -t   Et   @R1   R3   s5   Significant digit patterns can not contain "@" or "0"R,   i    c         S   st   d } } x] |  D]U } | d k r: | d 7} | d 7} q | d k rS | d 7} q | d k re q q Pq W| | f S(   s(   Calculate the min and max allowed digitsi    s   @0i   t   #t   ,(    (   t   pt   mint   maxt   c(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   parse_precision‘  s    

c         S   sƒ   t  |  ƒ } |  j d ƒ } | d k r+ d S| | d } |  | d  j d ƒ } | d k rg | | f S| | | d } | | f S(   sÉ   Parse primary and secondary digit grouping

        >>> parse_grouping('##')
        0, 0
        >>> parse_grouping('#,###')
        3, 3
        >>> parse_grouping('#,####,###')
        3, 4
        RO   iÿÿÿÿiè  i   i   (   iè  iè  (   RB   t   rfind(   RP   t   widtht   g1t   g2(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   parse_grouping   s    

t   +N(   R5   t   NumberPatternR8   t	   number_ret   searcht   groupst   NoneR/   R   t
   startswitht   lstrip(   R%   t   neg_patternt
   pos_prefixR    t
   pos_suffixt
   neg_prefixt   _t
   neg_suffixt   expt   integert   fractiont   min_fract   max_fracRT   RY   t   int_prect	   frac_prect   exp_plust   exp_prect   grouping(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR"   t  sH    !

		R[   c           B   sA   e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   c	   	      C   s«   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d d j |  j |  j ƒ k rs d |  _	 n4 d d j |  j |  j ƒ k rž d |  _	 n	 d |  _	 d  S(   Nt   %R,   id   u   â€°iè  i   (
   R%   t   prefixt   suffixRq   Rm   Rn   Rp   Ro   t   joinRH   (	   t   selfR%   Rs   Rt   Rq   Rm   Rn   Rp   Ro   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   __init__È  s    								c         C   s   d t  |  ƒ j |  j f S(   Ns   <%s %r>(   t   typeR)   R%   (   Rv   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   __repr__Ù  s    c      
   C   sP  | |  j  9} t | d k  ƒ } |  j rÁt | ƒ } | r^ t t j t j | d ƒ ƒ ƒ } n d } |  j d |  j d k r– | |  j d d 8} n2 |  j d rÈ t | ƒ |  j d |  j d } n  t sß t	 | t
 ƒ rî t | ƒ } n  | d k  r| d | } n | d | } d } | d k  r;t | ƒ } n |  j rSt | ƒ } n  t | ƒ } d |  j | |  j d |  j d ƒ t | ƒ | |  j t | ƒ |  j d |  j d | ƒ f } n(d |  j k rs|  j t | ƒ |  j d |  j d ƒ } d | k rX| j d ƒ \ }	 }
 |  j |	 d d | ƒ }	 |
 rKt | ƒ |
 }
 n  |	 |
 } qé|  j | d d | ƒ } nv t t t | ƒ |  j d ƒ ƒ \ }	 }
 |
 p¤d	 }
 |  j |	 |  j d |  j d | ƒ }	 |  j |
 | ƒ }
 |	 |
 } d
 |  j | | |  j | f } d | k rL| j d | j ƒ  ƒ } | j d t | | ƒ ƒ } n  | S(   Ni    i
   i   R,   u   %s%s%s%sRM   R1   iè  R3   u   %s%s%su   Â¤u   Â¤Â¤(   RH   R@   Rp   RA   t   matht   floort   logRm   R4   R5   R    R2   R   Ro   R   t   _format_sigdigRn   R   t   _format_intR6   R%   R8   R   R=   RI   t   _format_fracRs   Rt   R.   t   upperR   (   Rv   R9   R   R   t   is_negativeRh   t   exp_signR    R:   R;   R<   t   retval(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR#   Ü  sh    	$%	

c         C   s  t  | ƒ \ } } t | ƒ } | d k ri | d k ri d } x* | j d ƒ re | d } | d 8} q? Wn  t  t | | | ƒ ƒ \ } } t | | j d ƒ ƒ } | s° d } n  t | ƒ | k rÒ | d k rÒ | S| | k  ró | d | | 7} n  | rd | | f S| S(   s‡   Convert value to a string.

        The resulting string will contain between (min, max) number of
        significant digits.
        R3   R,   i    i   s   %s.%s(   R=   RB   R`   RI   Ra   (   Rv   R9   RQ   RR   R;   R<   t	   ndecimalsRE   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR}     s$    
	c   	      C   s˜   t  | ƒ } | | k  r- d | | | } n  |  j d } d } t | ƒ } xA t  | ƒ | k r | | | | } | |  } |  j d } qO W| | S(   NR3   i    R,   i   (   RB   Rq   R   (	   Rv   R9   RQ   RR   R   RV   t   gsizet   rett   symbol(    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR~   2  s    c         C   s·   |  j  \ } } t | ƒ | k  r< | d | t | ƒ 7} n  | d k sf | d k rj t | ƒ d k rj d St | ƒ } x0 t | ƒ | k r¨ | d d k r¨ | d  } qy Wt | ƒ | S(   NR3   i    R,   iÿÿÿÿ(   Rn   RB   R@   R   (   Rv   R9   R   RQ   RR   RV   (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR   ?  s    *%N(	   R)   R*   Rw   Ry   R_   R#   R}   R~   R   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyR[   Æ  s   		<		(.   R+   Rz   t   reR   R    t   TrueR4   t   ImportErrort   Falset
   babel.coreR   R   t
   babel.utilR   t   __all__t   __docformat__R   R   R   R   R   R   R   R   R   R_   R   R   R   R   R/   R   R	   R
   t
   PREFIX_ENDt   NUMBER_TOKENt   PREFIX_PATTERNt   NUMBER_PATTERNt   SUFFIX_PATTERNt   compileR\   R=   RI   R"   t   objectR[   (    (    (    s1   /usr/lib/python2.7/site-packages/babel/numbers.pyt   <module>   sP   

		 

	!	R