aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-18 09:58:57 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-18 10:03:10 +1200
commitf9e4249499f369932241b722e705575a0730fc75 (patch)
tree02c2f47c1a482563d3be66e4209e64519b8ae7b7
parent7b57c2948eb5bdfc5e1704e30fdd12e721f345ea (diff)
downloadmitmproxy-f9e4249499f369932241b722e705575a0730fc75.tar.gz
mitmproxy-f9e4249499f369932241b722e705575a0730fc75.tar.bz2
mitmproxy-f9e4249499f369932241b722e705575a0730fc75.zip
Add a toggller helper to Options, start using it in mitmproxy console
-rw-r--r--mitmproxy/console/flowlist.py2
-rw-r--r--mitmproxy/console/flowview.py4
-rw-r--r--mitmproxy/console/master.py1
-rw-r--r--mitmproxy/console/options.py9
-rw-r--r--mitmproxy/console/statusbar.py2
-rw-r--r--mitmproxy/options.py13
-rw-r--r--test/mitmproxy/test_options.py11
7 files changed, 31 insertions, 11 deletions
diff --git a/mitmproxy/console/flowlist.py b/mitmproxy/console/flowlist.py
index ebbe8d21..51424d23 100644
--- a/mitmproxy/console/flowlist.py
+++ b/mitmproxy/console/flowlist.py
@@ -118,7 +118,7 @@ class ConnectionItem(urwid.WidgetWrap):
return common.format_flow(
self.flow,
self.f,
- hostheader = self.master.showhost,
+ hostheader = self.master.options.showhost,
marked=self.state.flow_marked(self.flow)
)
diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py
index d13e9db0..c85a9f73 100644
--- a/mitmproxy/console/flowview.py
+++ b/mitmproxy/console/flowview.py
@@ -110,7 +110,7 @@ class FlowViewHeader(urwid.WidgetWrap):
f,
False,
extended=True,
- hostheader=self.master.showhost
+ hostheader=self.master.options.showhost
)
signals.flow_change.connect(self.sig_flow_change)
@@ -120,7 +120,7 @@ class FlowViewHeader(urwid.WidgetWrap):
flow,
False,
extended=True,
- hostheader=self.master.showhost
+ hostheader=self.master.options.showhost
)
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py
index a93eeddf..2d79f802 100644
--- a/mitmproxy/console/master.py
+++ b/mitmproxy/console/master.py
@@ -225,7 +225,6 @@ class ConsoleMaster(flow.FlowMaster):
self.killextra = options.kill
self.rheaders = options.rheaders
self.nopop = options.nopop
- self.showhost = options.showhost
self.palette = options.palette
self.palette_transparent = options.palette_transparent
diff --git a/mitmproxy/console/options.py b/mitmproxy/console/options.py
index afb9186d..03aec891 100644
--- a/mitmproxy/console/options.py
+++ b/mitmproxy/console/options.py
@@ -74,8 +74,8 @@ class Options(urwid.WidgetWrap):
select.Option(
"Show Host",
"w",
- lambda: master.showhost,
- self.toggle_showhost
+ lambda: master.options.showhost,
+ master.options.toggler("showhost")
),
select.Heading("Network"),
@@ -153,7 +153,6 @@ class Options(urwid.WidgetWrap):
def clearall(self):
self.master.killextra = False
- self.master.showhost = False
self.master.refresh_server_playback = True
self.master.server.config.no_upstream_cert = False
self.master.set_ignore_filter([])
@@ -165,6 +164,7 @@ class Options(urwid.WidgetWrap):
replacements = [],
scripts = [],
setheaders = [],
+ showhost = False,
stickyauth = None,
stickycookie = None
)
@@ -186,9 +186,6 @@ class Options(urwid.WidgetWrap):
def toggle_killextra(self):
self.master.killextra = not self.master.killextra
- def toggle_showhost(self):
- self.master.showhost = not self.master.showhost
-
def toggle_refresh_server_playback(self):
self.master.refresh_server_playback = not self.master.refresh_server_playback
diff --git a/mitmproxy/console/statusbar.py b/mitmproxy/console/statusbar.py
index 88e2ad0d..ab7ff5d3 100644
--- a/mitmproxy/console/statusbar.py
+++ b/mitmproxy/console/statusbar.py
@@ -194,7 +194,7 @@ class StatusBar(urwid.WidgetWrap):
opts.append("anticache")
if self.master.options.anticomp:
opts.append("anticomp")
- if self.master.showhost:
+ if self.master.options.showhost:
opts.append("showhost")
if not self.master.refresh_server_playback:
opts.append("norefresh")
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index a124eaf6..04353dca 100644
--- a/mitmproxy/options.py
+++ b/mitmproxy/options.py
@@ -76,10 +76,23 @@ class Options(object):
self.changed.send(self)
def setter(self, attr):
+ """
+ Generate a setter for a given attribute. This returns a callable
+ taking a single argument.
+ """
if attr not in self._opts:
raise KeyError("No such option: %s" % attr)
return lambda x: self.__setattr__(attr, x)
+ def toggler(self, attr):
+ """
+ Generate a toggler for a boolean attribute. This returns a callable
+ that takes no arguments.
+ """
+ if attr not in self._opts:
+ raise KeyError("No such option: %s" % attr)
+ return lambda: self.__setattr__(attr, not getattr(self, attr))
+
def __repr__(self):
options = pprint.pformat(self._opts, indent=4).strip(" {}")
if "\n" in options:
diff --git a/test/mitmproxy/test_options.py b/test/mitmproxy/test_options.py
index cdb0d765..af619b27 100644
--- a/test/mitmproxy/test_options.py
+++ b/test/mitmproxy/test_options.py
@@ -52,6 +52,17 @@ def test_setter():
o.setter("nonexistent")
+def test_toggler():
+ o = TO(two=True)
+ f = o.toggler("two")
+ f()
+ assert o.two is False
+ f()
+ assert o.two is True
+ with tutils.raises("no such option"):
+ o.toggler("nonexistent")
+
+
def test_rollback():
o = TO(one="two")