o
    ßdT×  ã                   @   sº   d Z ddlZddlmZ ddlmZ ddlmZm	Z
mZ dd„ Zd	d
„ Zdd„ dD ƒZe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒfZd dd„Zdd„ Zdd„ ZdS )!z!Humanizing functions for numbers.é    N)ÚFractioné   )Úcompat)ÚgettextÚgettext_noopÚpgettextc                 C   s¬   zt | ƒ} W n ttfy   |  Y S w tddƒtddƒtddƒtddƒtd	dƒtd
dƒtddƒtddƒtddƒtddƒf
}| d dv rLd| |d f S d| || d  f S )z×Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
    3 is '3rd', etc. Works for any integer or anything int() will turn into an
    integer.  Anything other value will have nothing done to it.Ú0ÚthÚ1ÚstÚ2ÚndÚ3ÚrdÚ4Ú5Ú6Ú7Ú8Ú9éd   )é   é   é   z%d%sr   é
   )ÚintÚ	TypeErrorÚ
ValueErrorÚP_)ÚvalueÚt© r!   úA/var/www/html/env/lib/python3.10/site-packages/humanize/number.pyÚordinal   s&   ÿ÷
r#   c              	   C   sp   zt | tjƒrt|  dd¡ƒ nt| ƒ W n ttfy"   |  Y S w t| ƒ}t 	dd|¡}||kr4|S t
|ƒS )zêConverts an integer to a string containing commas every three digits.
    For example, 3000 becomes '3,000' and 45000 becomes '45,000'.  To maintain
    some compatability with Django's intcomma, this function also accepts
    floats.ú,Ú z^(-?\d+)(\d{3})z\g<1>,\g<2>)Ú
isinstancer   Ústring_typesÚfloatÚreplacer   r   ÚstrÚreÚsubÚintcomma)r   ÚorigÚnewr!   r!   r"   r-   #   s   €ÿr-   c                 C   s   g | ]}d | ‘qS )r   r!   )Ú.0Úxr!   r!   r"   Ú
<listcomp>6   s    r2   )é   é	   r   é   é   é   é   é   é   é!   r   ÚmillionÚbillionÚtrillionÚquadrillionÚquintillionÚ
sextillionÚ
septillionÚ	octillionÚ	nonillionÚ	decillionÚgoogolú%.1fc              	   C   sž   zt | ƒ} W n ttfy   |  Y S w | td k rt| ƒS ttdd… dƒD ]#\}}| |k rJ| tt|d  ƒ }d |tt	|d  ƒg¡|   S q't| ƒS )aâ  Converts a large integer to a friendly text representation. Works best for
    numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
    becomes '1.2 million' and '1200000000' becomes '1.2 billion'.  Supports up to
    decillion (33 digits) and googol (100 digits).  You can pass format to change
    the number of decimal or general format of the number portion.  This function
    returns a string unless the value passed was unable to be coaxed into an int.r   r   Nú )
r   r   r   Úpowersr*   Ú	enumerater(   ÚjoinÚ_Úhuman_powers)r   Úformatr#   ÚpowerÚchoppedr!   r!   r"   Úintword<   s   ÿ"þrQ   c              
   C   sŽ   zt | ƒ} W n ttfy   |  Y S w d|   k r!dk s&t| ƒS  t| ƒS tdƒtdƒtdƒtdƒtdƒtdƒtd	ƒtd
ƒtdƒf	| d  S )z×For numbers 1-9, returns the number spelled out. Otherwise, returns the
    number. This follows Associated Press style.  This always returns a string
    unless the value was not int-able, unlike the Django filter.r   r   ÚoneÚtwoÚthreeÚfourÚfiveÚsixÚsevenÚeightÚniner   )r   r   r   r*   rL   )r   r!   r!   r"   ÚapnumberQ   s   ÿÿ$ÿÿr[   c              	   C   s„   zt | ƒ}W n ttfy   |  Y S w t|ƒ}t|| ƒ d¡}|j}|j}|r3|s3|dkr3d| S |s;d||f S d|||f S )as  
    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 whole number
        or a mixed fraction
    Examples:
        fractional(0.3) will return '1/3'
        fractional(1.3) will return '1 3/10'
        fractional(float(1/3)) will return '1/3'
        fractional(1) will return '1'
    This will always return a string.
    iè  r   z%.0fz	%.0f/%.0fz%.0f %.0f/%.0f)r(   r   r   r   r   Úlimit_denominatorÚ
_numeratorÚ_denominator)r   ÚnumberÚwholeNumberÚfracÚ	numeratorÚdenominatorr!   r!   r"   Ú
fractional_   s   ÿrd   )rG   )Ú__doc__r+   Ú	fractionsr   r%   r   Úi18nr   rL   r   ÚN_r   r   r#   r-   rI   rM   rQ   r[   rd   r!   r!   r!   r"   Ú<module>   s   þ
