From 2aa97c9b75989e20faf475fed5da1363e8bed87b Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 08:41:57 +0800 Subject: Move console-relatived options into their own addons. --- mitmproxy/options.py | 60 -------------------------------- mitmproxy/tools/console/consoleaddons.py | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 20151c19..87318919 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -4,29 +4,6 @@ from mitmproxy import optmanager from mitmproxy import contentviews from mitmproxy.net import tcp -# We redefine these here for now to avoid importing Urwid-related guff on -# platforms that don't support it, and circular imports. We can do better using -# a lazy checker down the track. -console_palettes = [ - "lowlight", - "lowdark", - "light", - "dark", - "solarized_light", - "solarized_dark" -] -view_orders = [ - "time", - "method", - "url", - "size", -] -console_layouts = [ - "single", - "vertical", - "horizontal", -] - log_verbosity = [ "error", "warn", @@ -474,43 +451,6 @@ class Options(optmanager.OptManager): "Intercept filter expression." ) - # Console options - self.add_option( - "console_layout", str, "single", - "Console layout.", - choices=sorted(console_layouts), - ) - self.add_option( - "console_layout_headers", bool, True, - "Show layout comonent headers", - ) - self.add_option( - "console_focus_follow", bool, False, - "Focus follows new flows." - ) - self.add_option( - "console_palette", str, "solarized_dark", - "Color palette.", - choices=sorted(console_palettes), - ) - self.add_option( - "console_palette_transparent", bool, False, - "Set transparent background for palette." - ) - self.add_option( - "console_mouse", bool, True, - "Console mouse interaction." - ) - self.add_option( - "console_order", str, "time", - "Flow sort order.", - choices=view_orders, - ) - self.add_option( - "console_order_reversed", bool, False, - "Reverse the sorting order." - ) - self.add_option( "view_filter", Optional[str], None, "Limit which flows are displayed." diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 0b0993c8..f561f61e 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -11,6 +11,29 @@ from mitmproxy.tools.console import overlay from mitmproxy.tools.console import signals from mitmproxy.tools.console import keymap +# We redefine these here for now to avoid importing Urwid-related guff on +# platforms that don't support it, and circular imports. We can do better using +# a lazy checker down the track. +console_palettes = [ + "lowlight", + "lowdark", + "light", + "dark", + "solarized_light", + "solarized_dark" +] +view_orders = [ + "time", + "method", + "url", + "size", +] +console_layouts = [ + "single", + "vertical", + "horizontal", +] + class Logger: def log(self, evt): @@ -60,6 +83,43 @@ class ConsoleAddon: self.master = master self.started = False + def load(self, loader): + loader.add_option( + "console_layout", str, "single", + "Console layout.", + choices=sorted(console_layouts), + ) + loader.add_option( + "console_layout_headers", bool, True, + "Show layout comonent headers", + ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + loader.add_option( + "console_palette", str, "solarized_dark", + "Color palette.", + choices=sorted(console_palettes), + ) + loader.add_option( + "console_palette_transparent", bool, False, + "Set transparent background for palette." + ) + loader.add_option( + "console_mouse", bool, True, + "Console mouse interaction." + ) + loader.add_option( + "console_order", str, "time", + "Flow sort order.", + choices=view_orders, + ) + loader.add_option( + "console_order_reversed", bool, False, + "Reverse the sorting order." + ) + @command.command("console.layout.options") def layout_options(self) -> typing.Sequence[str]: """ -- cgit v1.2.3 From 2ceaa5c9efd3bbbb7fdb6b0d3ebdb8de32305f92 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 08:42:51 +0800 Subject: Update tests. --- test/mitmproxy/addons/test_view.py | 12 ++++++++---- test/mitmproxy/tools/console/test_statusbar.py | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index e8eeb591..9a9534f9 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -7,6 +7,10 @@ from mitmproxy import flowfilter from mitmproxy import exceptions from mitmproxy import io from mitmproxy.test import taddons +from mitmproxy import options +from mitmproxy.tools.console.master import ConsoleMaster + +m = ConsoleMaster(options.Options()) def tft(*, method="get", start=0): @@ -26,7 +30,7 @@ def test_order_refresh(): v.sig_view_refresh.connect(save) tf = tflow.tflow(resp=True) - with taddons.context() as tctx: + with taddons.context(m) as tctx: tctx.configure(v, console_order="time") v.add([tf]) tf.request.timestamp_start = 1 @@ -293,7 +297,7 @@ def test_setgetval(): def test_order(): v = view.View() - with taddons.context() as tctx: + with taddons.context(m) as tctx: v.request(tft(method="get", start=1)) v.request(tft(method="put", start=2)) v.request(tft(method="get", start=3)) @@ -424,7 +428,7 @@ def test_signals(): def test_focus_follow(): v = view.View() - with taddons.context() as tctx: + with taddons.context(m) as tctx: tctx.configure(v, console_focus_follow=True, view_filter="~m get") v.add([tft(start=5)]) @@ -541,7 +545,7 @@ def test_settings(): def test_configure(): v = view.View() - with taddons.context() as tctx: + with taddons.context(m) as tctx: tctx.configure(v, view_filter="~q") with pytest.raises(Exception, match="Invalid interception filter"): tctx.configure(v, view_filter="~~") diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py index 2f7825c9..34981e42 100644 --- a/test/mitmproxy/tools/console/test_statusbar.py +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -13,14 +13,12 @@ def test_statusbar(monkeypatch): stickycookie="~dst example.com", stickyauth="~dst example.com", default_contentview="javascript", - console_order="url", anticache=True, anticomp=True, showhost=True, refresh_server_playback=False, replay_kill_extra=True, upstream_cert=False, - console_focus_follow=True, stream_large_bodies="3m", mode="transparent", scripts=["nonexistent"], -- cgit v1.2.3 From f078808fc60e3c4755bdcc664fac9518c52c7692 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 09:01:31 +0800 Subject: Adjust --verbose options to string type. --- mitmproxy/tools/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index 68ddc2c8..f919486b 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -48,7 +48,7 @@ def common_options(parser, opts): ) parser.add_argument( "-v", "--verbose", - action="store_const", dest="verbose", const=3, + action="store_const", dest="verbose", const='debug', help="Increase log verbosity." ) -- cgit v1.2.3 From e533d02d98e54320f437fef529fe632d8930c401 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 19:32:49 +0800 Subject: Remove redundant comment. --- mitmproxy/tools/console/consoleaddons.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index f561f61e..0d20fd94 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -11,9 +11,6 @@ from mitmproxy.tools.console import overlay from mitmproxy.tools.console import signals from mitmproxy.tools.console import keymap -# We redefine these here for now to avoid importing Urwid-related guff on -# platforms that don't support it, and circular imports. We can do better using -# a lazy checker down the track. console_palettes = [ "lowlight", "lowdark", -- cgit v1.2.3 From 7bbd89b121334a6eec2e88897ef85b03034eb700 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 22:58:27 +0800 Subject: Change console_order and console_order_reversed options Change console_order and console_order_reversed to view_order and view_order_reversed, and move them to the view addon. --- mitmproxy/addons/view.py | 23 +++++++++++++++++------ mitmproxy/tools/console/consoleaddons.py | 9 --------- mitmproxy/tools/console/statusbar.py | 6 +++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index b2db0171..2c02b72b 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -145,6 +145,17 @@ class View(collections.Sequence): self.focus = Focus(self) self.settings = Settings(self) + def load(self, loader): + loader.add_option( + "view_order", str, "time", + "Flow sort order.", + choices=list(map(lambda c: c[1], orders)), + ) + loader.add_option( + "view_order_reversed", bool, False, + "Reverse the sorting order." + ) + def store_count(self): return len(self._store) @@ -442,14 +453,14 @@ class View(collections.Sequence): "Invalid interception filter: %s" % ctx.options.view_filter ) self.set_filter(filt) - if "console_order" in updated: - if ctx.options.console_order not in self.orders: + if "view_order" in updated: + if ctx.options.view_order not in self.orders: raise exceptions.OptionsError( - "Unknown flow order: %s" % ctx.options.console_order + "Unknown flow order: %s" % ctx.options.view_order ) - self.set_order(self.orders[ctx.options.console_order]) - if "console_order_reversed" in updated: - self.set_reversed(ctx.options.console_order_reversed) + self.set_order(self.orders[ctx.options.view_order]) + if "view_order_reversed" in updated: + self.set_reversed(ctx.options.view_order_reversed) if "console_focus_follow" in updated: self.focus_follow = ctx.options.console_focus_follow diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 0d20fd94..87542fd4 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -107,15 +107,6 @@ class ConsoleAddon: "console_mouse", bool, True, "Console mouse interaction." ) - loader.add_option( - "console_order", str, "time", - "Flow sort order.", - choices=view_orders, - ) - loader.add_option( - "console_order_reversed", bool, False, - "Reverse the sorting order." - ) @command.command("console.layout.options") def layout_options(self) -> typing.Sequence[str]: diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index 5bfc611c..795b3d8a 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -199,10 +199,10 @@ class StatusBar(urwid.WidgetWrap): r.append("[") r.append(("heading_key", "M")) r.append(":%s]" % self.master.options.default_contentview) - if self.master.options.has_changed("console_order"): + if self.master.options.has_changed("view_order"): r.append("[") r.append(("heading_key", "o")) - r.append(":%s]" % self.master.options.console_order) + r.append(":%s]" % self.master.options.view_order) opts = [] if self.master.options.anticache: @@ -244,7 +244,7 @@ class StatusBar(urwid.WidgetWrap): else: offset = self.master.view.focus.index + 1 - if self.master.options.console_order_reversed: + if self.master.options.view_order_reversed: arrow = common.SYMBOL_UP else: arrow = common.SYMBOL_DOWN -- cgit v1.2.3 From ddffcf83ecef8b6c81e5f23ff57ae17af6131219 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 1 Aug 2017 23:01:58 +0800 Subject: Update tests. --- mitmproxy/test/taddons.py | 2 ++ test/mitmproxy/addons/test_script.py | 6 ++++++ test/mitmproxy/addons/test_view.py | 29 +++++++++++++++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py index 6160746a..3859e4d2 100644 --- a/mitmproxy/test/taddons.py +++ b/mitmproxy/test/taddons.py @@ -105,6 +105,8 @@ class context: Options object with the given keyword arguments, then calls the configure method on the addon with the updated value. """ + loader = addonmanager.Loader(self.master) + self.master.addons.invoke_addon(addon, "load", loader) with self.options.rollback(kwargs.keys(), reraise=True): self.options.update(**kwargs) self.master.addons.invoke_addon( diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 64fd9505..5b05aec8 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -260,6 +260,9 @@ class TestScriptLoader: debug = [i.msg for i in tctx.master.logs if i.level == "debug"] assert debug == [ + 'a load', + 'b load', + 'c load', 'c configure', 'a configure', 'b configure', @@ -277,6 +280,9 @@ class TestScriptLoader: debug = [i.msg for i in tctx.master.logs if i.level == "debug"] assert debug == [ + 'c load', + 'a load', + 'b load', 'c done', 'b done', 'a configure', diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 9a9534f9..a2e45e9b 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -7,10 +7,7 @@ from mitmproxy import flowfilter from mitmproxy import exceptions from mitmproxy import io from mitmproxy.test import taddons -from mitmproxy import options -from mitmproxy.tools.console.master import ConsoleMaster - -m = ConsoleMaster(options.Options()) +from mitmproxy.tools.console import consoleaddons def tft(*, method="get", start=0): @@ -30,8 +27,8 @@ def test_order_refresh(): v.sig_view_refresh.connect(save) tf = tflow.tflow(resp=True) - with taddons.context(m) as tctx: - tctx.configure(v, console_order="time") + with taddons.context() as tctx: + tctx.configure(v, view_order="time") v.add([tf]) tf.request.timestamp_start = 1 assert not sargs @@ -297,19 +294,19 @@ def test_setgetval(): def test_order(): v = view.View() - with taddons.context(m) as tctx: + with taddons.context() as tctx: v.request(tft(method="get", start=1)) v.request(tft(method="put", start=2)) v.request(tft(method="get", start=3)) v.request(tft(method="put", start=4)) assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] - tctx.configure(v, console_order="method") + tctx.configure(v, view_order="method") assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"] v.set_reversed(True) assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"] - tctx.configure(v, console_order="time") + tctx.configure(v, view_order="time") assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1] v.set_reversed(False) @@ -428,7 +425,9 @@ def test_signals(): def test_focus_follow(): v = view.View() - with taddons.context(m) as tctx: + with taddons.context() as tctx: + console_addon = consoleaddons.ConsoleAddon(tctx.master) + tctx.configure(console_addon) tctx.configure(v, console_focus_follow=True, view_filter="~m get") v.add([tft(start=5)]) @@ -545,16 +544,18 @@ def test_settings(): def test_configure(): v = view.View() - with taddons.context(m) as tctx: + with taddons.context() as tctx: tctx.configure(v, view_filter="~q") with pytest.raises(Exception, match="Invalid interception filter"): tctx.configure(v, view_filter="~~") - tctx.configure(v, console_order="method") + tctx.configure(v, view_order="method") with pytest.raises(Exception, match="Unknown flow order"): - tctx.configure(v, console_order="no") + tctx.configure(v, view_order="no") - tctx.configure(v, console_order_reversed=True) + tctx.configure(v, view_order_reversed=True) + console_addon = consoleaddons.ConsoleAddon(tctx.master) + tctx.configure(console_addon) tctx.configure(v, console_focus_follow=True) assert v.focus_follow -- cgit v1.2.3 From b42f5bcb9dd6a8d2609b8351f846a654a1fd65c2 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Thu, 3 Aug 2017 18:53:08 +0800 Subject: Update taddon and tests. --- mitmproxy/addonmanager.py | 4 ++++ mitmproxy/test/taddons.py | 4 ++-- test/mitmproxy/addons/test_script.py | 6 ------ test/mitmproxy/tools/console/test_statusbar.py | 3 ++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index 857ed530..31665548 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -202,6 +202,10 @@ class AddonManager: def __str__(self): return pprint.pformat([str(i) for i in self.chain]) + def __contains__(self, item): + name = _get_name(item) + return name in self.lookup + def handle_lifecycle(self, name, message): """ Handle a lifecycle event. diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py index 3859e4d2..d966f1d5 100644 --- a/mitmproxy/test/taddons.py +++ b/mitmproxy/test/taddons.py @@ -105,8 +105,8 @@ class context: Options object with the given keyword arguments, then calls the configure method on the addon with the updated value. """ - loader = addonmanager.Loader(self.master) - self.master.addons.invoke_addon(addon, "load", loader) + if addon not in self.master.addons: + self.master.addons.register(addon) with self.options.rollback(kwargs.keys(), reraise=True): self.options.update(**kwargs) self.master.addons.invoke_addon( diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 5b05aec8..64fd9505 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -260,9 +260,6 @@ class TestScriptLoader: debug = [i.msg for i in tctx.master.logs if i.level == "debug"] assert debug == [ - 'a load', - 'b load', - 'c load', 'c configure', 'a configure', 'b configure', @@ -280,9 +277,6 @@ class TestScriptLoader: debug = [i.msg for i in tctx.master.logs if i.level == "debug"] assert debug == [ - 'c load', - 'a load', - 'b load', 'c done', 'b done', 'a configure', diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py index 34981e42..0cb36c45 100644 --- a/test/mitmproxy/tools/console/test_statusbar.py +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -1,5 +1,5 @@ from mitmproxy import options -from mitmproxy.tools.console import statusbar, master +from mitmproxy.tools.console import statusbar, master, consoleaddons def test_statusbar(monkeypatch): @@ -25,6 +25,7 @@ def test_statusbar(monkeypatch): save_stream_file="foo", ) m = master.ConsoleMaster(o) + m.options.update(view_order='url', console_focus_follow=True) monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42) monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42) -- cgit v1.2.3 From ca2126b385d08d636b87432d4224389f91a47075 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Fri, 4 Aug 2017 10:59:42 +0800 Subject: Add consoleaddons.common_options to suggest dependency. --- mitmproxy/addons/view.py | 3 ++ mitmproxy/tools/console/consoleaddons.py | 55 +++++++++++++++++--------------- mitmproxy/tools/console/eventlog.py | 4 +++ 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 2c02b72b..b8bb42bb 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -23,6 +23,7 @@ from mitmproxy import connections from mitmproxy import ctx from mitmproxy import io from mitmproxy import http # noqa +from mitmproxy.tools.console import consoleaddons # The underlying sorted list implementation expects the sort key to be stable # for the lifetime of the object. However, if we sort by size, for instance, @@ -146,6 +147,8 @@ class View(collections.Sequence): self.settings = Settings(self) def load(self, loader): + + consoleaddons.common_options(loader) loader.add_option( "view_order", str, "time", "Flow sort order.", diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 87542fd4..a9903359 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -81,32 +81,7 @@ class ConsoleAddon: self.started = False def load(self, loader): - loader.add_option( - "console_layout", str, "single", - "Console layout.", - choices=sorted(console_layouts), - ) - loader.add_option( - "console_layout_headers", bool, True, - "Show layout comonent headers", - ) - loader.add_option( - "console_focus_follow", bool, False, - "Focus follows new flows." - ) - loader.add_option( - "console_palette", str, "solarized_dark", - "Color palette.", - choices=sorted(console_palettes), - ) - loader.add_option( - "console_palette_transparent", bool, False, - "Set transparent background for palette." - ) - loader.add_option( - "console_mouse", bool, True, - "Console mouse interaction." - ) + common_options(loader) @command.command("console.layout.options") def layout_options(self) -> typing.Sequence[str]: @@ -553,3 +528,31 @@ class ConsoleAddon: signals.update_settings.send(self) for f in flows: signals.flow_change.send(self, flow=f) + +def common_options(loader): + loader.add_option( + "console_layout", str, "single", + "Console layout.", + choices=sorted(console_layouts), + ) + loader.add_option( + "console_layout_headers", bool, True, + "Show layout comonent headers", + ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + loader.add_option( + "console_palette", str, "solarized_dark", + "Color palette.", + choices=sorted(console_palettes), + ) + loader.add_option( + "console_palette_transparent", bool, False, + "Set transparent background for palette." + ) + loader.add_option( + "console_mouse", bool, True, + "Console mouse interaction." + ) \ No newline at end of file diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py index a76b910e..d35e24c3 100644 --- a/mitmproxy/tools/console/eventlog.py +++ b/mitmproxy/tools/console/eventlog.py @@ -1,6 +1,7 @@ import urwid from mitmproxy.tools.console import signals from mitmproxy.tools.console import layoutwidget +from mitmproxy.tools.console import consoleaddons from mitmproxy import ctx from mitmproxy import log @@ -22,6 +23,9 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget): signals.sig_add_log.connect(self.sig_add_log) signals.sig_clear_log.connect(self.sig_clear_log) + def load(self, loader): + consoleaddons.common_options(loader) + def set_focus(self, index): if 0 <= index < len(self.walker): super().set_focus(index) -- cgit v1.2.3 From cd222ff4f92c9018813f55a54694e76dba72aa6d Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sat, 5 Aug 2017 09:17:38 +0800 Subject: Fix lint. --- mitmproxy/tools/console/consoleaddons.py | 3 ++- test/mitmproxy/addons/test_view.py | 2 -- test/mitmproxy/tools/console/test_statusbar.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index a9903359..0a36018e 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -529,6 +529,7 @@ class ConsoleAddon: for f in flows: signals.flow_change.send(self, flow=f) + def common_options(loader): loader.add_option( "console_layout", str, "single", @@ -555,4 +556,4 @@ def common_options(loader): loader.add_option( "console_mouse", bool, True, "Console mouse interaction." - ) \ No newline at end of file + ) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index a2e45e9b..1e0c3b55 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -555,7 +555,5 @@ def test_configure(): tctx.configure(v, view_order_reversed=True) - console_addon = consoleaddons.ConsoleAddon(tctx.master) - tctx.configure(console_addon) tctx.configure(v, console_focus_follow=True) assert v.focus_follow diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py index 0cb36c45..b131a5d3 100644 --- a/test/mitmproxy/tools/console/test_statusbar.py +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -1,5 +1,5 @@ from mitmproxy import options -from mitmproxy.tools.console import statusbar, master, consoleaddons +from mitmproxy.tools.console import statusbar, master def test_statusbar(monkeypatch): -- cgit v1.2.3 From 43e5647cefadd762d1ab14b20ea4c655dd45854e Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sat, 5 Aug 2017 11:30:12 +0800 Subject: Add console_focus_follow in view and eventlog addons. --- mitmproxy/addons/view.py | 7 ++-- mitmproxy/tools/console/consoleaddons.py | 56 +++++++++++++++----------------- mitmproxy/tools/console/eventlog.py | 6 ++-- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index b8bb42bb..8ae1f341 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -23,7 +23,6 @@ from mitmproxy import connections from mitmproxy import ctx from mitmproxy import io from mitmproxy import http # noqa -from mitmproxy.tools.console import consoleaddons # The underlying sorted list implementation expects the sort key to be stable # for the lifetime of the object. However, if we sort by size, for instance, @@ -147,8 +146,6 @@ class View(collections.Sequence): self.settings = Settings(self) def load(self, loader): - - consoleaddons.common_options(loader) loader.add_option( "view_order", str, "time", "Flow sort order.", @@ -158,6 +155,10 @@ class View(collections.Sequence): "view_order_reversed", bool, False, "Reverse the sorting order." ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) def store_count(self): return len(self._store) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 0a36018e..87542fd4 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -81,7 +81,32 @@ class ConsoleAddon: self.started = False def load(self, loader): - common_options(loader) + loader.add_option( + "console_layout", str, "single", + "Console layout.", + choices=sorted(console_layouts), + ) + loader.add_option( + "console_layout_headers", bool, True, + "Show layout comonent headers", + ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + loader.add_option( + "console_palette", str, "solarized_dark", + "Color palette.", + choices=sorted(console_palettes), + ) + loader.add_option( + "console_palette_transparent", bool, False, + "Set transparent background for palette." + ) + loader.add_option( + "console_mouse", bool, True, + "Console mouse interaction." + ) @command.command("console.layout.options") def layout_options(self) -> typing.Sequence[str]: @@ -528,32 +553,3 @@ class ConsoleAddon: signals.update_settings.send(self) for f in flows: signals.flow_change.send(self, flow=f) - - -def common_options(loader): - loader.add_option( - "console_layout", str, "single", - "Console layout.", - choices=sorted(console_layouts), - ) - loader.add_option( - "console_layout_headers", bool, True, - "Show layout comonent headers", - ) - loader.add_option( - "console_focus_follow", bool, False, - "Focus follows new flows." - ) - loader.add_option( - "console_palette", str, "solarized_dark", - "Color palette.", - choices=sorted(console_palettes), - ) - loader.add_option( - "console_palette_transparent", bool, False, - "Set transparent background for palette." - ) - loader.add_option( - "console_mouse", bool, True, - "Console mouse interaction." - ) diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py index d35e24c3..c3e5dd39 100644 --- a/mitmproxy/tools/console/eventlog.py +++ b/mitmproxy/tools/console/eventlog.py @@ -1,7 +1,6 @@ import urwid from mitmproxy.tools.console import signals from mitmproxy.tools.console import layoutwidget -from mitmproxy.tools.console import consoleaddons from mitmproxy import ctx from mitmproxy import log @@ -24,7 +23,10 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget): signals.sig_clear_log.connect(self.sig_clear_log) def load(self, loader): - consoleaddons.common_options(loader) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) def set_focus(self, index): if 0 <= index < len(self.walker): -- cgit v1.2.3 From 56781a0b08a0453fef0ff3f34d06c41c378cd7bc Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 8 Aug 2017 19:43:51 +0800 Subject: Add test for AddonManager.__contains__ --- test/mitmproxy/test_addonmanager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py index accf48e0..274d2d90 100644 --- a/test/mitmproxy/test_addonmanager.py +++ b/test/mitmproxy/test_addonmanager.py @@ -137,6 +137,8 @@ def test_simple(): a.trigger("custom") assert ta.custom_called + assert ta in a + def test_load_option(): o = options.Options() -- cgit v1.2.3