Minor refactor to PR #496

This commit is contained in:
Tarashish Mishra 2015-03-04 22:32:01 +05:30
parent b49d573c8b
commit 48023db59e
2 changed files with 13 additions and 11 deletions

View File

@ -37,15 +37,15 @@ class FlowDetailsView(urwid.ListBox):
cc = self.flow.client_conn
sc = self.flow.server_conn
req = self.flow.request;
resp = self.flow.response;
req = self.flow.request
resp = self.flow.response
if sc:
text.append(urwid.Text([("head", "Server Connection:")]))
parts = [
["Address", "%s:%s" % sc.address()],
]
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
c = sc.cert
@ -89,7 +89,7 @@ class FlowDetailsView(urwid.ListBox):
["Address", "%s:%s" % cc.address()],
# ["Requests", "%s"%cc.requestcount],
]
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
parts = []
@ -105,7 +105,7 @@ class FlowDetailsView(urwid.ListBox):
parts.append(["First response byte", utils.format_timestamp_with_milli(resp.timestamp_start) if resp else "active"])
parts.append(["Response complete", utils.format_timestamp_with_milli(resp.timestamp_end) if (resp and resp.timestamp_end) else "active"])
# sort operations by timestamp
# sort operations by timestamp
parts = sorted(parts, key=lambda p: p[1])
text.append(urwid.Text([("head", "Timing:")]))

View File

@ -15,10 +15,12 @@ def format_timestamp(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)
return d.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
def isBin(s):
"""
Does this string have any non-ASCII characters?
@ -84,15 +86,15 @@ def pretty_size(size):
def pretty_duration(secs):
formatters = [
(100, "{:.0f}s"),
(10, "{:2.1f}s"),
(1, "{:1.2f}s"),
(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
#less than 1 sec
return "{:.0f}ms".format(secs*1000)
class Data: