jffdZddlmZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z mZmZddlmZerddlmZedZGd d eZdmdndZdmdodZdmdpdZdmdqdZdefdrdZefdsdZdtdZdefdrdZe dudvd)Ze dudwd,Z dxdyd0Zefdzd1Z efdzd2Z!efdzd3Z"efdzd4Z#efdzd5Z$efdzd6Z%efd{d9Z&d|d;Z'd}d>Z(ded-d-fd~dCZ)dDeddEddIZ*ddNZ+GdOdPe,Z-ded-dQd-d-fddTZ.ded-dQd-d-fddUZ/dDeddEddWZ0ded-d-fd~dXZ1ded-fddYZ2GdZd[e3Z4efdd]Z5ed.fdd_Z6d`Z7daZ8dbe7zZ9dce8zZ:ddZ;ej<e9e:e;Z=ddgZ>ddkZ?GdldjZ@dS)a babel.numbers ~~~~~~~~~~~~~ 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`` :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details. ) annotationsN) TYPE_CHECKINGAnycastoverload)Localedefault_locale get_global)LocaleDataDict)Literal LC_NUMERICceZdZdZddZdS) UnknownCurrencyErrorzRException thrown when a currency is requested for which no data is available. identifierstrreturnNonecRt|d|d||_dS)zkCreate the exception. :param identifier: the identifier string of the unsupported currency zUnknown currency .N) Exception__init__r)selfrs m/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/babel/numbers.pyrzUnknownCurrencyError.__init__)s3 4!DZ!D!D!DEEE%N)rrrr)__name__ __module__ __qualname____doc__rrrrr%s2%%%%%%rrlocaleLocale | str | Nonerset[str]c|r,tj|j}nt d}t |S)aM Return a `set` of normalized currency codes. .. versionadded:: 2.5.0 :param locale: filters returned currency codes by the provided locale. Expected to be a locale instance or code. If no locale is provided, returns the list of all currencies from all locales. all_currencies)rparse currencieskeysr set)r r&s rlist_currenciesr)3sF2\&))499;;  011 z??rcurrencyrrcF|t|vrt|dS)a Check the currency code is recognized by Babel. Accepts a ``locale`` parameter for fined-grained validation, working as the one defined above in ``list_currencies()`` method. Raises a `UnknownCurrencyError` exception if the currency is unknown to Babel. N)r)rr*r s rvalidate_currencyr-Es-v...."8,,,/.rboolc~|rt|tsdS t||n#t$rYdSwxYwdS)zy Returns `True` only if a currency is recognized by Babel. This method always return a Boolean and never raise. FT) isinstancerr-rr,s r is_currencyr1Qsa :h44u(F++++ uu 4s , :: str | Nonec|t|tr|}t||sdS|S)zReturns the normalized identifier of any currency code. Accepts a ``locale`` parameter for fined-grained validation, working as the one defined above in ``list_currencies()`` method. Returns None if the currency is unknown to Babel. N)r0rupperr1r,s rnormalize_currencyr5_sA(C  $>>## x ( ( Orcountfloat | decimal.Decimal | Nonec&tj|}|a ||}n#ttf$rd}YnwxYw|jd}||vr ||}||vr||Sd|vr|dS|j||S)aReturn the name used by the locale for the specified currency. >>> get_currency_name('USD', locale='en_US') u'US Dollar' .. versionadded:: 0.9.4 :param currency: the currency code. :param count: the optional count. If provided the currency name will be pluralized to that number if possible. :param locale: the `Locale` object or locale identifier. Nothercurrency_names_plural)rr% plural_form OverflowError ValueError_datar&get)r*r6r locr; plural_namescurrency_plural_namess rget_currency_namerCns" ,v  C  "//%00KKz* " " "!KKK "y!89 | # #$0$: !333,[99///,W55 >  h 1 11s.AAc\tj|j||S)zReturn the symbol used by the locale for the specified currency. >>> get_currency_symbol('USD', locale='en_US') u'$' :param currency: the currency code. :param locale: the `Locale` object or locale identifier. )rr%currency_symbolsr?r,s rget_currency_symbolrFs' <   0 4 4Xx H HHrintcdtd}|||ddS)zReturn currency's precision. Precision is the number of decimals found after the decimal point in the currency's format pattern. .. versionadded:: 2.5.0 :param currency: the currency code. currency_fractionsDEFAULTr)r r?)r* precisionss rget_currency_precisionrLs0011J >>(Jy$9 : :1 ==rctj|}|9||} |jd|S#t$rYnwxYw|jddS)aV Return the unit pattern used for long display of a currency value for a given locale. This is a string containing ``{0}`` where the numeric part should be substituted and ``{1}`` where the currency long display name should be substituted. >>> get_currency_unit_pattern('USD', locale='en_US', count=10) u'{0} {1}' .. versionadded:: 2.7.0 :param currency: the currency code. :param count: the optional count. If provided the unit pattern for that number will be returned. :param locale: the `Locale` object or locale identifier. Ncurrency_unit_patternsr9)rr%r;r> LookupError)r*r6r r@r;s rget_currency_unit_patternrPsw, ,v  C ooe,,  956{C C    D  9- .w 77sA A  A . territory start_datedatetime.date | Noneend_datetender non_tenderinclude_detailsLiteral[False] list[str]cdSNrrQrRrTrUrVrWs rget_territory_currenciesr] Cr Literal[True]list[dict[str, Any]]cdSr[rr\s rr]r]r^rTF list[str] | list[dict[str, Any]]cltd}tjn.t tjrn.t tjr||d}fd}g} |D]m\} } } } | rtj| } | rtj| } | r|s| s@|r>|| | r2|r| | | | | dX| | n| S)asReturns the list of currencies for the given territory that are valid for the given date range. In addition to that the currency database distinguishes between tender and non-tender currencies. By default only tender currencies are returned. The return value is a list of all currencies roughly ordered by the time of when the currency became active. The longer the currency is being in use the more to the left of the list it will be. The start date defaults to today. If no end date is given it will be the same as the start date. Otherwise a range can be defined. For instance this can be used to find the currencies in use in Austria between 1995 and 2011: >>> from datetime import date >>> get_territory_currencies('AT', date(1995, 1, 1), date(2011, 1, 1)) ['ATS', 'EUR'] Likewise it's also possible to find all the currencies in use on a single date: >>> get_territory_currencies('AT', date(1995, 1, 1)) ['ATS'] >>> get_territory_currencies('AT', date(2011, 1, 1)) ['EUR'] By default the return value only includes tender currencies. This however can be changed: >>> get_territory_currencies('US') ['USD'] >>> get_territory_currencies('US', tender=False, non_tender=True, ... start_date=date(2014, 1, 1)) ['USN', 'USS'] .. versionadded:: 2.0 :param territory: the name of the territory to find the currency for. :param start_date: the start date. If not given today is assumed. :param end_date: the end date. If not given the start date is assumed. :param tender: controls whether tender currencies should be included. :param non_tender: controls whether non-tender currencies should be included. :param include_details: if set to `True`, instead of returning currency codes the return value will be dictionaries with detail information. In that case each dictionary will have the keys ``'currency'``, ``'from'``, ``'to'``, and ``'tender'``. territory_currenciesNrc,|dus|ko |dup|kSr[r)startendrTrRs r _is_activez,get_territory_currencies.._is_active)s/ 2(!22t 0sj0 2r)r*fromtorU)r datetimedatetodayr0r?r4append)rQrRrTrUrVrWr&cursrhresult currency_coderfrg is_tenders `` rr]r]sr233J]((** J 1 2 2'__&&  Hh/ 0 0#==?? >>)//++R 0 0D222222F04--, uc9  *M5)E  &-%C  -6 - -#- -4>Juc4J4J - - -!'  m,,, Mrc\tj|jddS)zReturn the symbol used by the locale to separate decimal fractions. >>> get_decimal_symbol('en_US') u'.' :param locale: the `Locale` object or locale identifier decimalrrr%number_symbolsr?r s rget_decimal_symbolrxBs' <   . 2 29c B BBrc\tj|jddS)zReturn the plus sign symbol used by the current locale. >>> get_plus_sign_symbol('en_US') u'+' :param locale: the `Locale` object or locale identifier plusSign+rurws rget_plus_sign_symbolr|Ms' <   . 2 2:s C CCrc\tj|jddS)zReturn the plus sign symbol used by the current locale. >>> get_minus_sign_symbol('en_US') u'-' :param locale: the `Locale` object or locale identifier minusSign-rurws rget_minus_sign_symbolrXs' <   . 2 2; D DDrc\tj|jddS)zReturn 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 exponentialErurws rget_exponential_symbolrcs' <   . 2 2=# F FFrc\tj|jddS)zReturn 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 group,rurws rget_group_symbolrns' <   . 2 27C @ @@rc\tj|jddS)uReturn the symbol used by the locale to represent infinity. >>> get_infinity_symbol('en_US') u'∞' :param locale: the `Locale` object or locale identifier infinityu∞rurws rget_infinity_symbolrys' <   . 2 2:u E EErnumberfloat | decimal.Decimal | strcXtjdtt||S)aReturn the given number formatted for a specific locale. >>> format_number(1099, locale='en_US') # doctest: +SKIP u'1,099' >>> format_number(1099, locale='de_DE') # doctest: +SKIP u'1.099' .. deprecated:: 2.6.0 Use babel.numbers.format_decimal() instead. :param number: the number to format :param locale: the `Locale` object or locale identifier z+Use babel.numbers.format_decimal() instead.rw)warningswarnDeprecationWarningformat_decimal)rr s r format_numberrs+" M?ASTTT & 0 0 00rdecimal.Decimalct|tjsJ|}t|jt r |jdkrdSt|jS)zReturn maximum precision of a decimal instance's fractional part. Precision is extracted from the fractional part only. r)r0rtDecimal normalizeas_tupleexponentrGabs)r decimal_tuples rget_decimal_precisionrsr fgo . ... .$$&&//11M m,c 2 2m6LPQ6Q6Qq }% & &&r precisionint | decimal.Decimalcxt|ttjfsJtjd| zS)z>> 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(1.2345, locale='de') u'1,234' The appropriate thousands grouping and the decimal separator are used for each locale: >>> format_decimal(12345.5, locale='en_US') u'12,345.5' By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the `decimal_quantization` parameter: >>> format_decimal(1.2346, locale='en_US') u'1.235' >>> format_decimal(1.2346, locale='en_US', decimal_quantization=False) u'1.2346' >>> format_decimal(12345.67, locale='fr_CA', group_separator=False) u'12345,67' >>> format_decimal(12345.67, locale='en_US', group_separator=True) u'12,345.67' :param number: the number to format :param format: :param locale: the `Locale` object or locale identifier :param decimal_quantization: Truncate and round high-precision numbers to the format pattern. Defaults to `True`. :param group_separator: Boolean to switch group separator on/off in a locale's number format. Nrr)rr%decimal_formats parse_patternapplyrrr rrpatterns rrrs\^\& ! !F ~'/F##G ==-ASb  d ddrshort) format_typer fraction_digitsrLiteral['short', 'long']rctj|}|j|}t||||\}}| |jd}t |}|||dS)uReturn the given decimal number formatted for a specific locale in compact form. >>> format_compact_decimal(12345, format_type="short", locale='en_US') u'12K' >>> format_compact_decimal(12345, format_type="long", locale='en_US') u'12 thousand' >>> format_compact_decimal(12345, format_type="short", locale='en_US', fraction_digits=2) u'12.34K' >>> format_compact_decimal(1234567, format_type="short", locale="ja_JP") u'123万' >>> format_compact_decimal(2345678, format_type="long", locale="mk") u'2 милиони' >>> format_compact_decimal(21000000, format_type="long", locale="mk") u'21 милион' :param number: the number to format :param format_type: Compact format to use ("short" or "long") :param locale: the `Locale` object or locale identifier :param fraction_digits: Number of digits after the decimal point to use. Defaults to `0`. NFr)rr%compact_decimal_formats_get_compact_formatrrr)rrr rcompact_formatrrs rformat_compact_decimalrsn6\& ! !F3K@N(YYNFF ~'-F##G ==e= D DDrrr r,tuple[decimal.Decimal, NumberPattern | None]c t|tjs!tjt|}|s|r|dfSd}t d|dDdD]}t||kr|dt|}t|j }|dkrnttj||d| ddz zzz }t||}| t|}||vrd}|dkrd |vrd }||t|}|}n||fS) zReturns the number after dividing by the unit and the format pattern to use. The algorithm is described here: https://www.unicode.org/reports/tr35/tr35-45/tr35-numbers.html#Compact_Number_Formats. Nc,g|]}t|Sr)rG).0ms r z'_get_compact_format..sEEESVVEEErr9T)reverse0r1)r0rtrris_nan is_infinitesortedrrrrr6roundr;) rrr rr magnituderroundedr;s rrr s fgo . ..V-- }}&,,..t| FEE^G-DEEEtTTT v;;) # ##G,S^^rceZdZdZdS)UnknownCurrencyFormatErrorz>Exception raised when an unknown currency format is requested.N)rrrrrrrrr1sHHHHrrstandardcurrency_digits)Literal['name', 'standard', 'accounting']c |dkrt|||||||Stj|}|rt|}n0 |j|}n!#t $rt |ddwxYw|||||||S)u Return formatted currency value. >>> format_currency(1099.98, 'USD', locale='en_US') '$1,099.98' >>> format_currency(1099.98, 'USD', locale='es_CO') u'US$1.099,98' >>> format_currency(1099.98, 'EUR', locale='de_DE') u'1.099,98\xa0\u20ac' The format can also be specified explicitly. The currency is placed with the '¤' sign. As the sign gets repeated the format expands (¤ being the symbol, ¤¤ is the currency abbreviation and ¤¤¤ is the full name of the currency): >>> format_currency(1099.98, 'EUR', u'¤¤ #,##0.00', locale='en_US') u'EUR 1,099.98' >>> format_currency(1099.98, 'EUR', u'#,##0.00 ¤¤¤', locale='en_US') u'1,099.98 euros' Currencies usually have a specific number of decimal digits. This function favours that information over the given format: >>> format_currency(1099.98, 'JPY', locale='en_US') u'\xa51,100' >>> format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES') u'1.099,98' However, the number of decimal digits can be overridden from the currency information, by setting the last parameter to ``False``: >>> format_currency(1099.98, 'JPY', locale='en_US', currency_digits=False) u'\xa51,099.98' >>> format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES', currency_digits=False) u'1.099,98' If a format is not specified the type of currency format to use from the locale can be specified: >>> format_currency(1099.98, 'EUR', locale='en_US', format_type='standard') u'\u20ac1,099.98' When the given currency format type is not available, an exception is raised: >>> format_currency('1099.98', 'EUR', locale='root', format_type='unknown') Traceback (most recent call last): ... UnknownCurrencyFormatError: "'unknown' is not a known currency format type" >>> format_currency(101299.98, 'USD', locale='en_US', group_separator=False) u'$101299.98' >>> format_currency(101299.98, 'USD', locale='en_US', group_separator=True) u'$101,299.98' You can also pass format_type='name' to use long display names. The order of the number and currency name, along with the correct localized plural form of the currency name, is chosen according to locale: >>> format_currency(1, 'USD', locale='en_US', format_type='name') u'1.00 US dollar' >>> format_currency(1099.98, 'USD', locale='en_US', format_type='name') u'1,099.98 US dollars' >>> format_currency(1099.98, 'USD', locale='ee', format_type='name') u'us ga dollar 1,099.98' By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the `decimal_quantization` parameter: >>> format_currency(1099.9876, 'USD', locale='en_US') u'$1,099.99' >>> format_currency(1099.9876, 'USD', locale='en_US', decimal_quantization=False) u'$1,099.9876' :param number: the number to format :param currency: the currency code :param format: the format string to use :param locale: the `Locale` object or locale identifier :param currency_digits: use the currency's natural number of decimal digits :param format_type: the currency format type to use :param decimal_quantization: Truncate and round high-precision numbers to the format pattern. Defaults to `True`. :param group_separator: Boolean to switch group separator on/off in a locale's number format. name)rr rrrz$ is not a known currency format typeNr*rrr)_format_currency_long_namerr%rcurrency_formatsKeyErrorrr) rr*rr rrrrrs rformat_currencyr5sBf)&(617?Setvvv v\& ! !F o'' o-k:GG o o o, -c-c-cddjn n o ==?1?  T TTs  AA0c\tj|}t|trt |n|}t |||} t |||} |s |j|}t|} | ||||||} | | | S)N)r6r r) rr%r0rfloatrPrCrrrr) rr*rr rrrrnumber_n unit_pattern display_namer number_parts rrrs\& ! !F!+63 7 7CuV}}}VH-XXfUUUL%XXfMMML 0'/F##G--?1? TTK   {L 9 99rLiteral['short']ctj|} |j|}n%#t$r}t |d|d}~wwxYwt ||||\}}|dt |vra|dD]X}|d|j}d|vrtj dd|}tj dd| }|td t|} | |||d d S) uFormat a number as a currency value in compact form. >>> format_compact_currency(12345, 'USD', locale='en_US') u'$12K' >>> format_compact_currency(123456789, 'USD', locale='en_US', fraction_digits=2) u'$123.46M' >>> format_compact_currency(123456789, 'EUR', locale='de_DE', fraction_digits=1) '123,5 Mio. €' :param number: the number to format :param currency: the currency code :param format_type: the compact format type to use. Defaults to "short". :param locale: the `Locale` object or locale identifier :param fraction_digits: Number of digits after the decimal point to use. Defaults to `0`. z, is not a known compact currency format typeN¤r9u [^0\s\¤]z(\s)\s+z\1zANo compact currency format found for the given number and locale.F)r*rr)rr%compact_currency_formatsrrrrrresubstripr=rr) rr*rr rrerrorrrrs rformat_compact_currencyrs8.\& ! !Ft8E ttt(K)g)g)ghhnsst(YYNFF ~S[[00'0  I#G,Y7?F6!!VL"f55FVJv66<<>>F  ~\]]]F##G ==(Ehm= n nns $ AAActj|}|s |j|}t|}|||||S)uDReturn 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‰', locale='en_US') u'25,123‰' By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the `decimal_quantization` parameter: >>> format_percent(23.9876, locale='en_US') u'2,399%' >>> format_percent(23.9876, locale='en_US', decimal_quantization=False) u'2,398.76%' >>> format_percent(229291.1234, locale='pt_BR', group_separator=False) u'22929112%' >>> format_percent(229291.1234, locale='pt_BR', group_separator=True) u'22.929.112%' :param number: the percent number to format :param format: :param locale: the `Locale` object or locale identifier :param decimal_quantization: Truncate and round high-precision numbers to the format pattern. Defaults to `True`. :param group_separator: Boolean to switch group separator on/off in a locale's number format. r)rr%percent_formatsrrrs rformat_percentrs_X\& ! !F 0'/F##G ==-ASb  d ddrctj|}|s |j|}t|}||||S)aReturn 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'##0.##E00', locale='en_US') u'1.23E06' By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the `decimal_quantization` parameter: >>> format_scientific(1234.9876, u'#.##E0', locale='en_US') u'1.23E3' >>> format_scientific(1234.9876, u'#.##E0', locale='en_US', decimal_quantization=False) u'1.2349876E3' :param number: the number to format :param format: :param locale: the `Locale` object or locale identifier :param decimal_quantization: Truncate and round high-precision numbers to the format pattern. Defaults to `True`. r)rr%scientific_formatsrr)rrr rrs rformat_scientificr3s[>\& ! !F 3*62F##G ==-A  C CCrc&eZdZdZd d fd ZxZS) NumberFormatErrorz>Exception raised when a string cannot be parsed into a number.Nmessager suggestionslist[str] | NonerrcXt|||_dSr[)superrr)rrr __class__s rrzNumberFormatError.__init__]s) !!!&rr[)rrrrrr)rrrrr __classcell__)rs@rrrZsHHH'''''''''''rrstringc t|t|dS#t$r}t |d|d}~wwxYw)aSParse localized number string into an integer. >>> parse_number('1,099', locale='en_US') 1099 >>> parse_number('1.099', locale='de_DE') 1099 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 :raise `NumberFormatError`: if the string can not be converted to a number rz is not a valid numberN)rGreplacerr=r)rr ves r parse_numberrcsi(M6>>"26":":B??@@@ MMM6 C C CDD"LMs/2 AAAstrictcltj|}t|}t|}|s$|dkr||vrd|vr|d|} t j||d|d}n*#t j$r}t|d|d}~wwxYw|r||vrt||d}||kr| d ||zkr t j||d|d}t||d} | |krt|d |d |g t|d |d | d || g #t j$r}t|d |d |g |d}~wwxYw|S)akParse localized decimal string into a decimal. >>> parse_decimal('1,099.98', locale='en_US') Decimal('1099.98') >>> parse_decimal('1.099,98', locale='de') Decimal('1099.98') >>> parse_decimal('12 345,123', locale='ru') Decimal('12345.123') 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 If `strict` is set to `True` and the given string contains a number formatted in an irregular way, an exception is raised: >>> parse_decimal('30.00', locale='de', strict=True) Traceback (most recent call last): ... NumberFormatError: '30.00' is not a properly formatted decimal number. Did you mean '3.000'? Or maybe '30,00'? >>> parse_decimal('0.00', locale='de', strict=True) Traceback (most recent call last): ... NumberFormatError: '0.00' is not a properly formatted decimal number. Did you mean '0'? :param string: the string to parse :param locale: the `Locale` object or locale identifier :param strict: controls whether numbers formatted in a weird way are accepted or rejected :raise NumberFormatError: if the string can not be converted to a decimal number   rrz is not a valid decimal numberNF)r rrz: is not a properly formatted decimal number. Did you mean ?)rz ? Or maybe ) rr%rrxrrtrInvalidOperationrrrstrip) rr r group_symboldecimal_symbolparsedexcproper parsed_alt proper_alts r parse_decimalr}sJ\& ! !F#F++L'//N 3F"" v \22V b!A!A(/(D(DFF  #VVV6 K K KLLRUUV ,&((vERRR V   c 2 2v7N O O $_V^^NB-O-O4;GL#4N4NPP ,Jv\abbb ''+!44(.444%+H ,!MM(.MM=GMMM%+Z$8+   '00$*000!'  ( Ms0&B99B><(?:'[^']*'|%s)*)z(?P%s*)z(?P.*)ptuple[int, int]ct|}|d}|dkrdS||z dz }|d| dz d}|dkr||fS||z |z dz }||fS)zParse primary and secondary digit grouping >>> parse_grouping('##') (1000, 1000) >>> parse_grouping('#,###') (3, 3) >>> parse_grouping('#,####,###') (3, 4) r)r rN)lenrfind)rwidthg1g2s rparse_groupingrs FFE B Rxxz aB 8RC!G8  3  B Rxx2v b1 B r6MrrNumberPattern | str NumberPatternc t|tr|Sd}|}d|vr8|dd\}}||\}}}||\}}} n||\}}}d|}|} d|vr|dd\}} nd} d|vrd|vrd |vrtd d|vr|dd\} } n|} d } d } | | }| | }| r6| d }| d } | | }nd}d}t| }t|||f|| f|||||| S)zParse number format patternsct|}|td||S)NzInvalid number pattern ) number_researchr=groups)rrvs r _match_numberz$parse_pattern.._match_numbers?   g & & :BwBBCC Cyy{{r;rrrN@rrz5Significant digit patterns can not contain "@" or "0"rc`dx}}|D]$}|dvr |dz }|dz }|dkr|dz }|dkr$||fS)z(Calculate the min and max allowed digitsrz@0r#rr)rminmaxcs rparse_precisionz&parse_pattern..parse_precisionsc c  ADyyqqcqcCxrr{)r0rsplitr=rsplit startswithlstripr)rr pos_pattern neg_pattern pos_prefixr pos_suffix neg_prefix_ neg_suffixexpintegerfractionr"int_prec frac_precexp_plusexp_precgroupings rrrs'=)) K g~~#*==a#8#8 [)6{)C)C& FJ$1M+$>$>! Azz)6{)C)C& FJ%%%   f}}ll3**  f}}3&==PQQQ f}}"MM#q11   w''H))I >>#&&jjoo"?3''g&&H :z":$j18!9!8V 5 55rcheZdZ d/d0dZd1dZd2dZd3dZ d4d5d%Zd6d)Zd7d,Z d8d-Z d/d9d.Z dS):rNrrprefixtuple[str, str]suffixr5rr1r2r4tuple[int, int] | Noner3 bool | Nonenumber_patternr2rrc ||_||_||_| |_||_||_||_||_||_| |_ dSr[) rr7r9r<r5r1r2r4r3 compute_scalescale) rrr7r9r5r1r2r4r3r<s rrzNumberPattern.__init__3s[   ,    "    '')) rcBdt|jd|jdS)N)typerr)rs r__repr__zNumberPattern.__repr__Ks&:4::&::::::rLiteral[0, 2, 3]cd}dd|j|jzvrd}n&dd|j|jzvrd}|S)uReturn the scaling factor to apply to the number before rendering. Auto-set to a factor of 2 or 3 if presence of a ``%`` or ``‰`` sign is detected in the prefix or suffix of the pattern. Default is to not mess with the scale at all and keep it to 0. r%rr u‰)joinr7r9)rr?s rr>zNumberPattern.compute_scaleNsZ "''$+ 344 4 4EE bggdkDK788 8 8E rvaluerr r! tuple[decimal.Decimal, int, str]c|}|t|z}|dksJtdt|jgdz }||z }|t| z}d}|dkrt |}n|jrt|}t|}|||fS)zG Returns normalized scientific notation components of a value. rrr) adjustedrr rr1rr3r|r)rrJr r. lead_shiftexp_signs rscientific_notation_elementsz*NumberPattern.scientific_notation_elements\snn+C000~~1$$$$ !S//011A5 J+ZK888 77,V44HH ] 4+F33H#hhc8##rTrr*rr.r force_fracrc "t|tjs!tjt|}||j}t |}t| }|j r| ||\}} } |rtj dt|} n|r|rt|fdz} n|j} |r |j r2| dkr,| dt#| dt%|gf} |j rvd|||| |t+|| |t| |j d|j d|g} nd|jvrv|||jd|jd} | d\}}}||dd |} |r| t7||zz } n|||| |} d|j||jdkr| nd|j|g}d |vrs|q|d tA|||}|d |!}|d tE||}tGj$dd|}|S)aRenders into a string a number following the defined pattern. Forced decimal quantization is active by default so we'll produce a number string that is strictly following CLDR pattern definitions. :param value: The value to format. If this is not a Decimal object, it will be cast to one. :type value: decimal.Decimal|float|int :param locale: The locale to use for formatting. :type locale: str|babel.core.Locale :param currency: Which currency, if any, to format as. :type currency: str|None :param currency_digits: Whether or not to use the currency's precision. If false, the pattern's precision is used. :type currency_digits: bool :param decimal_quantization: Whether decimal numbers should be forcibly quantized to produce a formatted output strictly matching the CLDR definition for the locale. :type decimal_quantization: bool :param force_frac: DEPRECATED - a forced override for `self.frac_prec` for a single formatting invocation. :return: Formatted decimal string. :rtype: str z@The force_frac parameter to NumberPattern.apply() is deprecated.r )rrrrrrrr rNu¤¤¤u¤¤z '([^']*)'c0|dpdS)Nr')r)rs rz%NumberPattern.apply..s 0Acr)%r0rtrrscalebr?rG is_signedrrr4rPrrrrLr2r rrI_quantize_valuer _format_intr_format_significantr1 partitionrxr7r<r9rrCr4rFrr)rrJr r*rrrQr is_negativer.rOr2rtextasepbretvals rrzNumberPattern.applywsF%11 0OCJJ//E TZ((%//++,, E $$&& = T#'#D#DUF#S#S E3  ' M\^p q q q"II  '/ '/99>Ds++IAsA%%aD&99F 9,V44q88))%OTTF K $)R//FFR K $&'' 6>>h2^^H.?%QW.X.XYYF^^FHNN,<,<==F^^D*=h*O*OPPF &A&A6JJ rminimumrGmaximumc |}|dz |z }t||t jd}|dkr |d| zz}n|d| }t |} | t|| z dz} d|pddt|dzd || | || d d d}|S)Nrrrz-{intpart}.{pad:0<{fill}}{fracpart}{fracextra}r)intpartpadfillfracpart fracextrar) rMrrVquantizertrr r rrr) rrJrbrcr.r?digitsrpreijs rrZz!NumberPattern._format_significantsnn! c!U\\%((11'/!2D2DEEFF A::cUFl*FFWufWoGG AC! Q'''ADKK3#'1oo%! *++C00 L fSkk  rrr c&t|}||kr d||z z|z}|jd}d}t|}t||kr<||| dz|z}|d| }|jd}t||k<||zS)Nrrrr)r r5r) rrJrr r rgsizeretsymbols rrYzNumberPattern._format_int sE  3;;3;'%/E a !&))%jj5  5%>)C/C'E6'NEM!$E%jj5  s{rcr|rt|St|d}||}|dd\}}} |} |r.|||jd|jd|} | || pd||z} | S)Nrfrrr)rrrrjr[rYr1 _format_frac) rrJr r2rquantumrr^r_r` integer_partrs rrXzNumberPattern._quantize_values      /&v.. .%il33..))NN,,S11 3  [++At}Q/?qAQSYZZL 1 1!(sFI N NN rcf|p|j\}}t||kr|d|t|z zz }|dks|dkrt|dkrdSt||kr5|ddkr)|dd}t||kr |ddk)t||zS)Nrrrr )r2r rGrx)rrJr rQrr s rrtzNumberPattern._format_frac#s/S u::   cS3u::-. /E !88qSZZ1__2%jj359#3#3#2#JE%jj359#3#3!&))E11rr[)rrr7r8r9r8r5rr1rr2rr4r:r3r;r<r2rr)rr)rrE)rJrr r!rrK)NTTNT)rJrr r!r*r2rr.rr.rQr:rr.)rJrrbrGrcrGrr) rJrrrGr rGr r!rr) rJrr r!r2rrr.rr)rJrr r!rQr:rr) rrrrrDr>rPrrZrYrXrtrrrrr1s&******0;;;;    $$$$> $ $%)-1 $iiiii~&        2222222rr[)r r!rr")r*rr r!rr)r*rr r!rr.)r*rr r!rr2)r*rr6r7r r!rr)r*rr r!rr)r*rrrG).....)rQrrRrSrTrSrUr.rVr.rWrXrrY)rQrrRrSrTrSrUr.rVr.rWr_rr`)NNTFF)rQrrRrSrTrSrUr.rVr.rWr.rrb)r r!rr)rrr r!rr)rrrrG)rrrr) rrrrr r!rr.rr.rr) rrrrr r!rrGrr) rrrr r rrrGrr)rrr*rrrr r!rr.rrrr.rr.rr) rrr*rrrr r!rrGrr) rrrrr r!rr.rr)rrr r!rrG)rrr r!rr.rr)rrrr)rrrr)Ar __future__rrkrtrrtypingrrrr babel.corerr r babel.localedatar typing_extensionsr r rrr)r-r1r5rCrFrLrPr]rxr|rrrrrrrrrrrrrrrrrr=rrr PREFIX_END NUMBER_TOKENPREFIX_PATTERNNUMBER_PATTERNSUFFIX_PATTERNcompilerrrrrrrrs<&#""""" 5555555555559999999999++++++*)))))) ^L ) )  % % % % %9 % % %$ - - - - -          "-1",22222BFP I I I I I > > > > -1",88888D (+%(&)   (+%(%(  (,%)! \\\\\~6@CCCCC8BDDDDD9CEEEEE:DGGGGG4>AAAAA7AFFFFFXb11111* ' ' ' '////*.",!% 4d4d4d4d4dt-4", "E"E"E"E"E"EJ%%%%PIIIIIIII*.", =G!% pTpTpTpTpTl*.", =G!% %:%:%:%:%:X%,", ,o,o,o,o,o,ob*.",!% 1d1d1d1d1dl.2&0%) $C$C$C$C$CN''''' '''=GMMMMM4>HX]PPPPPf  /*<#l2" BJ.J.J.JJ K K ,>5>5>5>5Bz2z2z2z2z2z2z2z2z2z2r