From 7c32d4ea2a435484e83aa459831f74ca483d8e3c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 14:48:42 +1300 Subject: [PATCH] flow.state -> addons.state --- examples/flowbasic | 2 +- mitmproxy/addons/onboarding/app.py | 93 ------------------- mitmproxy/{flow => addons}/state.py | 0 mitmproxy/console/master.py | 5 +- mitmproxy/flow/__init__.py | 2 - mitmproxy/web/master.py | 6 +- .../test_state.py} | 7 +- test/mitmproxy/test_flow.py | 27 +++--- test/mitmproxy/tservers.py | 2 +- 9 files changed, 26 insertions(+), 118 deletions(-) delete mode 100644 mitmproxy/addons/onboarding/app.py rename mitmproxy/{flow => addons}/state.py (100%) rename test/mitmproxy/{test_flow_state.py => addons/test_state.py} (83%) diff --git a/examples/flowbasic b/examples/flowbasic index 0eb163a40..bac98916b 100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -37,7 +37,7 @@ class MyMaster(master.Master): opts = options.Options(cadir="~/.mitmproxy/") config = ProxyConfig(opts) -state = flow.State() +state = state.State() server = ProxyServer(config) m = MyMaster(opts, server, state) m.run() diff --git a/mitmproxy/addons/onboarding/app.py b/mitmproxy/addons/onboarding/app.py deleted file mode 100644 index 20197c096..000000000 --- a/mitmproxy/addons/onboarding/app.py +++ /dev/null @@ -1,93 +0,0 @@ -import os - -import tornado.template -import tornado.web -import tornado.wsgi - -from mitmproxy import utils -from mitmproxy.proxy import config - -loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) - - -class Adapter(tornado.wsgi.WSGIAdapter): - # Tornado doesn't make the WSGI environment available to pages, so this - # hideous monkey patch is the easiest way to get to the mitmproxy.master - # variable. - - def __init__(self, application): - self._application = application - - def application(self, request): - request.master = self.environ["mitmproxy.master"] - return self._application(request) - - def __call__(self, environ, start_response): - self.environ = environ - return tornado.wsgi.WSGIAdapter.__call__( - self, - environ, - start_response - ) - - -class Index(tornado.web.RequestHandler): - - def get(self): - t = loader.load("index.html") - self.write(t.generate()) - - -class PEM(tornado.web.RequestHandler): - - @property - def filename(self): - return config.CONF_BASENAME + "-ca-cert.pem" - - def get(self): - p = os.path.join(self.request.master.options.cadir, self.filename) - p = os.path.expanduser(p) - self.set_header("Content-Type", "application/x-x509-ca-cert") - self.set_header( - "Content-Disposition", - "inline; filename={}".format( - self.filename)) - - with open(p, "rb") as f: - self.write(f.read()) - - -class P12(tornado.web.RequestHandler): - - @property - def filename(self): - return config.CONF_BASENAME + "-ca-cert.p12" - - def get(self): - p = os.path.join(self.request.master.options.cadir, self.filename) - p = os.path.expanduser(p) - self.set_header("Content-Type", "application/x-pkcs12") - self.set_header( - "Content-Disposition", - "inline; filename={}".format( - self.filename)) - - with open(p, "rb") as f: - self.write(f.read()) - - -application = tornado.web.Application( - [ - (r"/", Index), - (r"/cert/pem", PEM), - (r"/cert/p12", P12), - ( - r"/static/(.*)", - tornado.web.StaticFileHandler, - { - "path": utils.pkg_data.path("onboarding/static") - } - ), - ], - # debug=True -) diff --git a/mitmproxy/flow/state.py b/mitmproxy/addons/state.py similarity index 100% rename from mitmproxy/flow/state.py rename to mitmproxy/addons/state.py diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 4e49a51a9..46dd82542 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -22,6 +22,7 @@ from mitmproxy import master from mitmproxy import flow from mitmproxy import flowfilter from mitmproxy import utils +from mitmproxy.addons import state import mitmproxy.options from mitmproxy.console import flowlist from mitmproxy.console import flowview @@ -39,10 +40,10 @@ from netlib import tcp, strutils EVENTLOG_SIZE = 500 -class ConsoleState(flow.State): +class ConsoleState(state.State): def __init__(self): - flow.State.__init__(self) + state.State.__init__(self) self.focus = None self.follow_focus = None self.default_body_view = contentviews.get("Auto") diff --git a/mitmproxy/flow/__init__.py b/mitmproxy/flow/__init__.py index 2688966a5..69e3ed085 100644 --- a/mitmproxy/flow/__init__.py +++ b/mitmproxy/flow/__init__.py @@ -1,9 +1,7 @@ from mitmproxy.flow import export from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths -from mitmproxy.flow.state import State, FlowView __all__ = [ "export", "FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths", - "State", "FlowView", ] diff --git a/mitmproxy/web/master.py b/mitmproxy/web/master.py index c7976fcb3..f07d28c8c 100644 --- a/mitmproxy/web/master.py +++ b/mitmproxy/web/master.py @@ -9,7 +9,7 @@ from typing import Optional from mitmproxy import addons from mitmproxy import controller from mitmproxy import exceptions -from mitmproxy import flow +from mitmproxy.addons import state from mitmproxy import options from mitmproxy import master from mitmproxy.web import app @@ -20,7 +20,7 @@ class Stop(Exception): pass -class WebFlowView(flow.FlowView): +class WebFlowView(state.FlowView): def __init__(self, store): super().__init__(store, None) @@ -57,7 +57,7 @@ class WebFlowView(flow.FlowView): ) -class WebState(flow.State): +class WebState(state.State): def __init__(self): super().__init__() diff --git a/test/mitmproxy/test_flow_state.py b/test/mitmproxy/addons/test_state.py similarity index 83% rename from test/mitmproxy/test_flow_state.py rename to test/mitmproxy/addons/test_state.py index 05f4cbb43..71c46dcbc 100644 --- a/test/mitmproxy/test_flow_state.py +++ b/test/mitmproxy/addons/test_state.py @@ -1,12 +1,13 @@ -from mitmproxy import flow from mitmproxy import proxy from mitmproxy import master -from . import tutils +from mitmproxy.addons import state + +from .. import tutils class TestState: def test_duplicate_flow(self): - s = flow.State() + s = state.State() fm = master.Master(None, proxy.DummyServer()) fm.addons.add(s) f = tutils.tflow(resp=True) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 2b387f5c7..86cd7d160 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -4,6 +4,7 @@ import io import netlib.utils from netlib.http import Headers from mitmproxy import flowfilter, flow, options +from mitmproxy.addons import state from mitmproxy.contrib import tnetstring from mitmproxy.exceptions import FlowReadException, Kill from mitmproxy.models import Error @@ -110,7 +111,7 @@ class TestHTTPFlow: def test_killall(self): srv = DummyServer(None) - s = flow.State() + s = state.State() fm = master.Master(None, srv) fm.addons.add(s) @@ -190,7 +191,7 @@ class TestTCPFlow: class TestState: def test_backup(self): - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) f.backup() @@ -202,7 +203,7 @@ class TestState: connect -> request -> response """ - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) assert f @@ -226,13 +227,13 @@ class TestState: assert c.active_flow_count() == 0 def test_err(self): - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) f.error = Error("message") assert c.update_flow(f) - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) c.set_view_filter("~e") @@ -242,7 +243,7 @@ class TestState: assert c.view def test_set_view_filter(self): - c = flow.State() + c = state.State() f = tutils.tflow() assert len(c.view) == 0 @@ -270,7 +271,7 @@ class TestState: assert "Invalid" in c.set_view_filter("~") def test_set_intercept(self): - c = flow.State() + c = state.State() assert not c.set_intercept("~q") assert c.intercept_txt == "~q" assert "Invalid" in c.set_intercept("~") @@ -293,7 +294,7 @@ class TestState: state.add_flow(f) def test_clear(self): - c = flow.State() + c = state.State() f = self._add_request(c) f.intercepted = True @@ -301,7 +302,7 @@ class TestState: assert c.flow_count() == 0 def test_dump_flows(self): - c = flow.State() + c = state.State() self._add_request(c) self._add_response(c) self._add_request(c) @@ -317,7 +318,7 @@ class TestState: assert isinstance(c.flows[0], Flow) def test_accept_all(self): - c = flow.State() + c = state.State() self._add_request(c) self._add_response(c) self._add_request(c) @@ -363,7 +364,7 @@ class TestSerialize: def test_load_flows(self): r = self._treader() - s = flow.State() + s = state.State() fm = master.Master(None, DummyServer()) fm.addons.add(s) fm.load_flows(r) @@ -371,7 +372,7 @@ class TestSerialize: def test_load_flows_reverse(self): r = self._treader() - s = flow.State() + s = state.State() opts = options.Options( mode="reverse", upstream_server="https://use-this-domain" @@ -440,7 +441,7 @@ class TestFlowMaster: assert fm.create_request("GET", "http", "example.com", 80, "/") def test_all(self): - s = flow.State() + s = state.State() fm = master.Master(None, DummyServer()) fm.addons.add(s) f = tutils.tflow(req=None) diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 254af2f09..1243bca05 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -7,7 +7,7 @@ import sys from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.server import ProxyServer from mitmproxy import master -from mitmproxy.flow import state +from mitmproxy.addons import state import pathod.test import pathod.pathoc from mitmproxy import controller, options