(value)
return ugettext("%s%s PB") % (sign, filesize_number_format(value / PB))
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
Formats the value like a human - readable file size ( i . e . 13 KB 4 . 1 MB 102 bytes etc ) .
def filesizeformat(value):
    if value == 0:
        return '0 bytes'

    """
    Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
    """
    try:
        value = float(value)
    except (TypeError, ValueError, UnicodeDecodeError):
        return '0 bytes'

    def filesize_number_format(value):
        if value < 10:
            return formats.number_format(round(value, 2), 2)
        elif value < 100:
            return formats.number_format(round(value, 2), 1)
        else:
            return formats.number_format(round(value, 1), 0)

    KB = 1 << 10
    MB = 1 << 20
    GB = 1 << 30
    TB = 1 << 40
    PB = 1 << 50

    sign = '-' if value < 0 else ''
    value = abs(value)

    if value == 0:
        return ugettext("0 bytes")
    if value < KB:
        if value != 1:
            return '{sign}{size:d} bytes'.format(sign=sign, size=int(value))
        else:
            return '1 byte'
    if value < MB:
        return ugettext("%s%s KB") % (sign, filesize_number_format(value / KB))
    if value < GB:
        return ugettext("%s%s MB") % (sign, filesize_number_format(value / MB))
    if value < TB:
        return ugettext("%s%s GB") % (sign, filesize_number_format(value / GB))
    if value < PB:
        return ugettext("%s%s TB") % (sign, filesize_number_format(value / TB))
    return ugettext("%s%s PB") % (sign, filesize_number_format(value / PB))
def filesizeformat ( value ) : if value == 0 : return '0 bytes' try : value = float ( value ) except ( TypeError , ValueError , UnicodeDecodeError ) : return '0 bytes' def filesize_number_format ( value ) : if value < 10 : return formats . number_format ( round ( value , 2 ) , 2 ) elif value < 100 : return formats . number_format ( round ( value , 2 ) , 1 ) else : return formats . number_format ( round ( value , 1 ) , 0 ) KB = 1 << 10 MB = 1 << 20 GB = 1 << 30 TB = 1 << 40 PB = 1 << 50 sign = '-' if value < 0 else '' value = abs ( value ) if value == 0 : return ugettext ( "0 bytes" ) if value < KB : if value != 1 : return '{sign}{size:d} bytes' . format ( sign = sign , size = int ( value ) ) else : return '1 byte' if value < MB : return ugettext ( "%s%s KB" ) % ( sign , filesize_number_format ( value / KB ) ) if value < GB : return ugettext ( "%s%s MB" ) % ( sign , filesize_number_format ( value / MB ) ) if value < TB : return ugettext ( "%s%s GB" ) % ( sign , filesize_number_format ( value / GB ) ) if value < PB : return ugettext ( "%s%s TB" ) % ( sign , filesize_number_format ( value / TB ) ) return ugettext ( "%s%s PB" ) % ( sign , filesize_number_format ( value / PB ) )