Viewing File: /usr/lib/python2.7/site-packages/babel/numbers.pyo

ó
™‚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
Back to Directory File Manager