ifj?DUdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZdd l mZdd l mZe rejd krdd lmZndd lmZd Zded<d?dZd@dAdZdBdCdZddDZeddeddedded d ed!d!ed"d"ed#d#ed$d$ed%d%ed&d&ed'd'ed(d(f ZdDdEd+ZdFd,ZdFd-Z dGdHd1Z! dIdJd:Z"dKdLd>Z#dS)Mz!Humanizing functions for numbers.) annotationsN)Fraction) TYPE_CHECKING)_gettext) _ngettextdecimal_separatorthousands_separator)_ngettext_noop) _pgettext) ) TypeAliasz float | strrNumberOrStringvaluefloatreturnstrctj|rdStj|r|dkrdStj|r|dkrdSdS)z2Utility function to handle infinite and nan cases.NaNrz-Infz+Inf)mathisnanisinfrs o/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/humanize/number.py_format_not_finiters\ z%u z%UQYYv z%UQYYv 2malegenderc  tjt|stt|St |}n&#t t f$rt|cYSwxYw|dkrtddtddtddtdd td dtd dtd dtd dtddtddf }ntddtddtddtdd tddtddtddtddtddtddf }|dzdvr ||dS|||dzS)akConverts an integer to its ordinal as a string. For example, 1 is "1st", 2 is "2nd", 3 is "3rd", etc. Works for any integer or anything `int()` will turn into an integer. Anything else will return the output of str(value). Examples: ```pycon >>> ordinal(1) '1st' >>> ordinal(1002) '1002nd' >>> ordinal(103) '103rd' >>> ordinal(4) '4th' >>> ordinal(12) '12th' >>> ordinal(101) '101st' >>> ordinal(111) '111th' >>> ordinal("something else") 'something else' >>> ordinal([1, 2, 3]) == "[1, 2, 3]" True ``` Args: value (int, str, float): Integer to convert. gender (str): Gender for translations. Accepts either "male" or "female". Returns: str: Ordinal string. rz0 (male)thz1 (male)stz2 (male)ndz3 (male)rdz4 (male)z5 (male)z6 (male)z7 (male)z8 (male)z9 (male)z 0 (female)z 1 (female)z 2 (female)z 3 (female)z 4 (female)z 5 (female)z 6 (female)z 7 (female)z 8 (female)z 9 (female)d) rr) risfiniterrint TypeError ValueErrorrP_)rr ts rordinalr0%sJ}U5\\** 4%eEll33 3E  z "5zz  z4 z4 z4 z4 z4 z4 z4 z4 z4 z4   |T " " |T " " |T " " |T " " |T " " |T " " |T " " |T " " |T " " |T " "  s{l""1 $Qurz] $ $$>> intcomma(100) '100' >>> intcomma("1000") '1,000' >>> intcomma(1_000_000) '1,000,000' >>> intcomma(1_234_567.25) '1,234,567.25' >>> intcomma(1234.5454545, 2) '1,234.55' >>> intcomma(14308.40, 1) '14,308.4' >>> intcomma("14308.40", 1) '14,308.4' >>> intcomma(None) 'None' ``` Args: value (int, float, str): Integer or float to convert. ndigits (int, None): Digits of precision for rounding after the decimal point. Returns: str: String containing commas every three digits. r.Nz {0:.{1}f}Tz^(-?\d+)(\d{3})z\g<1>z\g<2>)r r isinstancerreplacerr*rrr+r,r-formatresub)rr2 thousands_sep decimal_seporignews rintcommar?osD())M#%%K eS ! ! MM-44<<[#NNE=u.. 8)%,,777e||e E =u.. 8)%,,777 %LLL z "5zz!!%115zz <<[ ) )Df')F-)F)F)FMM 3;;J sA;D A D ;D D.-D.cg|]}d|zS)r).0xs r rDs H H HA"a% H H Hr) r  r(!r&thousandmillionbilliontrillion quadrillion quintillion sextillion septillion octillion nonillion decilliongoogol%.1fr8c  tjt|stt|St |}n&#t t f$rt|cYSwxYw|dkr|dz}d}nd}|tdkr|t|zSttdddD]!\}}||kr|tt|dz z }t|t|dz z }t||z|krm|tt|z }t|\}}|d |t||tj |gz|zcSt|dz \}}|d |t||tj |gz|zcS#|t|zS)aConverts a large integer to a friendly text representation. Works best for numbers over 1 million. For example, 1_000_000 becomes "1.0 million", 1200000 becomes "1.2 million" and "1_200_000_000" becomes "1.2 billion". Supports up to decillion (33 digits) and googol (100 digits). Examples: ```pycon >>> intword("100") '100' >>> intword("12400") '12.4 thousand' >>> intword("1000000") '1.0 million' >>> intword(1_200_000_000) '1.2 billion' >>> intword(8100000000000000000000000000000000) '8.1 decillion' >>> intword(None) 'None' >>> intword("1234000", "%0.3f") '1.234 million' ``` Args: value (int, float, str): Integer to convert. format (str): To change the number of decimal or general format of the number portion. Returns: str: Friendly text representation as a string, unless the value passed could not be coaxed into an `int`. r-rrN )rr*rrr+r,r-rpowers enumerate human_powersjoinrceil) rr8negative_prefixordinal_powerchoppedpowers_differencesingularplurals rintwordrksF}U5\\** 4%eEll33 3E  z "5zz qyy   vayU++$VABBZ33% 5==eF8a<$8999G &x 06(Q,3G G Vg%&&*;;;%x(8"9"99#/#9 &#hh8VTYw=O=O!P!PQ  ,HqL9 Hf((FIh '@R@R$S$STUUV    & SZZ ''r1c N tjt|stt|St |}n&#t t f$rt|cYSwxYwd|cxkrdksnt|Stdtdtdtdtdtdtd td td td f |S) aJConverts an integer to Associated Press style. Examples: ```pycon >>> apnumber(0) 'zero' >>> apnumber(5) 'five' >>> apnumber(10) '10' >>> apnumber("7") 'seven' >>> apnumber("foo") 'foo' >>> apnumber(None) 'None' ``` Args: value (int, float, str): Integer to convert. Returns: str: For numbers 0-9, the number spelled out. Otherwise, the number. This always returns a string unless the value was not `int`-able, then `str(value)` is returned. rrzeroonetwothreefourfivesixseveneightnine) rr*rrr+r,r-r_rs rapnumberrx s8}U5\\** 4%eEll33 3E  z "5zz ????????5zz &  % % '  &  &  % '  '  &     r1c t|}tj|st|Sn&#tt f$rt |cYSwxYwt|}t||z  d}|j }|j }|r |s |dkr|dS|s |dd|dS|dd|dd|dS)aConvert to fractional number. There will be some cases where one might not want to show ugly decimal places for floats and decimals. This function returns a human-readable fractional number in form of fractions and mixed fractions. Pass in a string, or a number or a float, and this function returns: * a string representation of a fraction * or a whole number * or a mixed fraction * or the str output of the value, if it could not be converted Examples: ```pycon >>> fractional(0.3) '3/10' >>> fractional(1.3) '1 3/10' >>> fractional(float(1/3)) '1/3' >>> fractional(1) '1' >>> fractional("ten") 'ten' >>> fractional(None) 'None' ``` Args: value (int, float, str): Integer to convert. Returns: str: Fractional number as a string. irz.0f/r^) rrr*rr,r-rr+rlimit_denominator numerator denominator)rnumber whole_numberfracr|r}s r fractionalr<sNu}V$$ .%f-- - . z "5zzv;;L F\) * * < >> scientific(float(0.3)) '3.00 x 10⁻¹' >>> scientific(int(500)) '5.00 x 10²' >>> scientific(-1000) '-1.00 x 10³' >>> scientific(1000, 1) '1.0 x 10³' >>> scientific(1000, 3) '1.000 x 10³' >>> scientific("99") '9.90 x 10¹' >>> scientific("foo") 'foo' >>> scientific(None) 'None' ``` Args: value (int, float, str): Input number. precision (int): Number of decimal for first part of the number. Returns: str: Number in scientific notation z.wq x 10ⁿ. u⁰¹²³u⁴u⁵u⁶u⁷u⁸u⁹u⁻) 0123456789r]z{:.%se}ez^\+?(\-?)0*(.+)$z\1\2z x 10r)rrr*rr-r,rr+r8splitr9r:appendrb) rr exponentsfmtnpart1part2 new_part2char final_strs r scientificrxs8@            Ie }U## -%e,, , -  "5zz c#i..)) )C 5A773<floor float | Nonerc floor_token ceil_tokenc>|dStj|st|S| ||kr|}|}n| ||kr|}|}nd}t|tr|||zSt |r|||zSd}t|)aReturns number with the specified format, clamped between floor and ceil. If the number is larger than ceil or smaller than floor, then the respective limit will be returned, formatted and prepended with a token specifying as such. Examples: ```pycon >>> clamp(123.456) '123.456' >>> clamp(0.0001, floor=0.01) '<0.01' >>> clamp(0.99, format="{:.0%}", ceil=0.99) '99%' >>> clamp(0.999, format="{:.0%}", ceil=0.99) '>99%' >>> clamp(1, format=intword, floor=1e6, floor_token="under ") 'under 1.0 million' >>> clamp(None) is None True ``` Args: value (int, float): Input number. format (str OR callable): Can either be a formatting string, or a callable function that receives value and returns a string. floor (int, float): Smallest value before clamping. ceil (int, float): Largest value before clamping. floor_token (str): If value is smaller than floor, token will be prepended to output. ceil_token (str): If value is larger than ceil, token will be prepended to output. Returns: str: Formatted number. The output is clamped between the indicated floor and ceil. If the number is larger than ceil or smaller than floor, the output will be prepended with a token indicating as such. NrzpInvalid format. Must be either a valid formatting string, or a function that accepts value and returns a string.)rr*rr6rr8callabler-)rr8rrcrrtokenmsgs rclamprs^ }t =  )!%((( UU]] edll&#,v}}U++++%vve}}$$ 3 S//rrr unitc tj|st|S|dkr@ttjtjt |nd}|dks|dkrt||dz |zS|d|dzdzzz}|dkrd|dzdz }n|dkrd| dz dz}nd }t|d ||dzz dz z}|s|r|d vrd }nd }||||S) uReturn a value with a metric SI unit-prefix appended. Examples: ```pycon >>> metric(1500, "V") '1.50 kV' >>> metric(2e8, "W") '200 MW' >>> metric(220e-6, "F") '220 μF' >>> metric(1e-14, precision=4) '10.00 f' ``` The unit prefix is always chosen so that non-significant zero digits are required. i.e. `123,000` will become `123k` instead of `0.123M` and `1,230,000` will become `1.23M` instead of `1230K`. For numbers that are either too huge or too tiny to represent without resorting to either leading or trailing zeroes, it falls back to `scientific()`. ```pycon >>> metric(1e40) '1.00 x 10⁴⁰' ``` Args: value (int, float): Input number. unit (str): Optional base unit. precision (int): The number of digits the output should contain. Returns: str: rrMirrr kMGTPEZYRQu mμnpfazyrqrz.%if)°u′u″r^) rr*rr+rlog10absrr8)rrrexponentrevalue_spaces rmetricrsAF =  )!%(((:?1**s4:djU4455666!H2~~C%Q//$66 RHMA% &&E1}}A  12 A 8)a-A!56 E6Y(Q,%?!%CD E EF H)=!=!= -e -X -t - --r)rrrr)r)rrr rrr)N)rrr2r3rr)rZ)rrr8rrr)rrrr)r)rrrr+rr)rNNrr)rrr8rrrrcrrrrrrr)rr )rrrrrr+rr)$__doc__ __future__rrr9sys fractionsrtypingri18nrrwrr r r NS_r r. version_infortyping_extensionsr__annotations__rr0r?r_rarkrxrrrrrArrrs'''""""""  CCCCCCCCCC''''''!!!!!!0 7""$$$$$$$//////*))))G%G%G%G%G%T=====@ I HG H H HC JC 9C 9C JC }%%C }%%C l##C l##C [!!C [!!C [!!C(  G(G(G(G(G(T/ / / / d9C9C9C9Cx>>>>>F HHHHHV7.7.7.7.7.7.7.r