mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
fixed formatting and added a 'test' (sort of)
This commit is contained in:
parent
91e5a4a4b5
commit
58dba3f490
@ -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))
|
||||
|
||||
|
@ -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?
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user