Docstrings.

This commit is contained in:
Itamar Turner-Trauring 2020-12-18 15:43:27 -05:00
parent 48b9ffe2a5
commit f964ae1782
2 changed files with 25 additions and 2 deletions

View File

@ -208,7 +208,15 @@ def compute_rate(bytes, seconds):
return 1.0 * bytes / seconds
def abbreviate_rate(data):
# 21.8kBps, 554.4kBps 4.37MBps
"""
Convert number of bytes/second into human readable strings (unicode).
Uses metric measures, so 1000 not 1024, e.g. 21.8kBps, 554.4kBps, 4.37MBps.
:param data: Either ``None`` or integer.
:return: Unicode string.
"""
if data is None:
return u""
r = float(data)
@ -219,7 +227,15 @@ def abbreviate_rate(data):
return u"%.0fBps" % r
def abbreviate_size(data):
# 21.8kB, 554.4kB 4.37MB
"""
Convert number of bytes into human readable strings (unicode).
Uses metric measures, so 1000 not 1024, e.g. 21.8kB, 554.4kB, 4.37MB.
:param data: Either ``None`` or integer.
:return: Unicode string.
"""
if data is None:
return u""
r = float(data)

View File

@ -95,6 +95,13 @@ class MultiFormatResource(resource.Resource, object):
def abbreviate_time(data):
"""
Convert number of seconds into human readable string.
:param data: Either ``None`` or integer or float, seconds.
:return: Unicode string.
"""
# 1.23s, 790ms, 132us
if data is None:
return u""