from itertools import imap, groupby
from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode
from jinja2.runtime import Undefined
-from jinja2.exceptions import FilterArgumentError, SecurityError
+from jinja2.exceptions import FilterArgumentError
_word_re = re.compile(r'\w+(?u)')
bytes = float(value)
base = binary and 1024 or 1000
prefixes = [
- (binary and "KiB" or "kB"),
- (binary and "MiB" or "MB"),
- (binary and "GiB" or "GB"),
- (binary and "TiB" or "TB"),
- (binary and "PiB" or "PB"),
- (binary and "EiB" or "EB"),
- (binary and "ZiB" or "ZB"),
- (binary and "YiB" or "YB")
+ (binary and 'KiB' or 'kB'),
+ (binary and 'MiB' or 'MB'),
+ (binary and 'GiB' or 'GB'),
+ (binary and 'TiB' or 'TB'),
+ (binary and 'PiB' or 'PB'),
+ (binary and 'EiB' or 'EB'),
+ (binary and 'ZiB' or 'ZB'),
+ (binary and 'YiB' or 'YB')
]
if bytes == 1:
- return "1 Byte"
+ return '1 Byte'
elif bytes < base:
- return "%d Bytes" % bytes
+ return '%d Bytes' % bytes
else:
for i, prefix in enumerate(prefixes):
- unit = base * base ** (i + 1)
- if bytes < unit:
- return "%.1f %s" % ((bytes / unit), prefix)
- return "%.1f %s" % ((bytes / unit), prefix)
+ unit = base ** (i + 1)
+ if bytes <= unit:
+ return '%.1f %s' % ((bytes / unit), prefix)
+ return '%.1f %s' % ((bytes / unit), prefix)
def do_pprint(value, verbose=False):