ok

Mini Shell

Direktori : /proc/self/root/proc/self/root/proc/self/root/lib/python2.7/site-packages/babel/
Upload File :
Current File : //proc/self/root/proc/self/root/proc/self/root/lib/python2.7/site-packages/babel/numbers.pyc

�
��Mc@s�dZddlZddlZyddlmZeZWnek
rQeZnXddl	m
Z
mZddlm
Z
dddd	d
ddd
gZdZe
d�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zded�Zded�Zded�Zded�Zd
efd��YZed�Z ed�Z!dZ"d Z#d!e"Z$d"e#Z%d#Z&ej'd$e$e%e&f�Z(d%�Z)d&d'�Z*d(�Z+d)e,fd*��YZ-dS(+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(tDecimal(tdefault_localetLocale(trsplitt
format_numbertformat_decimaltformat_currencytformat_percenttformat_scientifictparse_numbert
parse_decimaltNumberFormatErrorsrestructuredtext ent
LC_NUMERICcCstj|�jj||�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
    (Rtparset
currenciestget(tcurrencytlocale((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_currency_name,scCstj|�jj||�S(sReturn 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`
    (RR
tcurrency_symbolsR(RR((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_currency_symbol:scCstj|�jjdd�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`
    tdecimalu.(RR
tnumber_symbolsR(R((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_decimal_symbolGs
cCstj|�jjdd�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`
    tplusSignu+(RR
RR(R((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_plus_sign_symbolSs
cCstj|�jjdd�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-(RR
RR(R((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_minus_sign_symbol_s
cCstj|�jjdd�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`
    texponentialuE(RR
RR(R((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_exponential_symbolks
cCstj|�jjdd�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`
    tgroupu,(RR
RR(R((s1/usr/lib/python2.7/site-packages/babel/numbers.pytget_group_symbolws
cCst|d|�S(sReturn 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(tnumberR((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR�scCsFtj|�}|s*|jj|�}nt|�}|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`
    (RR
tdecimal_formatsRt
parse_patterntapply(R tformatRtpattern((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR�s
cCsLtj|�}|s*|jj|�}nt|�}|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(RR
tcurrency_formatsRR"R#(R RR$RR%((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR�s
cCsFtj|�}|s*|jj|�}nt|�}|j||�S(sNReturn 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`
    (RR
tpercent_formatsRR"R#(R R$RR%((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR�s
cCsFtj|�}|s*|jj|�}nt|�}|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`
    (RR
tscientific_formatsRR"R#(R R$RR%((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR�s
cBseZdZRS(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�scCsHy t|jt|�d��SWn!tk
rCtd|��nXdS(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
    ts%r is not a valid numberN(tlongtreplaceRt
ValueErrorR(tstringR((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR	s 
cCsitj|�}y2t|jt|�d�jt|�d��SWn!tk
rdtd|��nXdS(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(RR
tfloatR.RRR/R(R0R((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%scCs�tr$t|t�r$t|�}nd|jd�}d|krs|jdd�\}}|dkr�d}q�n
|d}}||fS(s=Convert a number into a (intasstring, fractionasstring) tuples%.9ft0R1iR,(thave_decimalt
isinstanceRtstrtrstriptsplit(tvaluettexttatb((s1/usr/lib/python2.7/site-packages/babel/numbers.pytsplit_numberEs
ic		Cs&t|dk�rdpd}t|�}t|�\}}||}d}t|�|}|dks�|t|�kr}nF||dkr�d}n-||dkr�||ddkr�d}nd|}trt|t�rtt|||��||Stt|||��||SdS(sCRound 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
    ii����it5t13579i
N(tinttabsR=tlenR4R5RR2(	R9tndigitstsignR;R<tdigitstaddtitscale((s1/usr/lib/python2.7/site-packages/babel/numbers.pytbankersroundSs 
	$	
 c
Cs�t|t�r|Sd|krv|jdd�\}}tj|�j�\}}}tj|�j�\}}}n.tj|�j�\}}}d|}|}d|kr�|jdd�\}}nd}d|krd|krd|krtd��qnd|kr.t|dd�\}	}
n|}	d	}
d
}}d�}
d�}|
|	�}|
|
�}|r�|
|	|
�}|j	d
�}|j
d
�}|
|�}nd}d}||	�}t|||f||f|||||�S(sParse number format patternst;it-tEt@R1R3s5Significant digit patterns can not contain "@" or "0"R,icSstd}}x]|D]U}|dkr:|d7}|d7}q|dkrS|d7}q|dkreqqPqW||fS(s(Calculate the min and max allowed digitsis@0it#t,((tptmintmaxtc((s1/usr/lib/python2.7/site-packages/babel/numbers.pytparse_precision�s




cSs�t|�}|jd�}|dkr+dS||d}||d jd�}|dkrg||fS|||d}||fS(s�Parse primary and secondary digit grouping

        >>> parse_grouping('##')
        0, 0
        >>> parse_grouping('#,###')
        3, 3
        >>> parse_grouping('#,####,###')
        3, 4
        ROi����i�ii(i�i�(RBtrfind(RPtwidthtg1tg2((s1/usr/lib/python2.7/site-packages/babel/numbers.pytparse_grouping�s

t+N(R5t
NumberPatternR8t	number_retsearchtgroupstNoneR/Rt
startswithtlstrip(R%tneg_patternt
pos_prefixR t
pos_suffixt
neg_prefixt_t
neg_suffixtexptintegertfractiontmin_fractmax_fracRTRYtint_prect	frac_prectexp_plustexp_prectgrouping((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR"tsH!

		R[cBsAeZd�Zd�Zdd�Zd�Zd�Zd�ZRS(c		Cs�||_||_||_||_||_||_||_||_ddj|j|j�krsd|_	n4ddj|j|j�kr�d|_	n	d|_	dS(Nt%R,idu‰i�i(
R%tprefixtsuffixRqRmRnRpRotjoinRH(	tselfR%RsRtRqRmRnRpRo((s1/usr/lib/python2.7/site-packages/babel/numbers.pyt__init__�s								cCsdt|�j|jfS(Ns<%s %r>(ttypeR)R%(Rv((s1/usr/lib/python2.7/site-packages/babel/numbers.pyt__repr__�sc
CsP||j9}t|dk�}|jr�t|�}|r^ttjtj|d���}nd}|jd|jdkr�||jdd8}n2|jdr�t|�|jd|jd}nts�t	|t
�r�t|�}n|dkr|d|}n|d|}d}|dkr;t|�}n|j
rSt|�}nt|�}d|j||jd|jd�t|�||jt|�|jd|jd|�f}n(d|jkrs|jt|�|jd|jd�}d|krX|jd�\}	}
|j|	dd|�}	|
rKt|�|
}
n|	|
}q�|j|dd|�}nvttt|�|jd��\}	}
|
p�d	}
|j|	|jd|jd|�}	|j|
|�}
|	|
}d
|j|||j|f}d|krL|jd|j��}|jdt||��}n|S(
Nii
iR,u%s%s%s%sRMR1i�R3u%s%s%su¤u¤¤(RHR@RpRAtmathtfloortlogRmR4R5RR2RRoRt_format_sigdigRnRt_format_intR6R%R8RR=RIt_format_fracRsRtR.tupperR(RvR9RRtis_negativeRhtexp_signR R:R;R<tretval((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR#�sh
	$
%	



cCst|�\}}t|�}|dkri|dkrid}x*|jd�re|d}|d8}q?Wntt|||��\}}t||jd��}|s�d}nt|�|kr�|dkr�|S||kr�|d||7}n|rd||fS|S(s�Convert value to a string.

        The resulting string will contain between (min, max) number of
        significant digits.
        R3R,iis%s.%s(R=RBR`RIRa(RvR9RQRRR;R<t	ndecimalsRE((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR}s$
	c	Cs�t|�}||kr-d|||}n|jd}d}t|�}xAt|�|kr�||||}|| }|jd}qOW||S(NR3iR,i(RBRqR(	RvR9RQRRRRVtgsizetrettsymbol((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR~2s
cCs�|j\}}t|�|kr<|d|t|�7}n|dksf|dkrjt|�dkrjdSt|�}x0t|�|kr�|ddkr�|d }qyWt|�|S(NR3iR,i����(RnRBR@R(RvR9RRQRRRV((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR?s*%N(	R)R*RwRyR_R#R}R~R(((s1/usr/lib/python2.7/site-packages/babel/numbers.pyR[�s		<		
(.R+RztreRRtTrueR4tImportErrortFalset
babel.coreRRt
babel.utilRt__all__t
__docformat__RRRRRRRRRR_RRRRR/RR	R
t
PREFIX_ENDtNUMBER_TOKENtPREFIX_PATTERNtNUMBER_PATTERNtSUFFIX_PATTERNtcompileR\R=RIR"tobjectR[(((s1/usr/lib/python2.7/site-packages/babel/numbers.pyt<module>sP


		
 


	!	R

Zerion Mini Shell 1.0