Ñò ž²Hc@sÞdZddkZddkZyddklZeZWnej o eZnXddk l Z l Z ddddd d d d gZ d Z e dƒZed„Zed„Zed„Zed„Zed„Zed„Zed„Zed„Zded„Zded„Zded„Zded„Zd efd„ƒYZed„Zed„ZdZ dZ!d e Z"d!e!Z#d"Z$ei%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_localetLocalet format_numbertformat_decimaltformat_currencytformat_percenttformat_scientifict parse_numbert parse_decimaltNumberFormatErrorsrestructuredtext ent LC_NUMERICcCsti|ƒii||ƒ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.6/site-packages/babel/numbers.pytget_currency_name+s cCsti|ƒii||ƒ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.6/site-packages/babel/numbers.pytget_currency_symbol9s cCsti|ƒiiddƒ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.6/site-packages/babel/numbers.pytget_decimal_symbolFs cCsti|ƒiiddƒ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.6/site-packages/babel/numbers.pytget_plus_sign_symbolRs cCsti|ƒiiddƒ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.6/site-packages/babel/numbers.pytget_minus_sign_symbol^s cCsti|ƒiiddƒ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 exponentialuE(RR RR(R((s1/usr/lib/python2.6/site-packages/babel/numbers.pytget_exponential_symboljs cCsti|ƒiiddƒ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.6/site-packages/babel/numbers.pytget_group_symbolvs 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.6/site-packages/babel/numbers.pyR‚s cCsHti|ƒ}|p|ii|ƒ}nt|ƒ}|i||ƒ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(RtformatRtpattern((s1/usr/lib/python2.6/site-packages/babel/numbers.pyRs  cCsNti|ƒ}|p|ii|ƒ}nt|ƒ}|i||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"(RRR#RR$((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR°s  cCsHti|ƒ}|p|ii|ƒ}nt|ƒ}|i||ƒ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"(RR#RR$((s1/usr/lib/python2.6/site-packages/babel/numbers.pyRËs  cCsHti|ƒ}|p|ii|ƒ}nt|ƒ}|i||ƒ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"(RR#RR$((s1/usr/lib/python2.6/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.6/site-packages/babel/numbers.pyR þscCsJy t|it|ƒdƒƒSWn#tj otd|ƒ‚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.6/site-packages/babel/numbers.pyRs cCskti|ƒ}y2t|it|ƒdƒit|ƒdƒƒSWn#tj otd|ƒ‚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 (R/R((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR s s [^0-9@#.,]s [0-9@#.\-,E+]s(?P(?:'[^']*'|%s)*)s(?P%s+)s(?P.*)s%s%s%scCs‘to t|tƒot|ƒ}nd|idƒ}d|jo3|iddƒ\}}|djo d}q‡n|d}}||fS(s=Convert a number into a (intasstring, fractionasstring) tuples%.9ft0R0iR+(t have_decimalt isinstanceRtstrtrstriptsplit(tvaluettexttatb((s1/usr/lib/python2.6/site-packages/babel/numbers.pyt split_numberDs   ic Cs3t|djƒodpd}t|ƒ}t|ƒ\}}||}d}t|ƒ|}|djp|t|ƒjonL||djo d}n1||djo||ddjo d}nd|}to1t|tƒo!tt|||ƒƒ||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<tlenR3R4RR1( R8tndigitstsignR:R;tdigitstaddtitscale((s1/usr/lib/python2.6/site-packages/babel/numbers.pyt bankersroundRs      &  !c Cst|tƒo|Sd|joX|iddƒ\}}ti|ƒiƒ\}}}ti|ƒiƒ\}}}n/ti|ƒiƒ\}}}d|}|}d|jo|iddƒ\}}nd}d|jo.d|jod|jotdƒ‚qnd|jo|iddƒ\} } n |} d } d } } d „} d „}| | ƒ}| | ƒ}|o>| | | ƒ}|i d ƒ}|i d ƒ}| |ƒ}n d}d}|| ƒ}t|||f||f|||||ƒS(sParse number format patternst;it-tEt@R0R2s5Significant digit patterns can not contain "@" or "0"R+icSszd}}xc|D][}|djo|d7}|d7}q|djo|d7}q|djoqqPqW||fS(s(Calculate the min and max allowed digitsis@0it#t,((tptmintmaxtc((s1/usr/lib/python2.6/site-packages/babel/numbers.pytparse_precisions     cSs‡t|ƒ}|idƒ}|djodS||d}|| d idƒ}|djo ||fS|||d}||fS(sÉParse primary and secondary digit grouping >>> parse_grouping('##') 0, 0 >>> parse_grouping('#,###') 3, 3 >>> parse_grouping('#,####,###') 3, 4 RNiÿÿÿÿièii(ièiè(RAtrfind(ROtwidthtg1tg2((s1/usr/lib/python2.6/site-packages/babel/numbers.pytparse_groupingŸs    t+N( R4t NumberPatternR7t number_retsearchtgroupstNoneR.trsplitt startswithtlstrip(R$t neg_patternt pos_prefixRt pos_suffixt neg_prefixt_t neg_suffixtexptintegertfractiontmin_fractmax_fracRSRXtint_prect frac_prectexp_plustexp_prectgrouping((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR!ssH "           RZcBsAeZd„Zd„Zdd„Zd„Zd„Zd„ZRS(c Cs¯||_||_||_||_||_||_||_||_ddi|i|iƒjo d|_ n7ddi|i|iƒjo d|_ n d|_ dS(Nt%R+idu‰ièi( R$tprefixtsuffixRqRmRnRpRotjoinRG( tselfR$RsRtRqRmRnRpRo((s1/usr/lib/python2.6/site-packages/babel/numbers.pyt__init__Çs            cCsdt|ƒi|ifS(Ns<%s %r>(ttypeR(R$(Rv((s1/usr/lib/python2.6/site-packages/babel/numbers.pyt__repr__Øsc Csj||i9}t|djƒ}|io©t|ƒ}|o%ttiti|dƒƒƒ}nd}|id|idjo||idd8}n5|ido&t|ƒ|id|id}nt pt |t ƒ ot |ƒ}n|djo|d| }n|d|}d}|djot |ƒ}n|i ot|ƒ}nt|ƒ}d|i||id|idƒt|ƒ||it|ƒ|id|id|ƒf}n0d|ijo¨|it|ƒ|id|idƒ}d|joV|idƒ\} } |i| dd|ƒ} | ot|ƒ| } n| | }q|i|dd|ƒ}nxttt|ƒ|idƒƒ\} } | pd } |i| |id|id|ƒ} |i| |ƒ} | | }d |i|||i|f} d | jo7| id |iƒƒ} | id t||ƒƒ} n| S( Nii iR+u%s%s%s%sRLR0ièR2u%s%s%su¤u¤¤(RGR?RpR@tmathtfloortlogRmR3R4RR1RRoRt_format_sigdigRnRt _format_intR5R$R7RR<RHt _format_fracRsRtR-tupperR( RvR8RRt is_negativeRhtexp_signRR9R:R;tretval((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR"Ûsh   %&           cCst|ƒ\}}t|ƒ}|djoC|djo6d}x-|idƒo|d}|d8}qAWntt|||ƒƒ\}}t||idƒƒ}|p d}nt|ƒ|jo|djo|S||jo|d||7}n|od||fS|S(s‡Convert value to a string. The resulting string will contain between (min, max) number of significant digits. R2R+iis%s.%s(R<RAR`RHRa(RvR8RPRQR:R;t ndecimalsRD((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR}s&     c Csœt|ƒ}||jod|||}n|id}d}t|ƒ}xCt|ƒ|jo/||| |}|| }|id}qQW||S(NR2iR+i(RARqR( RvR8RPRQRRUtgsizetrettsymbol((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR~1s     cCsÀ|i\}}t|ƒ|jo|d|t|ƒ7}n|djp |djot|ƒdjodSt|ƒ}x3t|ƒ|jo|ddjo|d }qWt|ƒ|S(NR2iR+iÿÿÿÿ(RnRAR?R(RvR8RRPRQRU((s1/usr/lib/python2.6/site-packages/babel/numbers.pyR>s- $N( R(R)RwRyR^R"R}R~R(((s1/usr/lib/python2.6/site-packages/babel/numbers.pyRZÅs    <  (,R*RztreRRtTrueR3t ImportErrortFalset babel.coreRRt__all__t __docformat__R RRRRRRRRR^RRRRR.R RR t PREFIX_ENDt NUMBER_TOKENtPREFIX_PATTERNtNUMBER_PATTERNtSUFFIX_PATTERNtcompileR[R<RHR!tobjectRZ(((s1/usr/lib/python2.6/site-packages/babel/numbers.pytsN                  ! R