diff options
author | Marcelo Glezer <marcelo.glezer@gmail.com> | 2015-03-02 23:22:44 -0300 |
---|---|---|
committer | Marcelo Glezer <marcelo.glezer@gmail.com> | 2015-03-02 23:22:44 -0300 |
commit | 58dba3f49083288e19f6e9edb7cc60e88dd446e3 (patch) | |
tree | 2cbcafe106575bf8f3b93494c97fa87bab050b38 | |
parent | 91e5a4a4b5bf1beb083afb0731294cfeaca62944 (diff) | |
download | mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.tar.gz mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.tar.bz2 mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.zip |
fixed formatting and added a 'test' (sort of)
-rw-r--r-- | libmproxy/console/flowdetailview.py | 8 | ||||
-rw-r--r-- | libmproxy/utils.py | 22 | ||||
-rw-r--r-- | test/test_utils.py | 2 |
3 files changed, 14 insertions, 18 deletions
diff --git a/libmproxy/console/flowdetailview.py b/libmproxy/console/flowdetailview.py index d0326f1a..e1339d77 100644 --- a/libmproxy/console/flowdetailview.py +++ b/libmproxy/console/flowdetailview.py @@ -40,8 +40,8 @@ class FlowDetailsView(urwid.ListBox): sc = self.flow.server_conn parts = [ ["Address", "%s:%s" % sc.address()], - ["Start time", utils.format_timestamp(sc.timestamp_start, True)], - ["End time", utils.format_timestamp(sc.timestamp_end, True) if sc.timestamp_end else "active"], + ["Start time", utils.format_timestamp_with_milli(sc.timestamp_start)], + ["End time", utils.format_timestamp_with_milli(sc.timestamp_end) if sc.timestamp_end else "active"], ] text.extend(common.format_keyvals(parts, key="key", val="text", indent=4)) @@ -84,9 +84,9 @@ class FlowDetailsView(urwid.ListBox): cc = self.flow.client_conn parts = [ ["Address", "%s:%s" % cc.address()], - ["Start time", utils.format_timestamp(cc.timestamp_start, True)], + ["Start time", utils.format_timestamp_with_milli(cc.timestamp_start)], # ["Requests", "%s"%cc.requestcount], - ["End time", utils.format_timestamp(cc.timestamp_end, True) if cc.timestamp_end else "active"], + ["End time", utils.format_timestamp_with_milli(cc.timestamp_end) if cc.timestamp_end else "active"], ] text.extend(common.format_keyvals(parts, key="key", val="text", indent=4)) diff --git a/libmproxy/utils.py b/libmproxy/utils.py index a50be7fc..e608c8a3 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -11,20 +11,14 @@ def timestamp(): def format_timestamp(s, include_fractions = False): - if type(s) is not float: - s = time.localtime(s) - d = datetime.datetime.fromtimestamp(time.mktime(s)) - else: - # s is a timestamp(float) can be converted to a datetime without lossing microsecs - d = datetime.datetime.fromtimestamp(s) - if not include_fractions: - format = "%Y-%m-%d %H:%M:%S" - else: - # this will show 3 miliseconds digits (but will truncate and not round the 4th significant digit - # so 600999 microseconds will be 600ms and not 601ms) - format = "%Y-%m-%d %H:%M:%S."+str(d.microsecond/1000) - return d.strftime(format) - + 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.")+str(d.microsecond/1000).zfill(3) + def isBin(s): """ Does this string have any non-ASCII characters? diff --git a/test/test_utils.py b/test/test_utils.py index 45bfb4f7..78d1c072 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -8,6 +8,8 @@ utils.CERT_SLEEP_TIME = 0 def test_format_timestamp(): assert utils.format_timestamp(utils.timestamp()) +def test_format_timestamp_with_milli(): + assert utils.format_timestamp_with_milli(utils.timestamp()) def test_isBin(): assert not utils.isBin("testing\n\r") |