From a617e3b5f717b95d1ffc8c87dd70712e36445be9 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 5 Dec 2016 17:49:16 +1300 Subject: Amalgamate all the Options objects --- mitmproxy/options.py | 47 ++++++++++++++++++++++++++++++++++- mitmproxy/tools/console/master.py | 28 --------------------- mitmproxy/tools/main.py | 7 +++--- mitmproxy/tools/web/master.py | 21 ---------------- test/mitmproxy/console/test_master.py | 11 ++++---- test/mitmproxy/test_web_app.py | 3 ++- test/mitmproxy/test_web_master.py | 5 ++-- 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 06ea30ee..157b0168 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -82,7 +82,29 @@ class Options(optmanager.OptManager): ssl_insecure: bool = False, ssl_verify_upstream_trusted_cadir: Optional[str] = None, ssl_verify_upstream_trusted_ca: Optional[str] = None, - tcp_hosts: Sequence[str] = [] + tcp_hosts: Sequence[str] = [], + + intercept: Optional[str] = None, + + # Console options + eventlog: bool = False, + focus_follow: bool = False, + filter: Optional[str] = None, + palette: Optional[str] = "dark", + palette_transparent: bool = False, + no_mouse: bool = False, + order: Optional[str] = None, + order_reversed: bool = False, + + # Web options + open_browser: bool = True, + wdebug: bool = False, + wport: int = 8081, + wiface: str = "127.0.0.1", + + # Dump options + filtstr: Optional[str] = None, + flow_detail: int = 1 ) -> None: # We could replace all assignments with clever metaprogramming, # but type hints are a much more valueable asset. @@ -146,4 +168,27 @@ class Options(optmanager.OptManager): self.ssl_verify_upstream_trusted_cadir = ssl_verify_upstream_trusted_cadir self.ssl_verify_upstream_trusted_ca = ssl_verify_upstream_trusted_ca self.tcp_hosts = tcp_hosts + + self.intercept = intercept + + # Console options + self.eventlog = eventlog + self.focus_follow = focus_follow + self.filter = filter + self.palette = palette + self.palette_transparent = palette_transparent + self.no_mouse = no_mouse + self.order = order + self.order_reversed = order_reversed + + # Web options + self.open_browser = open_browser + self.wdebug = wdebug + self.wport = wport + self.wiface = wiface + + # Dump options + self.filtstr = filtstr + self.flow_detail = flow_detail + super().__init__() diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 27f5cb58..9b6cc6ab 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -11,7 +11,6 @@ import tempfile import traceback import urwid -from typing import Optional from mitmproxy import addons from mitmproxy import controller @@ -39,33 +38,6 @@ from mitmproxy.net import tcp EVENTLOG_SIZE = 500 -class Options(mitmproxy.options.Options): - def __init__( - self, - *, # all args are keyword-only. - eventlog: bool = False, - focus_follow: bool = False, - intercept: Optional[str] = None, - filter: Optional[str] = None, - palette: Optional[str] = palettes.DEFAULT, - palette_transparent: bool = False, - no_mouse: bool = False, - order: Optional[str] = None, - order_reversed: bool = False, - **kwargs - ): - self.eventlog = eventlog - self.focus_follow = focus_follow - self.intercept = intercept - self.filter = filter - self.palette = palette - self.palette_transparent = palette_transparent - self.no_mouse = no_mouse - self.order = order - self.order_reversed = order_reversed - super().__init__(**kwargs) - - class ConsoleMaster(master.Master): palette = [] diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index a6b75db1..3c0e44bc 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -11,6 +11,7 @@ import signal # noqa from mitmproxy.tools import cmdline # noqa from mitmproxy import exceptions # noqa +from mitmproxy import options # noqa from mitmproxy.proxy import config # noqa from mitmproxy.proxy import server # noqa from mitmproxy.utils import version_check # noqa @@ -71,7 +72,7 @@ def mitmproxy(args=None): # pragma: no cover args = parser.parse_args(args) try: - console_options = console.master.Options() + console_options = options.Options() console_options.load_paths(args.conf) console_options.update(**notnone(cmdline.get_common_options(args))) console_options.update( @@ -110,7 +111,7 @@ def mitmdump(args=None): # pragma: no cover master = None try: - dump_options = dump.Options() + dump_options = options.Options() dump_options.load_paths(args.conf) dump_options.update(**notnone(cmdline.get_common_options(args))) dump_options.update( @@ -149,7 +150,7 @@ def mitmweb(args=None): # pragma: no cover args = parser.parse_args(args) try: - web_options = web.master.Options() + web_options = options.Options() web_options.load_paths(args.conf) web_options.update(**notnone(cmdline.get_common_options(args))) web_options.update( diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index 36bdcb07..edb12467 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -1,5 +1,4 @@ import webbrowser -from typing import Optional import tornado.httpserver import tornado.ioloop @@ -7,7 +6,6 @@ from mitmproxy import addons from mitmproxy import exceptions from mitmproxy import log from mitmproxy import master -from mitmproxy import options from mitmproxy.addons import eventstore from mitmproxy.addons import intercept from mitmproxy.addons import termlog @@ -15,25 +13,6 @@ from mitmproxy.addons import view from mitmproxy.tools.web import app -class Options(options.Options): - def __init__( - self, - *, # all args are keyword-only. - intercept: Optional[str] = None, - open_browser: bool = True, - wdebug: bool = False, - wport: int = 8081, - wiface: str = "127.0.0.1", - **kwargs - ) -> None: - self.intercept = intercept - self.open_browser = open_browser - self.wdebug = wdebug - self.wport = wport - self.wiface = wiface - super().__init__(**kwargs) - - class WebMaster(master.Master): def __init__(self, options, server): super().__init__(options, server) diff --git a/test/mitmproxy/console/test_master.py b/test/mitmproxy/console/test_master.py index eb840187..fb3c2527 100644 --- a/test/mitmproxy/console/test_master.py +++ b/test/mitmproxy/console/test_master.py @@ -2,6 +2,7 @@ from mitmproxy.test import tflow import mitmproxy.test.tutils from mitmproxy.tools import console from mitmproxy import proxy +from mitmproxy import options from mitmproxy.tools.console import common from .. import mastertest @@ -20,14 +21,14 @@ def test_format_keyvals(): def test_options(): - assert console.master.Options(replay_kill_extra=True) + assert options.Options(replay_kill_extra=True) class TestMaster(mastertest.MasterTest): - def mkmaster(self, **options): - if "verbosity" not in options: - options["verbosity"] = 0 - o = console.master.Options(**options) + def mkmaster(self, **opts): + if "verbosity" not in opts: + opts["verbosity"] = 0 + o = options.Options(**opts) return console.master.ConsoleMaster(o, proxy.DummyServer()) def test_basic(self): diff --git a/test/mitmproxy/test_web_app.py b/test/mitmproxy/test_web_app.py index be195528..2cab5bf4 100644 --- a/test/mitmproxy/test_web_app.py +++ b/test/mitmproxy/test_web_app.py @@ -4,6 +4,7 @@ import mock import tornado.testing from mitmproxy import exceptions from mitmproxy import proxy +from mitmproxy import options from mitmproxy.test import tflow from mitmproxy.tools.web import app from mitmproxy.tools.web import master as webmaster @@ -17,7 +18,7 @@ def json(resp: httpclient.HTTPResponse): class TestApp(tornado.testing.AsyncHTTPTestCase): def get_app(self): - o = webmaster.Options() + o = options.Options() m = webmaster.WebMaster(o, proxy.DummyServer()) f = tflow.tflow(resp=True) f.id = "42" diff --git a/test/mitmproxy/test_web_master.py b/test/mitmproxy/test_web_master.py index 298b14eb..08dce8f3 100644 --- a/test/mitmproxy/test_web_master.py +++ b/test/mitmproxy/test_web_master.py @@ -1,11 +1,12 @@ from mitmproxy.tools.web import master from mitmproxy import proxy +from mitmproxy import options from . import mastertest class TestWebMaster(mastertest.MasterTest): - def mkmaster(self, **options): - o = master.Options(**options) + def mkmaster(self, **opts): + o = options.Options(**opts) return master.WebMaster(o, proxy.DummyServer(o)) def test_basic(self): -- cgit v1.2.3