|
a/Allura/allura/lib/helpers.py |
|
b/Allura/allura/lib/helpers.py |
|
... |
|
... |
587 |
elif code_mode and linenumbers_style == TABLE:
|
587 |
elif code_mode and linenumbers_style == TABLE:
|
588 |
text = _add_table_line_numbers_to_text(text)
|
588 |
text = _add_table_line_numbers_to_text(text)
|
589 |
else:
|
589 |
else:
|
590 |
text = '<pre>%s</pre>' % text
|
590 |
text = '<pre>%s</pre>' % text
|
591 |
return Markup(text)
|
591 |
return Markup(text)
|
|
|
592 |
|
|
|
593 |
# copied from jinja2 dev
|
|
|
594 |
# latest release, 2.6, implements this incorrectly
|
|
|
595 |
# can remove and use jinja2 implementation after upgrading to 2.7
|
|
|
596 |
def do_filesizeformat(value, binary=False):
|
|
|
597 |
"""Format the value like a 'human-readable' file size (i.e. 13 kB,
|
|
|
598 |
4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,
|
|
|
599 |
Giga, etc.), if the second parameter is set to `True` the binary
|
|
|
600 |
prefixes are used (Mebi, Gibi).
|
|
|
601 |
"""
|
|
|
602 |
bytes = float(value)
|
|
|
603 |
base = binary and 1024 or 1000
|
|
|
604 |
prefixes = [
|
|
|
605 |
(binary and 'KiB' or 'kB'),
|
|
|
606 |
(binary and 'MiB' or 'MB'),
|
|
|
607 |
(binary and 'GiB' or 'GB'),
|
|
|
608 |
(binary and 'TiB' or 'TB'),
|
|
|
609 |
(binary and 'PiB' or 'PB'),
|
|
|
610 |
(binary and 'EiB' or 'EB'),
|
|
|
611 |
(binary and 'ZiB' or 'ZB'),
|
|
|
612 |
(binary and 'YiB' or 'YB')
|
|
|
613 |
]
|
|
|
614 |
if bytes == 1:
|
|
|
615 |
return '1 Byte'
|
|
|
616 |
elif bytes < base:
|
|
|
617 |
return '%d Bytes' % bytes
|
|
|
618 |
else:
|
|
|
619 |
for i, prefix in enumerate(prefixes):
|
|
|
620 |
unit = base ** (i + 2)
|
|
|
621 |
if bytes < unit:
|
|
|
622 |
return '%.1f %s' % ((base * bytes / unit), prefix)
|
|
|
623 |
return '%.1f %s' % ((base * bytes / unit), prefix)
|