o
    †Q `¶  ã                   @   sj   d Z ddlmZ ddlmZ ddlZejrddlmZmZmZ g d¢Z	dd„ Z
d	d
„ Zdd„ Zdd„ ZdS )aŽ  Functions for reporting filesizes.

The functions declared in this module should cover the different
usecases needed to generate a string representation of a file size
using several different units. Since there are many standards regarding
file size units, three different functions have been implemented.

See Also:
    * `Wikipedia: Binary prefix <https://en.wikipedia.org/wiki/Binary_prefix>`_

é    )Údivision)Úunicode_literalsN)ÚIterableÚSupportsIntÚText)ÚtraditionalÚdecimalÚbinaryc                 C   s„   zt | ƒ} W n ty   td | ¡ƒ‚w | dkrdS | |k r$d | ¡S t|dƒD ]\}}|| }| |k r7 nq)d ||  | |¡S )Nz+filesize requires a numeric value, not {!r}é   z1 bytez
{:,} bytesé   z
{:,.1f} {})ÚintÚ
ValueErrorÚ	TypeErrorÚformatÚ	enumerate)ÚsizeÚsuffixesÚbaseÚiÚsuffixZunit© r   ú-/usr/lib/python3/dist-packages/fs/filesize.pyÚ_to_str   s   ÿ
ÿr   c                 C   ó   t | ddƒS )u}  Convert a filesize in to a string (powers of 1024, JDEC prefixes).

    In this convention, ``1024 B = 1 KB``.

    This is the format that was used to display the size of DVDs
    (*700 MB* meaning actually about *734 003 200 bytes*) before
    standardisation of IEC units among manufacturers, and still
    used by **Windows** to report the storage capacity of hard
    drives (*279.4 GB* meaning *279.4 Ã— 1024Â³ bytes*).

    Arguments:
        size (int): A file size.

    Returns:
        `str`: A string containing an abbreviated file size and units.

    Example:
        >>> filesize.traditional(30000)
        '29.3 KB'

    )ZKBÚMBÚGBÚTBÚPBÚEBÚZBÚYBé   ©r   ©r   r   r   r   r   -   ó   r   c                 C   r   )ae  Convert a filesize in to a string (powers of 1024, IEC prefixes).

    In this convention, ``1024 B = 1 KiB``.

    This is the format that has gained adoption among manufacturers
    to avoid ambiguity regarding size units, since it explicitly states
    using a binary base (*KiB = kibi bytes = kilo binary bytes*).
    This format is notably being used by the **Linux** kernel (see
    ``man 7 units``).

    Arguments:
        int (size): A file size.

    Returns:
        `str`: A string containing a abbreviated file size and units.

    Example:
        >>> filesize.binary(30000)
        '29.3 KiB'

    )ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBr!   r"   r#   r   r   r   r	   G   r$   r	   c                 C   r   )a8  Convert a filesize in to a string (powers of 1000, SI prefixes).

    In this convention, ``1000 B = 1 kB``.

    This is typically the format used to advertise the storage
    capacity of USB flash drives and the like (*256 MB* meaning
    actually a storage capacity of more than *256 000 000 B*),
    or used by **Mac OS X** since v10.6 to report file sizes.

    Arguments:
        int (size): A file size.

    Returns:
        `str`: A string containing a abbreviated file size and units.

    Example:
        >>> filesize.decimal(30000)
        '30.0 kB'

    )ZkBr   r   r   r   r   r   r    iè  r"   r#   r   r   r   r   a   s   r   )Ú__doc__Z
__future__r   r   ÚtypingZTYPE_CHECKINGr   r   r   Ú__all__r   r   r	   r   r   r   r   r   Ú<module>   s   