U
    ‰dy  ã                   @  s8   d Z ddlmZ ddddœZdd	d
d
dddœdd„ZdS )z$Bits and bytes related humanization.é    )Úannotations)z kBz MBz GBz TBz PBz EBz ZBz YB)z KiBz MiBz GiBz TiBz PiBz EiBz ZiBz YiBZKMGTPEZY)ÚdecimalÚbinaryÚgnuFú%.1fzfloat | strÚboolÚstr)Úvaluer   r   ÚformatÚreturnc                 C  sÂ   |rt d }n|rt d }nt d }|s,|r0dnd}t| ƒ}t|ƒ}|dkrX|sXd| S ||k rl|sld| S ||k r€|r€d	| S t|ƒD ] \}}	||d
  }
||
k rˆ qªqˆ||| |
  |	 }|S )aO  Format a number of bytes like a human readable filesize (e.g. 10 kB).

    By default, decimal suffixes (kB, MB) are used.

    Non-GNU modes are compatible with jinja2's `filesizeformat` filter.

    Examples:
        ```pycon
        >>> naturalsize(3000000)
        '3.0 MB'
        >>> naturalsize(300, False, True)
        '300B'
        >>> naturalsize(3000, False, True)
        '2.9K'
        >>> naturalsize(3000, False, True, "%.3f")
        '2.930K'
        >>> naturalsize(3000, True)
        '2.9 KiB'
        >>> naturalsize(10**28)
        '10000.0 YB'
        >>> naturalsize(-4096, True)
        '-4.0 KiB'

        ```
    Args:
        value (int, float, str): Integer to convert.
        binary (bool): If `True`, uses binary suffixes (KiB, MiB) with base
            2<sup>10</sup> instead of 10<sup>3</sup>.
        gnu (bool): If `True`, the binary argument is ignored and GNU-style
            (`ls -sh` style) prefixes are used (K, M) with the 2**10 definition.
        format (str): Custom formatter.

    Returns:
        str: Human readable representation of a filesize.
    r   r   r   i   iè  é   z%d Bytez%d Bytesz%dBé   )ÚsuffixesÚfloatÚabsÚ	enumerate)r	   r   r   r
   ÚsuffixÚbaseZbytes_Z	abs_bytesÚiÚsÚunitÚret© r   ú5/tmp/pip-unpacked-wheel-kd4adnh7/humanize/filesize.pyÚnaturalsize   s(    )

r   N)FFr   )Ú__doc__Ú
__future__r   r   r   r   r   r   r   Ú<module>   s   ý	   ü