diff options
| author | Aldo Cortesi <aldo@corte.si> | 2016-10-20 12:36:26 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-20 12:36:26 +1300 |
| commit | 711078ba3f63257df745bb3edd80a85717e94b20 (patch) | |
| tree | d3116cd540faf01f272a0892fc6a9b83b4f6de8a /netlib/human.py | |
| parent | ee56d3fae0baeef1f31a83db122dd832d4c0e07e (diff) | |
| parent | 8430f857b504a3e7406dc36e54dc32783569d0dd (diff) | |
| download | mitmproxy-711078ba3f63257df745bb3edd80a85717e94b20.tar.gz mitmproxy-711078ba3f63257df745bb3edd80a85717e94b20.tar.bz2 mitmproxy-711078ba3f63257df745bb3edd80a85717e94b20.zip | |
Merge pull request #1637 from cortesi/tatanetlib
This PR merges netlib into mitmproxy
Diffstat (limited to 'netlib/human.py')
| -rw-r--r-- | netlib/human.py | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/netlib/human.py b/netlib/human.py deleted file mode 100644 index 72e96d30..00000000 --- a/netlib/human.py +++ /dev/null @@ -1,64 +0,0 @@ -import datetime -import time - - -SIZE_TABLE = [ - ("b", 1024 ** 0), - ("k", 1024 ** 1), - ("m", 1024 ** 2), - ("g", 1024 ** 3), - ("t", 1024 ** 4), -] - -SIZE_UNITS = dict(SIZE_TABLE) - - -def pretty_size(size): - for bottom, top in zip(SIZE_TABLE, SIZE_TABLE[1:]): - if bottom[1] <= size < top[1]: - suf = bottom[0] - lim = bottom[1] - x = round(size / lim, 2) - if x == int(x): - x = int(x) - return str(x) + suf - return "%s%s" % (size, SIZE_TABLE[0][0]) - - -def parse_size(s): - try: - return int(s) - except ValueError: - pass - for i in SIZE_UNITS.keys(): - if s.endswith(i): - try: - return int(s[:-1]) * SIZE_UNITS[i] - except ValueError: - break - raise ValueError("Invalid size specification.") - - -def pretty_duration(secs): - formatters = [ - (100, "{:.0f}s"), - (10, "{:2.1f}s"), - (1, "{:1.2f}s"), - ] - - for limit, formatter in formatters: - if secs >= limit: - return formatter.format(secs) - # less than 1 sec - return "{:.0f}ms".format(secs * 1000) - - -def format_timestamp(s): - s = time.localtime(s) - d = datetime.datetime.fromtimestamp(time.mktime(s)) - return d.strftime("%Y-%m-%d %H:%M:%S") - - -def format_timestamp_with_milli(s): - d = datetime.datetime.fromtimestamp(s) - return d.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] |
