aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-07 15:59:38 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-07 15:59:38 +1200
commite76467e977c061d92f88500b23f11bbf3cc365bb (patch)
tree9722ad8700db8a5726a840779efbbf4d40ee3537
parentc7b1234e13bd81891d4dc0fcc68de6237cec2e8c (diff)
downloadmitmproxy-e76467e977c061d92f88500b23f11bbf3cc365bb.tar.gz
mitmproxy-e76467e977c061d92f88500b23f11bbf3cc365bb.tar.bz2
mitmproxy-e76467e977c061d92f88500b23f11bbf3cc365bb.zip
Refactor flow list state management
- Use signal mechanism for state synchronisation - Move "Copy to clipboard" shortcut to "P"
-rw-r--r--libmproxy/console/__init__.py20
-rw-r--r--libmproxy/console/flowlist.py23
-rw-r--r--libmproxy/console/flowview.py4
-rw-r--r--libmproxy/console/help.py22
-rw-r--r--libmproxy/console/options.py4
-rw-r--r--libmproxy/console/signals.py2
-rw-r--r--libmproxy/console/statusbar.py1
7 files changed, 28 insertions, 48 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py
index b055ba96..5c2402f6 100644
--- a/libmproxy/console/__init__.py
+++ b/libmproxy/console/__init__.py
@@ -157,8 +157,6 @@ class ConsoleMaster(flow.FlowMaster):
for i in options.setheaders:
self.setheaders.add(*i)
- self.flow_list_walker = None
-
r = self.set_intercept(options.intercept)
if r:
print >> sys.stderr, "Intercept error:", r
@@ -410,7 +408,6 @@ class ConsoleMaster(flow.FlowMaster):
self.ui = urwid.raw_display.Screen()
self.ui.set_terminal_properties(256)
self.set_palette(self.palette)
- self.flow_list_walker = flowlist.FlowListWalker(self, self.state)
self.loop = urwid.MainLoop(
urwid.SolidFill("x"),
screen = self.ui,
@@ -566,8 +563,7 @@ class ConsoleMaster(flow.FlowMaster):
flow.FlowMaster.load_flows_file(self, path)
except flow.FlowReadError, v:
reterr = str(v)
- if self.flow_list_walker:
- self.sync_list_view()
+ signals.flowlist_change.send(self)
return reterr
def accept_all(self):
@@ -575,7 +571,7 @@ class ConsoleMaster(flow.FlowMaster):
def set_limit(self, txt):
v = self.state.set_limit(txt)
- self.sync_list_view()
+ signals.flowlist_change.send(self)
return v
def set_intercept(self, txt):
@@ -612,13 +608,9 @@ class ConsoleMaster(flow.FlowMaster):
self.state.killall(self)
flow.FlowMaster.shutdown(self)
- def sync_list_view(self):
- self.flow_list_walker._modified()
- signals.update_settings.send(self)
-
def clear_flows(self):
self.state.clear()
- self.sync_list_view()
+ signals.flowlist_change.send(self)
def toggle_follow_flows(self):
# toggle flow follow
@@ -626,11 +618,11 @@ class ConsoleMaster(flow.FlowMaster):
# jump to most recent flow if follow is now on
if self.state.follow_focus:
self.state.set_focus(self.state.flow_count())
- self.sync_list_view()
+ signals.flowlist_change.send(self)
def delete_flow(self, f):
self.state.delete_flow(f)
- self.sync_list_view()
+ signals.flowlist_change.send(self)
def refresh_focus(self):
if self.state.view:
@@ -644,7 +636,7 @@ class ConsoleMaster(flow.FlowMaster):
f.intercept(self)
else:
f.reply()
- self.sync_list_view()
+ signals.flowlist_change.send(self)
signals.flow_change.send(self, flow = f)
def clear_events(self):
diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py
index 946bd97b..8923fd60 100644
--- a/libmproxy/console/flowlist.py
+++ b/libmproxy/console/flowlist.py
@@ -15,10 +15,10 @@ def _mkhelp():
("D", "duplicate flow"),
("e", "toggle eventlog"),
("F", "toggle follow flow list"),
- ("g", "copy flow to clipboard"),
("l", "set limit filter pattern"),
("L", "load saved flows"),
("n", "create a new request"),
+ ("P", "copy flow to clipboard"),
("r", "replay request"),
("V", "revert changes to request"),
("w", "save flows "),
@@ -157,11 +157,11 @@ class ConnectionItem(urwid.WidgetWrap):
key = common.shortcuts(key)
if key == "a":
self.flow.accept_intercept(self.master)
- self.master.sync_list_view()
+ signals.flowlist_change.send(self)
elif key == "d":
self.flow.kill(self.master)
self.state.delete_flow(self.flow)
- self.master.sync_list_view()
+ signals.flowlist_change.send(self)
elif key == "D":
f = self.master.duplicate_flow(self.flow)
self.master.view_flow(f)
@@ -169,7 +169,7 @@ class ConnectionItem(urwid.WidgetWrap):
r = self.master.replay_request(self.flow)
if r:
signals.status_message.send(message=r)
- self.master.sync_list_view()
+ signals.flowlist_change.send(self)
elif key == "S":
if not self.master.server_playback:
signals.status_prompt_onekey.send(
@@ -195,7 +195,7 @@ class ConnectionItem(urwid.WidgetWrap):
signals.status_message.send(message="Flow not modified.")
return
self.state.revert(self.flow)
- self.master.sync_list_view()
+ signals.flowlist_change.send(self)
signals.status_message.send(message="Reverted.")
elif key == "w":
signals.status_prompt_onekey.send(
@@ -218,7 +218,7 @@ class ConnectionItem(urwid.WidgetWrap):
callback = self.master.run_script_once,
args = (self.flow,)
)
- elif key == "g":
+ elif key == "P":
common.ask_copy_part("a", self.flow, self.master, self.state)
elif key == "b":
common.ask_save_body(None, self.master, self.state, self.flow)
@@ -231,6 +231,10 @@ class FlowListWalker(urwid.ListWalker):
self.master, self.state = master, state
if self.state.flow_count():
self.set_focus(0)
+ signals.flowlist_change.connect(self.sig_flowlist_change)
+
+ def sig_flowlist_change(self, sender):
+ self._modified()
def get_focus(self):
f, i = self.state.get_focus()
@@ -255,7 +259,10 @@ class FlowListWalker(urwid.ListWalker):
class FlowListBox(urwid.ListBox):
def __init__(self, master):
self.master = master
- urwid.ListBox.__init__(self, master.flow_list_walker)
+ urwid.ListBox.__init__(
+ self,
+ FlowListWalker(master, master.state)
+ )
def get_method_raw(self, k):
if k:
@@ -297,7 +304,7 @@ class FlowListBox(urwid.ListBox):
key = common.shortcuts(key)
if key == "A":
self.master.accept_all()
- self.master.sync_list_view()
+ signals.flowlist_change.send(self)
elif key == "C":
self.master.clear_flows()
elif key == "e":
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 99844cb7..9776f2b1 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -20,7 +20,6 @@ def _mkhelp():
("D", "duplicate flow"),
("e", "edit request/response"),
("f", "load full body data"),
- ("g", "copy response(content/headers) to clipboard"),
("m", "change body display mode for this entity"),
(None,
common.highlight_key("automatic", "a") +
@@ -60,6 +59,7 @@ def _mkhelp():
),
("M", "change default body display mode"),
("p", "previous flow"),
+ ("P", "copy response(content/headers) to clipboard"),
("r", "replay request"),
("V", "revert changes to request"),
("v", "view body in external viewer"),
@@ -546,7 +546,7 @@ class FlowView(tabs.Tabs):
)
signals.flow_change.send(self, flow = self.flow)
signals.status_message.send(message="")
- elif key == "g":
+ elif key == "P":
if self.tab_offset == TAB_REQ:
scope = "q"
else:
diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py
index 44195798..0da29907 100644
--- a/libmproxy/console/help.py
+++ b/libmproxy/console/help.py
@@ -103,25 +103,3 @@ class HelpView(urwid.ListBox):
elif key == "?":
key = None
return urwid.ListBox.keypress(self, size, key)
-
-
-class PalettePicker(urwid.WidgetWrap):
- def __init__(self, master):
- self.master = master
- self.lb = select.Select(
- [
- select.Heading("Low"),
- select.Option(
- "One Two",
- "O",
- ),
- ]
- )
- title = urwid.Text("Palettes")
- title = urwid.Padding(title, align="left", width=("relative", 100))
- title = urwid.AttrWrap(title, "heading")
- self._w = urwid.Frame(
- self.lb,
- header = title
- )
-
diff --git a/libmproxy/console/options.py b/libmproxy/console/options.py
index 23774dc3..dc7e00d5 100644
--- a/libmproxy/console/options.py
+++ b/libmproxy/console/options.py
@@ -1,7 +1,7 @@
import urwid
from . import common, signals, grideditor, contentview
-from . import select
+from . import select, palettes
footer = [
('heading_key', "enter/space"), ":toggle ",
@@ -60,7 +60,7 @@ class Options(urwid.WidgetWrap):
select.Option(
"Palette",
"P",
- lambda: False,
+ lambda: self.master.palette != palettes.DEFAULT,
self.palette
),
select.Option(
diff --git a/libmproxy/console/signals.py b/libmproxy/console/signals.py
index e4c11f5a..6d429b93 100644
--- a/libmproxy/console/signals.py
+++ b/libmproxy/console/signals.py
@@ -24,6 +24,8 @@ update_settings = blinker.Signal()
# Fired when a flow changes
flow_change = blinker.Signal()
+# Fired when the flow list changes
+flowlist_change = blinker.Signal()
# Pop and push view state onto a stack
pop_view_state = blinker.Signal()
diff --git a/libmproxy/console/statusbar.py b/libmproxy/console/statusbar.py
index 7fb15aa6..5455ad6e 100644
--- a/libmproxy/console/statusbar.py
+++ b/libmproxy/console/statusbar.py
@@ -114,6 +114,7 @@ class StatusBar(urwid.WidgetWrap):
self.ib = urwid.WidgetWrap(urwid.Text(""))
self._w = urwid.Pile([self.ib, self.ab])
signals.update_settings.connect(self.sig_update_settings)
+ signals.flowlist_change.connect(self.sig_update_settings)
self.redraw()
def sig_update_settings(self, sender):