mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Remove refresh_flow mechanism in favor of a signal-based implementation
This commit is contained in:
parent
7a119ac7d7
commit
aa9a38522f
@ -263,7 +263,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
if f.error:
|
if f.error:
|
||||||
self._run_script_method("error", s, f)
|
self._run_script_method("error", s, f)
|
||||||
s.unload()
|
s.unload()
|
||||||
self.refresh_flow(f)
|
signals.flow_change.send(self, flow = f)
|
||||||
|
|
||||||
def set_script(self, command):
|
def set_script(self, command):
|
||||||
if not command:
|
if not command:
|
||||||
@ -378,7 +378,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
changed = self.tick(self.masterq, timeout=0)
|
changed = self.tick(self.masterq, timeout=0)
|
||||||
if changed:
|
if changed:
|
||||||
self.loop.draw_screen()
|
self.loop.draw_screen()
|
||||||
self.statusbar.redraw()
|
signals.update_settings.send()
|
||||||
self.loop.set_alarm_in(0.01, self.ticker)
|
self.loop.set_alarm_in(0.01, self.ticker)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -397,7 +397,6 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
screen = self.ui,
|
screen = self.ui,
|
||||||
)
|
)
|
||||||
self.view_flowlist()
|
self.view_flowlist()
|
||||||
self.statusbar.redraw()
|
|
||||||
|
|
||||||
self.server.start_slave(
|
self.server.start_slave(
|
||||||
controller.Slave,
|
controller.Slave,
|
||||||
@ -446,7 +445,6 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
header = self.header,
|
header = self.header,
|
||||||
footer = self.statusbar
|
footer = self.statusbar
|
||||||
)
|
)
|
||||||
self.statusbar.redraw()
|
|
||||||
return self.view
|
return self.view
|
||||||
|
|
||||||
def view_help(self):
|
def view_help(self):
|
||||||
@ -633,15 +631,10 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
|
|
||||||
def refresh_focus(self):
|
def refresh_focus(self):
|
||||||
if self.state.view:
|
if self.state.view:
|
||||||
self.refresh_flow(self.state.view[self.state.focus])
|
signals.flow_change.send(
|
||||||
|
self,
|
||||||
def refresh_flow(self, c):
|
flow = self.state.view[self.state.focus]
|
||||||
if hasattr(self.header, "refresh_flow"):
|
)
|
||||||
self.header.refresh_flow(c)
|
|
||||||
if hasattr(self.body, "refresh_flow"):
|
|
||||||
self.body.refresh_flow(c)
|
|
||||||
if hasattr(self.statusbar, "refresh_flow"):
|
|
||||||
self.statusbar.refresh_flow(c)
|
|
||||||
|
|
||||||
def process_flow(self, f):
|
def process_flow(self, f):
|
||||||
if self.state.intercept and f.match(self.state.intercept) and not f.request.is_replay:
|
if self.state.intercept and f.match(self.state.intercept) and not f.request.is_replay:
|
||||||
@ -649,7 +642,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
else:
|
else:
|
||||||
f.reply()
|
f.reply()
|
||||||
self.sync_list_view()
|
self.sync_list_view()
|
||||||
self.refresh_flow(f)
|
signals.flow_change.send(self, flow = f)
|
||||||
|
|
||||||
def clear_events(self):
|
def clear_events(self):
|
||||||
self.eventlist[:] = []
|
self.eventlist[:] = []
|
||||||
|
@ -88,10 +88,17 @@ class FlowViewHeader(urwid.WidgetWrap):
|
|||||||
def __init__(self, master, f):
|
def __init__(self, master, f):
|
||||||
self.master, self.flow = master, f
|
self.master, self.flow = master, f
|
||||||
self._w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
|
self._w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
|
||||||
|
signals.flow_change.connect(self.sig_flow_change)
|
||||||
|
|
||||||
def refresh_flow(self, f):
|
def sig_flow_change(self, sender, flow):
|
||||||
if f == self.flow:
|
if flow == self.flow:
|
||||||
self._w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
|
self._w = common.format_flow(
|
||||||
|
flow,
|
||||||
|
False,
|
||||||
|
extended=True,
|
||||||
|
padding=0,
|
||||||
|
hostheader=self.master.showhost
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CallbackCache:
|
class CallbackCache:
|
||||||
@ -119,6 +126,14 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
self.view_response()
|
self.view_response()
|
||||||
else:
|
else:
|
||||||
self.view_request()
|
self.view_request()
|
||||||
|
signals.flow_change.connect(self.sig_flow_change)
|
||||||
|
|
||||||
|
def sig_flow_change(self, sender, flow):
|
||||||
|
if flow == self.flow:
|
||||||
|
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and self.flow.response:
|
||||||
|
self.view_response()
|
||||||
|
else:
|
||||||
|
self.view_request()
|
||||||
|
|
||||||
def _cached_content_view(self, viewmode, hdrItems, content, limit, is_request):
|
def _cached_content_view(self, viewmode, hdrItems, content, limit, is_request):
|
||||||
return contentview.get_content_view(viewmode, hdrItems, content, limit, self.master.add_event, is_request)
|
return contentview.get_content_view(viewmode, hdrItems, content, limit, self.master.add_event, is_request)
|
||||||
@ -332,7 +347,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
list_box = urwid.ListBox(merged)
|
list_box = urwid.ListBox(merged)
|
||||||
list_box.set_focus(focus_position + 2)
|
list_box.set_focus(focus_position + 2)
|
||||||
self._w = self.wrap_body(const, list_box)
|
self._w = self.wrap_body(const, list_box)
|
||||||
self.master.statusbar.redraw()
|
signals.update_settings.send(self)
|
||||||
|
|
||||||
self.last_displayed_body = list_box
|
self.last_displayed_body = list_box
|
||||||
|
|
||||||
@ -456,7 +471,6 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
||||||
body = self.conn_text(self.flow.request)
|
body = self.conn_text(self.flow.request)
|
||||||
self._w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
|
self._w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
|
||||||
self.master.statusbar.redraw()
|
|
||||||
|
|
||||||
def view_response(self):
|
def view_response(self):
|
||||||
self.state.view_flow_mode = common.VIEW_FLOW_RESPONSE
|
self.state.view_flow_mode = common.VIEW_FLOW_RESPONSE
|
||||||
@ -476,19 +490,11 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
self._w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
self._w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
||||||
self.master.statusbar.redraw()
|
|
||||||
|
|
||||||
def refresh_flow(self, c=None):
|
|
||||||
if c == self.flow:
|
|
||||||
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and self.flow.response:
|
|
||||||
self.view_response()
|
|
||||||
else:
|
|
||||||
self.view_request()
|
|
||||||
|
|
||||||
def set_method_raw(self, m):
|
def set_method_raw(self, m):
|
||||||
if m:
|
if m:
|
||||||
self.flow.request.method = m
|
self.flow.request.method = m
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def edit_method(self, m):
|
def edit_method(self, m):
|
||||||
if m == "e":
|
if m == "e":
|
||||||
@ -501,7 +507,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
for i in common.METHOD_OPTIONS:
|
for i in common.METHOD_OPTIONS:
|
||||||
if i[1] == m:
|
if i[1] == m:
|
||||||
self.flow.request.method = i[0].upper()
|
self.flow.request.method = i[0].upper()
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def set_url(self, url):
|
def set_url(self, url):
|
||||||
request = self.flow.request
|
request = self.flow.request
|
||||||
@ -509,7 +515,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
request.url = str(url)
|
request.url = str(url)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return "Invalid URL."
|
return "Invalid URL."
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def set_resp_code(self, code):
|
def set_resp_code(self, code):
|
||||||
response = self.flow.response
|
response = self.flow.response
|
||||||
@ -520,12 +526,12 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
import BaseHTTPServer
|
import BaseHTTPServer
|
||||||
if BaseHTTPServer.BaseHTTPRequestHandler.responses.has_key(int(code)):
|
if BaseHTTPServer.BaseHTTPRequestHandler.responses.has_key(int(code)):
|
||||||
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[int(code)][0]
|
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[int(code)][0]
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def set_resp_msg(self, msg):
|
def set_resp_msg(self, msg):
|
||||||
response = self.flow.response
|
response = self.flow.response
|
||||||
response.msg = msg
|
response.msg = msg
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def set_headers(self, lst, conn):
|
def set_headers(self, lst, conn):
|
||||||
conn.headers = flow.ODictCaseless(lst)
|
conn.headers = flow.ODictCaseless(lst)
|
||||||
@ -614,7 +620,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
text = message.msg,
|
text = message.msg,
|
||||||
callback = self.set_resp_msg
|
callback = self.set_resp_msg
|
||||||
)
|
)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def _view_nextprev_flow(self, np, flow):
|
def _view_nextprev_flow(self, np, flow):
|
||||||
try:
|
try:
|
||||||
@ -642,7 +648,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
(self.state.view_flow_mode, "prettyview"),
|
(self.state.view_flow_mode, "prettyview"),
|
||||||
contentview.get_by_shortcut(t)
|
contentview.get_by_shortcut(t)
|
||||||
)
|
)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def delete_body(self, t):
|
def delete_body(self, t):
|
||||||
if t == "m":
|
if t == "m":
|
||||||
@ -653,7 +659,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
self.flow.request.content = val
|
self.flow.request.content = val
|
||||||
else:
|
else:
|
||||||
self.flow.response.content = val
|
self.flow.response.content = val
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
if key == " ":
|
if key == " ":
|
||||||
@ -736,7 +742,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
(self.state.view_flow_mode, "fullcontents"),
|
(self.state.view_flow_mode, "fullcontents"),
|
||||||
True
|
True
|
||||||
)
|
)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
signals.status_message.send(message="")
|
signals.status_message.send(message="")
|
||||||
elif key == "g":
|
elif key == "g":
|
||||||
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||||
@ -760,13 +766,13 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
r = self.master.replay_request(self.flow)
|
r = self.master.replay_request(self.flow)
|
||||||
if r:
|
if r:
|
||||||
signals.status_message.send(message=r)
|
signals.status_message.send(message=r)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
elif key == "V":
|
elif key == "V":
|
||||||
if not self.flow.modified():
|
if not self.flow.modified():
|
||||||
signals.status_message.send(message="Flow not modified.")
|
signals.status_message.send(message="Flow not modified.")
|
||||||
return
|
return
|
||||||
self.state.revert(self.flow)
|
self.state.revert(self.flow)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
signals.status_message.send(message="Reverted.")
|
signals.status_message.send(message="Reverted.")
|
||||||
elif key == "W":
|
elif key == "W":
|
||||||
signals.status_prompt_path.send(
|
signals.status_prompt_path.send(
|
||||||
@ -817,7 +823,7 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
callback = self.encode_callback,
|
callback = self.encode_callback,
|
||||||
args = (conn,)
|
args = (conn,)
|
||||||
)
|
)
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
elif key == "/":
|
elif key == "/":
|
||||||
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
|
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
|
||||||
search_prompt = "Search body ["+last_search_string+"]" if last_search_string else "Search body"
|
search_prompt = "Search body ["+last_search_string+"]" if last_search_string else "Search body"
|
||||||
@ -839,4 +845,4 @@ class FlowView(urwid.WidgetWrap):
|
|||||||
"d": "deflate",
|
"d": "deflate",
|
||||||
}
|
}
|
||||||
conn.encode(encoding_map[key])
|
conn.encode(encoding_map[key])
|
||||||
self.master.refresh_flow(self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
@ -20,3 +20,6 @@ focus = blinker.Signal()
|
|||||||
|
|
||||||
# Fired when settings change
|
# Fired when settings change
|
||||||
update_settings = blinker.Signal()
|
update_settings = blinker.Signal()
|
||||||
|
|
||||||
|
# Fired when a flow changes
|
||||||
|
flow_change = blinker.Signal()
|
||||||
|
Loading…
Reference in New Issue
Block a user