This commit is contained in:
Maximilian Hils 2016-07-23 18:48:54 -07:00 committed by GitHub
parent a87d089561
commit 4d042ec543
2 changed files with 140 additions and 141 deletions

View File

@ -39,7 +39,7 @@ def _mkhelp():
("d", "delete flow"), ("d", "delete flow"),
("e", "edit request/response"), ("e", "edit request/response"),
("f", "load full body data"), ("f", "load full body data"),
("m", "change body display mode for this entity"), ("m", "change body display mode for this entity\n(default mode can be changed in the options)"),
(None, (None,
common.highlight_key("automatic", "a") + common.highlight_key("automatic", "a") +
[("text", ": automatic detection")] [("text", ": automatic detection")]
@ -76,7 +76,6 @@ def _mkhelp():
common.highlight_key("xml", "x") + common.highlight_key("xml", "x") +
[("text", ": XML")] [("text", ": XML")]
), ),
("M", "change default body display mode"),
("E", "export flow to file"), ("E", "export flow to file"),
("r", "replay request"), ("r", "replay request"),
("V", "revert changes to request"), ("V", "revert changes to request"),
@ -137,7 +136,7 @@ class FlowView(tabs.Tabs):
def __init__(self, master, state, flow, tab_offset): def __init__(self, master, state, flow, tab_offset):
self.master, self.state, self.flow = master, state, flow self.master, self.state, self.flow = master, state, flow
tabs.Tabs.__init__(self, super(FlowView, self).__init__(
[ [
(self.tab_request, self.view_request), (self.tab_request, self.view_request),
(self.tab_response, self.view_response), (self.tab_response, self.view_response),
@ -145,6 +144,7 @@ class FlowView(tabs.Tabs):
], ],
tab_offset tab_offset
) )
self.show() self.show()
self.last_displayed_body = None self.last_displayed_body = None
signals.flow_change.connect(self.sig_flow_change) signals.flow_change.connect(self.sig_flow_change)
@ -404,7 +404,7 @@ class FlowView(tabs.Tabs):
if not self.flow.response: if not self.flow.response:
self.flow.response = models.HTTPResponse( self.flow.response = models.HTTPResponse(
self.flow.request.http_version, self.flow.request.http_version,
200, "OK", Headers(), "" 200, b"OK", Headers(), b""
) )
self.flow.response.reply = controller.DummyReply() self.flow.response.reply = controller.DummyReply()
message = self.flow.response message = self.flow.response
@ -533,24 +533,23 @@ class FlowView(tabs.Tabs):
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
def keypress(self, size, key): def keypress(self, size, key):
key = super(self.__class__, self).keypress(size, key)
if key == " ":
self.view_next_flow(self.flow)
return
key = common.shortcuts(key)
conn = None # type: Optional[Union[models.HTTPRequest, models.HTTPResponse]] conn = None # type: Optional[Union[models.HTTPRequest, models.HTTPResponse]]
if self.tab_offset == TAB_REQ: if self.tab_offset == TAB_REQ:
conn = self.flow.request conn = self.flow.request
elif self.tab_offset == TAB_RESP: elif self.tab_offset == TAB_RESP:
conn = self.flow.response conn = self.flow.response
else:
conn = None
key = super(self.__class__, self).keypress(size, key)
# Special case: Space moves over to the next flow.
# We need to catch that before applying common.shortcuts()
if key == " ":
self.view_next_flow(self.flow)
return
key = common.shortcuts(key)
if key in ("up", "down", "page up", "page down"): if key in ("up", "down", "page up", "page down"):
# Why doesn't this just work?? # Pass scroll events to the wrapped widget
self._w.keypress(size, key) self._w.keypress(size, key)
elif key == "a": elif key == "a":
self.flow.accept_intercept(self.master) self.flow.accept_intercept(self.master)
@ -582,12 +581,12 @@ class FlowView(tabs.Tabs):
signals.status_message.send(message=r) signals.status_message.send(message=r)
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
elif key == "V": elif key == "V":
if not self.flow.modified(): if self.flow.modified():
signals.status_message.send(message="Flow not modified.")
return
self.state.revert(self.flow) self.state.revert(self.flow)
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
signals.status_message.send(message="Reverted.") signals.status_message.send(message="Reverted.")
else:
signals.status_message.send(message="Flow not modified.")
elif key == "W": elif key == "W":
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Save this flow", prompt = "Save this flow",
@ -600,27 +599,11 @@ class FlowView(tabs.Tabs):
callback = self.master.run_script_once, callback = self.master.run_script_once,
args = (self.flow,) args = (self.flow,)
) )
if not conn and key in set(list("befgmxvzEC")):
signals.status_message.send(
message = "Tab to the request or response",
expire = 1
)
elif conn:
if key == "b":
if self.tab_offset == TAB_REQ:
common.ask_save_body(
"q", self.flow
)
else:
common.ask_save_body(
"s", self.flow
)
elif key == "e": elif key == "e":
if self.tab_offset == TAB_REQ: if self.tab_offset == TAB_REQ:
signals.status_prompt_onekey.send( signals.status_prompt_onekey.send(
prompt = "Edit request", prompt="Edit request",
keys = ( keys=(
("cookies", "c"), ("cookies", "c"),
("query", "q"), ("query", "q"),
("path", "p"), ("path", "p"),
@ -630,21 +613,36 @@ class FlowView(tabs.Tabs):
("raw body", "r"), ("raw body", "r"),
("method", "m"), ("method", "m"),
), ),
callback = self.edit callback=self.edit
) )
else: elif self.tab_offset == TAB_RESP:
signals.status_prompt_onekey.send( signals.status_prompt_onekey.send(
prompt = "Edit response", prompt="Edit response",
keys = ( keys=(
("cookies", "c"), ("cookies", "c"),
("code", "o"), ("code", "o"),
("message", "m"), ("message", "m"),
("header", "h"), ("header", "h"),
("raw body", "r"), ("raw body", "r"),
), ),
callback = self.edit callback=self.edit
) )
key = None else:
signals.status_message.send(
message="Tab to the request or response",
expire=1
)
elif key in "bfgmxvzEC" and not conn:
signals.status_message.send(
message = "Tab to the request or response",
expire = 1
)
return
elif key == "b":
if self.tab_offset == TAB_REQ:
common.ask_save_body("q", self.flow)
else:
common.ask_save_body("s", self.flow)
elif key == "f": elif key == "f":
signals.status_message.send(message="Loading all body data...") signals.status_message.send(message="Loading all body data...")
self.state.add_flow_setting( self.state.add_flow_setting(
@ -663,7 +661,6 @@ class FlowView(tabs.Tabs):
keys = p, keys = p,
callback = self.change_this_display_mode callback = self.change_this_display_mode
) )
key = None
elif key == "E": elif key == "E":
if self.tab_offset == TAB_REQ: if self.tab_offset == TAB_REQ:
scope = "q" scope = "q"
@ -721,6 +718,8 @@ class FlowView(tabs.Tabs):
args = (conn,) args = (conn,)
) )
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
else:
# Key is not handled here.
return key return key
def encode_callback(self, key, conn): def encode_callback(self, key, conn):

View File

@ -25,7 +25,7 @@ class Tab(urwid.WidgetWrap):
class Tabs(urwid.WidgetWrap): class Tabs(urwid.WidgetWrap):
def __init__(self, tabs, tab_offset=0): def __init__(self, tabs, tab_offset=0):
urwid.WidgetWrap.__init__(self, "") super(Tabs, self).__init__("")
self.tab_offset = tab_offset self.tab_offset = tab_offset
self.tabs = tabs self.tabs = tabs
self.show() self.show()