diff options
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/http/response.py | 2 | ||||
-rw-r--r-- | netlib/human.py | 64 | ||||
-rw-r--r-- | netlib/websockets/frame.py | 2 |
3 files changed, 2 insertions, 66 deletions
diff --git a/netlib/http/response.py b/netlib/http/response.py index a8b48be0..12dba92a 100644 --- a/netlib/http/response.py +++ b/netlib/http/response.py @@ -1,6 +1,6 @@ import time from email.utils import parsedate_tz, formatdate, mktime_tz -from netlib import human +from mitmproxy.utils import human from netlib import multidict from netlib.http import cookies from netlib.http import headers as nheaders 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] diff --git a/netlib/websockets/frame.py b/netlib/websockets/frame.py index b58fa289..02d74112 100644 --- a/netlib/websockets/frame.py +++ b/netlib/websockets/frame.py @@ -5,7 +5,7 @@ import io from netlib import tcp from netlib import strutils from netlib import utils -from netlib import human +from mitmproxy.utils import human from .masker import Masker |