Merge pull request #1397 from mhils/console-fixes

Console fixes
This commit is contained in:
Maximilian Hils 2016-07-21 19:11:53 -07:00 committed by GitHub
commit daae51823d
5 changed files with 14 additions and 24 deletions

View File

@ -216,7 +216,7 @@ def copy_to_clipboard_or_prompt(data):
def format_flow_data(key, scope, flow):
data = ""
data = b""
if scope in ("q", "b"):
request = flow.request.copy()
request.decode(strict=False)
@ -230,7 +230,7 @@ def format_flow_data(key, scope, flow):
raise ValueError("Unknown key: {}".format(key))
if scope == "b" and flow.request.raw_content and flow.response:
# Add padding between request and response
data += "\r\n" * 2
data += b"\r\n" * 2
if scope in ("s", "b") and flow.response:
response = flow.response.copy()
response.decode(strict=False)
@ -293,7 +293,7 @@ def ask_save_body(scope, flow):
)
elif scope == "b" and request_has_content and response_has_content:
ask_save_path(
(flow.request.get_content(strict=False) + "\n" +
(flow.request.get_content(strict=False) + b"\n" +
flow.response.get_content(strict=False)),
"Save request & response content to"
)

View File

@ -193,7 +193,8 @@ class ConnectionItem(urwid.WidgetWrap):
signals.flowlist_change.send(self)
elif key == "D":
f = self.master.duplicate_flow(self.flow)
self.master.view_flow(f)
self.master.state.set_focus_flow(f)
signals.flowlist_change.send(self)
elif key == "m":
if self.state.flow_marked(self.flow):
self.state.set_flow_marked(self.flow, False)
@ -356,7 +357,8 @@ class FlowListBox(urwid.ListBox):
return
scheme, host, port, path = parts
f = self.master.create_request(method, scheme, host, port, path)
self.master.view_flow(f)
self.master.state.set_focus_flow(f)
signals.flowlist_change.send(self)
def keypress(self, size, key):
key = common.shortcuts(key)

View File

@ -567,6 +567,7 @@ class FlowView(tabs.Tabs):
self.state.delete_flow(f)
elif key == "D":
f = self.master.duplicate_flow(self.flow)
signals.pop_view_state.send(self)
self.master.view_flow(f)
signals.status_message.send(message="Duplicated.")
elif key == "p":
@ -605,11 +606,11 @@ class FlowView(tabs.Tabs):
if key == "b":
if self.tab_offset == TAB_REQ:
common.ask_save_body(
"q", self.master, self.state, self.flow
"q", self.flow
)
else:
common.ask_save_body(
"s", self.master, self.state, self.flow
"s", self.flow
)
elif key == "e":
if self.tab_offset == TAB_REQ:

View File

@ -86,10 +86,10 @@ class ConsoleState(flow.State):
def set_focus(self, idx):
if self.view:
if idx >= len(self.view):
idx = len(self.view) - 1
elif idx < 0:
if idx is None or idx < 0:
idx = 0
elif idx >= len(self.view):
idx = len(self.view) - 1
self.focus = idx
else:
self.focus = None
@ -254,10 +254,6 @@ class ConsoleMaster(flow.FlowMaster):
expire=1
)
def load_script(self, command, use_reloader=True):
# We default to using the reloader in the console ui.
return super(ConsoleMaster, self).load_script(command, use_reloader)
def sig_add_log(self, sender, e, level):
if self.options.verbosity < utils.log_tier(level):
return
@ -352,7 +348,7 @@ class ConsoleMaster(flow.FlowMaster):
try:
return flow.read_flows_from_paths(path)
except exceptions.FlowReadException as e:
signals.status_message.send(message=e.strerror)
signals.status_message.send(message=str(e))
def client_playback_path(self, path):
if not isinstance(path, list):
@ -748,10 +744,3 @@ class ConsoleMaster(flow.FlowMaster):
direction=direction,
), "info")
self.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
@controller.handler
def script_change(self, script):
if super(ConsoleMaster, self).script_change(script):
signals.status_message.send(message='"{}" reloaded.'.format(script.path))
else:
signals.status_message.send(message='Error reloading "{}".'.format(script.path))

View File

@ -37,8 +37,6 @@ Events = frozenset([
"configure",
"done",
"tick",
"script_change",
])