From 22eebfd574c95bbaf600aa67f14e52a44345e678 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 14:25:11 +1300 Subject: [PATCH] addons.Addons -> addonmanager, builtins -> addons --- docs/scripting/api.rst | 8 +++-- docs/scripting/overview.rst | 2 +- examples/proxapp.py | 2 +- mitmproxy/{addons.py => addonmanager.py} | 2 +- mitmproxy/addons/__init__.py | 29 ++++++++++++++++++ mitmproxy/{builtins => addons}/anticache.py | 0 mitmproxy/{builtins => addons}/anticomp.py | 0 .../{builtins => addons}/clientplayback.py | 0 mitmproxy/{builtins => addons}/dumper.py | 0 .../{builtins => addons}/filestreamer.py | 0 mitmproxy/{builtins => addons}/onboarding.py | 4 +-- .../{builtins => addons}/onboarding/app.py | 2 +- .../onboardingapp/__init__.py | 0 .../{builtins => addons}/onboardingapp/app.py | 6 ++-- .../onboardingapp/static/bootstrap.min.css | 0 .../static/fontawesome/css/font-awesome.css | 0 .../fontawesome/css/font-awesome.min.css | 0 .../static/fontawesome/fonts/FontAwesome.otf | Bin .../fontawesome/fonts/fontawesome-webfont.eot | Bin .../fontawesome/fonts/fontawesome-webfont.svg | 0 .../fontawesome/fonts/fontawesome-webfont.ttf | Bin .../fonts/fontawesome-webfont.woff | Bin .../onboardingapp/static/mitmproxy.css | 0 .../onboardingapp/templates/frame.html | 0 .../onboardingapp/templates/index.html | 0 .../onboardingapp/templates/layout.html | 0 mitmproxy/{builtins => addons}/replace.py | 0 mitmproxy/{builtins => addons}/script.py | 0 .../{builtins => addons}/serverplayback.py | 0 mitmproxy/{builtins => addons}/setheaders.py | 0 mitmproxy/{builtins => addons}/stickyauth.py | 0 .../{builtins => addons}/stickycookie.py | 0 .../{builtins => addons}/streambodies.py | 0 mitmproxy/{builtins => addons}/termlog.py | 0 mitmproxy/{builtins => addons}/wsgiapp.py | 0 mitmproxy/builtins/__init__.py | 29 ------------------ mitmproxy/console/grideditor/editors.py | 2 +- mitmproxy/console/master.py | 4 +-- mitmproxy/dump.py | 6 ++-- mitmproxy/master.py | 4 +-- mitmproxy/web/master.py | 4 +-- setup.cfg | 2 +- .../{builtins => addons}/__init__.py | 0 .../{builtins => addons}/test_anticache.py | 2 +- .../{builtins => addons}/test_anticomp.py | 2 +- .../test_clientplayback.py | 2 +- .../{builtins => addons}/test_dumper.py | 2 +- .../{builtins => addons}/test_filestreamer.py | 2 +- .../{builtins => addons}/test_onboarding.py | 2 +- .../{builtins => addons}/test_replace.py | 2 +- .../{builtins => addons}/test_script.py | 2 +- .../test_serverplayback.py | 2 +- .../{builtins => addons}/test_setheaders.py | 2 +- .../{builtins => addons}/test_stickyauth.py | 2 +- .../{builtins => addons}/test_stickycookie.py | 2 +- .../{builtins => addons}/test_streambodies.py | 2 +- .../{builtins => addons}/test_termlog.py | 2 +- .../{builtins => addons}/test_wsgiapp.py | 10 +++--- test/mitmproxy/script/test_concurrent.py | 2 +- .../{test_addons.py => test_addonmanager.py} | 4 +-- test/mitmproxy/test_examples.py | 2 +- test/mitmproxy/test_server.py | 2 +- test/mitmproxy/tools/benchtool.py | 2 +- test/netlib/http/test_request.py | 2 +- test/netlib/http/test_response.py | 2 +- 65 files changed, 81 insertions(+), 79 deletions(-) rename mitmproxy/{addons.py => addonmanager.py} (99%) create mode 100644 mitmproxy/addons/__init__.py rename mitmproxy/{builtins => addons}/anticache.py (100%) rename mitmproxy/{builtins => addons}/anticomp.py (100%) rename mitmproxy/{builtins => addons}/clientplayback.py (100%) rename mitmproxy/{builtins => addons}/dumper.py (100%) rename mitmproxy/{builtins => addons}/filestreamer.py (100%) rename mitmproxy/{builtins => addons}/onboarding.py (81%) rename mitmproxy/{builtins => addons}/onboarding/app.py (96%) rename mitmproxy/{builtins => addons}/onboardingapp/__init__.py (100%) rename mitmproxy/{builtins => addons}/onboardingapp/app.py (92%) rename mitmproxy/{builtins => addons}/onboardingapp/static/bootstrap.min.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/css/font-awesome.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/css/font-awesome.min.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/FontAwesome.otf (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/mitmproxy.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/frame.html (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/index.html (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/layout.html (100%) rename mitmproxy/{builtins => addons}/replace.py (100%) rename mitmproxy/{builtins => addons}/script.py (100%) rename mitmproxy/{builtins => addons}/serverplayback.py (100%) rename mitmproxy/{builtins => addons}/setheaders.py (100%) rename mitmproxy/{builtins => addons}/stickyauth.py (100%) rename mitmproxy/{builtins => addons}/stickycookie.py (100%) rename mitmproxy/{builtins => addons}/streambodies.py (100%) rename mitmproxy/{builtins => addons}/termlog.py (100%) rename mitmproxy/{builtins => addons}/wsgiapp.py (100%) delete mode 100644 mitmproxy/builtins/__init__.py rename test/mitmproxy/{builtins => addons}/__init__.py (100%) rename test/mitmproxy/{builtins => addons}/test_anticache.py (94%) rename test/mitmproxy/{builtins => addons}/test_anticomp.py (93%) rename test/mitmproxy/{builtins => addons}/test_clientplayback.py (95%) rename test/mitmproxy/{builtins => addons}/test_dumper.py (98%) rename test/mitmproxy/{builtins => addons}/test_filestreamer.py (95%) rename test/mitmproxy/{builtins => addons}/test_onboarding.py (90%) rename test/mitmproxy/{builtins => addons}/test_replace.py (98%) rename test/mitmproxy/{builtins => addons}/test_script.py (99%) rename test/mitmproxy/{builtins => addons}/test_serverplayback.py (99%) rename test/mitmproxy/{builtins => addons}/test_setheaders.py (97%) rename test/mitmproxy/{builtins => addons}/test_stickyauth.py (93%) rename test/mitmproxy/{builtins => addons}/test_stickycookie.py (98%) rename test/mitmproxy/{builtins => addons}/test_streambodies.py (94%) rename test/mitmproxy/{builtins => addons}/test_termlog.py (92%) rename test/mitmproxy/{builtins => addons}/test_wsgiapp.py (81%) rename test/mitmproxy/{test_addons.py => test_addonmanager.py} (85%) diff --git a/docs/scripting/api.rst b/docs/scripting/api.rst index abc9ff3e3..59ef8d95d 100644 --- a/docs/scripting/api.rst +++ b/docs/scripting/api.rst @@ -11,8 +11,8 @@ API - `mitmproxy.models.http.HTTPResponse <#mitmproxy.models.http.HTTPResponse>`_ - `mitmproxy.models.http.HTTPFlow <#mitmproxy.models.http.HTTPFlow>`_ - Logging - - `mitmproxy.controller.Log <#mitmproxy.controller.Log>`_ - - `mitmproxy.controller.LogEntry <#mitmproxy.controller.LogEntry>`_ + - `mitmproxy.log.Log <#mitmproxy.controller.Log>`_ + - `mitmproxy.log.LogEntry <#mitmproxy.controller.LogEntry>`_ Errors @@ -36,5 +36,7 @@ HTTP Logging -------- -.. autoclass:: mitmproxy.controller.Log +.. autoclass:: mitmproxy.log.Log + :inherited-members: +.. autoclass:: mitmproxy.log.LogEntry :inherited-members: diff --git a/docs/scripting/overview.rst b/docs/scripting/overview.rst index 5966eb1de..b820538e7 100644 --- a/docs/scripting/overview.rst +++ b/docs/scripting/overview.rst @@ -6,7 +6,7 @@ Overview Mitmproxy has a powerful scripting API that allows you to control almost any aspect of traffic being proxied. In fact, much of mitmproxy's own core functionality is implemented using the exact same API exposed to scripters (see -:src:`mitmproxy/builtins`). +:src:`mitmproxy/addons`). A simple example diff --git a/examples/proxapp.py b/examples/proxapp.py index b4fa8d3dd..f95c41e5c 100644 --- a/examples/proxapp.py +++ b/examples/proxapp.py @@ -4,7 +4,7 @@ instance, we're using the Flask framework (http://flask.pocoo.org/) to expose a single simplest-possible page. """ from flask import Flask -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp app = Flask("proxapp") diff --git a/mitmproxy/addons.py b/mitmproxy/addonmanager.py similarity index 99% rename from mitmproxy/addons.py rename to mitmproxy/addonmanager.py index 34ca8e554..db8e0cd7e 100644 --- a/mitmproxy/addons.py +++ b/mitmproxy/addonmanager.py @@ -6,7 +6,7 @@ def _get_name(itm): return getattr(itm, "name", itm.__class__.__name__.lower()) -class Addons: +class AddonManager: def __init__(self, master): self.chain = [] self.master = master diff --git a/mitmproxy/addons/__init__.py b/mitmproxy/addons/__init__.py new file mode 100644 index 000000000..c5d405253 --- /dev/null +++ b/mitmproxy/addons/__init__.py @@ -0,0 +1,29 @@ +from mitmproxy.addons import anticache +from mitmproxy.addons import anticomp +from mitmproxy.addons import clientplayback +from mitmproxy.addons import filestreamer +from mitmproxy.addons import onboarding +from mitmproxy.addons import replace +from mitmproxy.addons import script +from mitmproxy.addons import setheaders +from mitmproxy.addons import serverplayback +from mitmproxy.addons import stickyauth +from mitmproxy.addons import stickycookie +from mitmproxy.addons import streambodies + + +def default_addons(): + return [ + onboarding.Onboarding(), + anticache.AntiCache(), + anticomp.AntiComp(), + stickyauth.StickyAuth(), + stickycookie.StickyCookie(), + script.ScriptLoader(), + filestreamer.FileStreamer(), + streambodies.StreamBodies(), + replace.Replace(), + setheaders.SetHeaders(), + serverplayback.ServerPlayback(), + clientplayback.ClientPlayback(), + ] diff --git a/mitmproxy/builtins/anticache.py b/mitmproxy/addons/anticache.py similarity index 100% rename from mitmproxy/builtins/anticache.py rename to mitmproxy/addons/anticache.py diff --git a/mitmproxy/builtins/anticomp.py b/mitmproxy/addons/anticomp.py similarity index 100% rename from mitmproxy/builtins/anticomp.py rename to mitmproxy/addons/anticomp.py diff --git a/mitmproxy/builtins/clientplayback.py b/mitmproxy/addons/clientplayback.py similarity index 100% rename from mitmproxy/builtins/clientplayback.py rename to mitmproxy/addons/clientplayback.py diff --git a/mitmproxy/builtins/dumper.py b/mitmproxy/addons/dumper.py similarity index 100% rename from mitmproxy/builtins/dumper.py rename to mitmproxy/addons/dumper.py diff --git a/mitmproxy/builtins/filestreamer.py b/mitmproxy/addons/filestreamer.py similarity index 100% rename from mitmproxy/builtins/filestreamer.py rename to mitmproxy/addons/filestreamer.py diff --git a/mitmproxy/builtins/onboarding.py b/mitmproxy/addons/onboarding.py similarity index 81% rename from mitmproxy/builtins/onboarding.py rename to mitmproxy/addons/onboarding.py index 958440109..4b9524381 100644 --- a/mitmproxy/builtins/onboarding.py +++ b/mitmproxy/addons/onboarding.py @@ -1,5 +1,5 @@ -from mitmproxy.builtins import wsgiapp -from mitmproxy.builtins.onboardingapp import app +from mitmproxy.addons import wsgiapp +from mitmproxy.addons.onboardingapp import app class Onboarding(wsgiapp.WSGIApp): diff --git a/mitmproxy/builtins/onboarding/app.py b/mitmproxy/addons/onboarding/app.py similarity index 96% rename from mitmproxy/builtins/onboarding/app.py rename to mitmproxy/addons/onboarding/app.py index c7fcf87b5..20197c096 100644 --- a/mitmproxy/builtins/onboarding/app.py +++ b/mitmproxy/addons/onboarding/app.py @@ -7,7 +7,7 @@ import tornado.wsgi from mitmproxy import utils from mitmproxy.proxy import config -loader = tornado.template.Loader(utils.pkg_data.path("builtins/onboardingapp/templates")) +loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) class Adapter(tornado.wsgi.WSGIAdapter): diff --git a/mitmproxy/builtins/onboardingapp/__init__.py b/mitmproxy/addons/onboardingapp/__init__.py similarity index 100% rename from mitmproxy/builtins/onboardingapp/__init__.py rename to mitmproxy/addons/onboardingapp/__init__.py diff --git a/mitmproxy/builtins/onboardingapp/app.py b/mitmproxy/addons/onboardingapp/app.py similarity index 92% rename from mitmproxy/builtins/onboardingapp/app.py rename to mitmproxy/addons/onboardingapp/app.py index 6a65d1422..9e07b75fd 100644 --- a/mitmproxy/builtins/onboardingapp/app.py +++ b/mitmproxy/addons/onboardingapp/app.py @@ -6,9 +6,9 @@ import tornado.wsgi from mitmproxy import utils from mitmproxy.proxy import config -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp -loader = tornado.template.Loader(utils.pkg_data.path("builtins/onboardingapp/templates")) +loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) class Adapter(tornado.wsgi.WSGIAdapter): @@ -86,7 +86,7 @@ application = tornado.web.Application( r"/static/(.*)", tornado.web.StaticFileHandler, { - "path": utils.pkg_data.path("builtins/onboardingapp/static") + "path": utils.pkg_data.path("addons/onboardingapp/static") } ), ], diff --git a/mitmproxy/builtins/onboardingapp/static/bootstrap.min.css b/mitmproxy/addons/onboardingapp/static/bootstrap.min.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/bootstrap.min.css rename to mitmproxy/addons/onboardingapp/static/bootstrap.min.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.css b/mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.css rename to mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.min.css b/mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.min.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.min.css rename to mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.min.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/FontAwesome.otf b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/FontAwesome.otf similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/FontAwesome.otf rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/FontAwesome.otf diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff diff --git a/mitmproxy/builtins/onboardingapp/static/mitmproxy.css b/mitmproxy/addons/onboardingapp/static/mitmproxy.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/mitmproxy.css rename to mitmproxy/addons/onboardingapp/static/mitmproxy.css diff --git a/mitmproxy/builtins/onboardingapp/templates/frame.html b/mitmproxy/addons/onboardingapp/templates/frame.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/frame.html rename to mitmproxy/addons/onboardingapp/templates/frame.html diff --git a/mitmproxy/builtins/onboardingapp/templates/index.html b/mitmproxy/addons/onboardingapp/templates/index.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/index.html rename to mitmproxy/addons/onboardingapp/templates/index.html diff --git a/mitmproxy/builtins/onboardingapp/templates/layout.html b/mitmproxy/addons/onboardingapp/templates/layout.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/layout.html rename to mitmproxy/addons/onboardingapp/templates/layout.html diff --git a/mitmproxy/builtins/replace.py b/mitmproxy/addons/replace.py similarity index 100% rename from mitmproxy/builtins/replace.py rename to mitmproxy/addons/replace.py diff --git a/mitmproxy/builtins/script.py b/mitmproxy/addons/script.py similarity index 100% rename from mitmproxy/builtins/script.py rename to mitmproxy/addons/script.py diff --git a/mitmproxy/builtins/serverplayback.py b/mitmproxy/addons/serverplayback.py similarity index 100% rename from mitmproxy/builtins/serverplayback.py rename to mitmproxy/addons/serverplayback.py diff --git a/mitmproxy/builtins/setheaders.py b/mitmproxy/addons/setheaders.py similarity index 100% rename from mitmproxy/builtins/setheaders.py rename to mitmproxy/addons/setheaders.py diff --git a/mitmproxy/builtins/stickyauth.py b/mitmproxy/addons/stickyauth.py similarity index 100% rename from mitmproxy/builtins/stickyauth.py rename to mitmproxy/addons/stickyauth.py diff --git a/mitmproxy/builtins/stickycookie.py b/mitmproxy/addons/stickycookie.py similarity index 100% rename from mitmproxy/builtins/stickycookie.py rename to mitmproxy/addons/stickycookie.py diff --git a/mitmproxy/builtins/streambodies.py b/mitmproxy/addons/streambodies.py similarity index 100% rename from mitmproxy/builtins/streambodies.py rename to mitmproxy/addons/streambodies.py diff --git a/mitmproxy/builtins/termlog.py b/mitmproxy/addons/termlog.py similarity index 100% rename from mitmproxy/builtins/termlog.py rename to mitmproxy/addons/termlog.py diff --git a/mitmproxy/builtins/wsgiapp.py b/mitmproxy/addons/wsgiapp.py similarity index 100% rename from mitmproxy/builtins/wsgiapp.py rename to mitmproxy/addons/wsgiapp.py diff --git a/mitmproxy/builtins/__init__.py b/mitmproxy/builtins/__init__.py deleted file mode 100644 index 54b52a9a6..000000000 --- a/mitmproxy/builtins/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -from mitmproxy.builtins import anticache -from mitmproxy.builtins import anticomp -from mitmproxy.builtins import clientplayback -from mitmproxy.builtins import filestreamer -from mitmproxy.builtins import onboarding -from mitmproxy.builtins import replace -from mitmproxy.builtins import script -from mitmproxy.builtins import setheaders -from mitmproxy.builtins import serverplayback -from mitmproxy.builtins import stickyauth -from mitmproxy.builtins import stickycookie -from mitmproxy.builtins import streambodies - - -def default_addons(): - return [ - onboarding.Onboarding(), - anticache.AntiCache(), - anticomp.AntiComp(), - stickyauth.StickyAuth(), - stickycookie.StickyCookie(), - script.ScriptLoader(), - filestreamer.FileStreamer(), - streambodies.StreamBodies(), - replace.Replace(), - setheaders.SetHeaders(), - serverplayback.ServerPlayback(), - clientplayback.ClientPlayback(), - ] diff --git a/mitmproxy/console/grideditor/editors.py b/mitmproxy/console/grideditor/editors.py index 7a1ef0978..512c2416f 100644 --- a/mitmproxy/console/grideditor/editors.py +++ b/mitmproxy/console/grideditor/editors.py @@ -2,7 +2,7 @@ import re import urwid from mitmproxy import exceptions from mitmproxy import flowfilter -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy.console import common from mitmproxy.console.grideditor import base from mitmproxy.console.grideditor import col_bytes diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index b19c62a2b..4e49a51a9 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -14,7 +14,7 @@ import weakref import urwid from typing import Optional -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import contentviews from mitmproxy import controller from mitmproxy import exceptions @@ -251,7 +251,7 @@ class ConsoleMaster(master.Master): signals.replace_view_state.connect(self.sig_replace_view_state) signals.push_view_state.connect(self.sig_push_view_state) signals.sig_add_log.connect(self.sig_add_log) - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(self.state) def __setattr__(self, name, value): diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index 4731686c9..e8b3126f3 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -4,10 +4,10 @@ from typing import Optional from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import flow -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import options from mitmproxy import master -from mitmproxy.builtins import dumper, termlog +from mitmproxy.addons import dumper, termlog from netlib import tcp @@ -37,7 +37,7 @@ class DumpMaster(master.Master): master.Master.__init__(self, options, server) self.has_errored = False self.addons.add(termlog.TermLog()) - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(dumper.Dumper()) # This line is just for type hinting self.options = self.options # type: Options diff --git a/mitmproxy/master.py b/mitmproxy/master.py index ce1dd2c6a..aa9892e59 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -4,7 +4,7 @@ import contextlib import queue import sys -from mitmproxy import addons +from mitmproxy import addonmanager from mitmproxy import options from mitmproxy import controller from mitmproxy import events @@ -37,7 +37,7 @@ class Master: """ def __init__(self, opts, server): self.options = opts or options.Options() - self.addons = addons.Addons(self) + self.addons = addonmanager.AddonManager(self) self.event_queue = queue.Queue() self.should_exit = threading.Event() self.server = server diff --git a/mitmproxy/web/master.py b/mitmproxy/web/master.py index 1f0dc709e..c7976fcb3 100644 --- a/mitmproxy/web/master.py +++ b/mitmproxy/web/master.py @@ -6,7 +6,7 @@ import tornado.ioloop from typing import Optional -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import flow @@ -136,7 +136,7 @@ class WebMaster(master.Master): def __init__(self, options, server): super().__init__(options, server) self.state = WebState() - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(self.state) self.app = app.Application( self, self.options.wdebug, self.options.wauthenticator diff --git a/setup.cfg b/setup.cfg index 47fe119ae..87ef81ede 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ max-line-length = 140 max-complexity = 25 ignore = E251,C901 exclude = mitmproxy/contrib/*,test/mitmproxy/data/* -builtins = file,open,basestring,xrange,unicode,long,cmp +addons = file,open,basestring,xrange,unicode,long,cmp [tool:pytest] testpaths = test diff --git a/test/mitmproxy/builtins/__init__.py b/test/mitmproxy/addons/__init__.py similarity index 100% rename from test/mitmproxy/builtins/__init__.py rename to test/mitmproxy/addons/__init__.py diff --git a/test/mitmproxy/builtins/test_anticache.py b/test/mitmproxy/addons/test_anticache.py similarity index 94% rename from test/mitmproxy/builtins/test_anticache.py rename to test/mitmproxy/addons/test_anticache.py index 790ae97d2..f7418f389 100644 --- a/test/mitmproxy/builtins/test_anticache.py +++ b/test/mitmproxy/addons/test_anticache.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import anticache +from mitmproxy.addons import anticache from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_anticomp.py b/test/mitmproxy/addons/test_anticomp.py similarity index 93% rename from test/mitmproxy/builtins/test_anticomp.py rename to test/mitmproxy/addons/test_anticomp.py index d5a0d6eb7..5f95013f9 100644 --- a/test/mitmproxy/builtins/test_anticomp.py +++ b/test/mitmproxy/addons/test_anticomp.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import anticomp +from mitmproxy.addons import anticomp from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py similarity index 95% rename from test/mitmproxy/builtins/test_clientplayback.py rename to test/mitmproxy/addons/test_clientplayback.py index e2c5be7e7..c5407d187 100644 --- a/test/mitmproxy/builtins/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -1,6 +1,6 @@ import mock -from mitmproxy.builtins import clientplayback +from mitmproxy.addons import clientplayback from mitmproxy import options from .. import tutils, mastertest diff --git a/test/mitmproxy/builtins/test_dumper.py b/test/mitmproxy/addons/test_dumper.py similarity index 98% rename from test/mitmproxy/builtins/test_dumper.py rename to test/mitmproxy/addons/test_dumper.py index d5291bc49..ce2d2de9a 100644 --- a/test/mitmproxy/builtins/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -2,7 +2,7 @@ import io from .. import tutils, mastertest -from mitmproxy.builtins import dumper +from mitmproxy.addons import dumper from mitmproxy import exceptions from mitmproxy import dump from mitmproxy import models diff --git a/test/mitmproxy/builtins/test_filestreamer.py b/test/mitmproxy/addons/test_filestreamer.py similarity index 95% rename from test/mitmproxy/builtins/test_filestreamer.py rename to test/mitmproxy/addons/test_filestreamer.py index 35fe1ca2a..a85fcd0c2 100644 --- a/test/mitmproxy/builtins/test_filestreamer.py +++ b/test/mitmproxy/addons/test_filestreamer.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest import os.path -from mitmproxy.builtins import filestreamer +from mitmproxy.addons import filestreamer from mitmproxy import master from mitmproxy.flow import io from mitmproxy import options diff --git a/test/mitmproxy/builtins/test_onboarding.py b/test/mitmproxy/addons/test_onboarding.py similarity index 90% rename from test/mitmproxy/builtins/test_onboarding.py rename to test/mitmproxy/addons/test_onboarding.py index 3226aec36..63125c23a 100644 --- a/test/mitmproxy/builtins/test_onboarding.py +++ b/test/mitmproxy/addons/test_onboarding.py @@ -1,4 +1,4 @@ -from mitmproxy.builtins import onboarding +from mitmproxy.addons import onboarding from .. import tservers diff --git a/test/mitmproxy/builtins/test_replace.py b/test/mitmproxy/addons/test_replace.py similarity index 98% rename from test/mitmproxy/builtins/test_replace.py rename to test/mitmproxy/addons/test_replace.py index 35f3d4301..94c2f832b 100644 --- a/test/mitmproxy/builtins/test_replace.py +++ b/test/mitmproxy/addons/test_replace.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest, tservers -from mitmproxy.builtins import replace +from mitmproxy.addons import replace from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/addons/test_script.py similarity index 99% rename from test/mitmproxy/builtins/test_script.py rename to test/mitmproxy/addons/test_script.py index ab4343b5e..83e60fbda 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -7,7 +7,7 @@ import re from mitmproxy import exceptions from mitmproxy import options from mitmproxy import proxy -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import master from .. import tutils, mastertest diff --git a/test/mitmproxy/builtins/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py similarity index 99% rename from test/mitmproxy/builtins/test_serverplayback.py rename to test/mitmproxy/addons/test_serverplayback.py index c51814f51..649b3c227 100644 --- a/test/mitmproxy/builtins/test_serverplayback.py +++ b/test/mitmproxy/addons/test_serverplayback.py @@ -1,7 +1,7 @@ from .. import tutils, mastertest import netlib.tutils -from mitmproxy.builtins import serverplayback +from mitmproxy.addons import serverplayback from mitmproxy import options from mitmproxy import proxy from mitmproxy import exceptions diff --git a/test/mitmproxy/builtins/test_setheaders.py b/test/mitmproxy/addons/test_setheaders.py similarity index 97% rename from test/mitmproxy/builtins/test_setheaders.py rename to test/mitmproxy/addons/test_setheaders.py index bac8b02ee..0fbbd4cb0 100644 --- a/test/mitmproxy/builtins/test_setheaders.py +++ b/test/mitmproxy/addons/test_setheaders.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest -from mitmproxy.builtins import setheaders +from mitmproxy.addons import setheaders from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_stickyauth.py b/test/mitmproxy/addons/test_stickyauth.py similarity index 93% rename from test/mitmproxy/builtins/test_stickyauth.py rename to test/mitmproxy/addons/test_stickyauth.py index 225235488..459dc5f71 100644 --- a/test/mitmproxy/builtins/test_stickyauth.py +++ b/test/mitmproxy/addons/test_stickyauth.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import stickyauth +from mitmproxy.addons import stickyauth from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/addons/test_stickycookie.py similarity index 98% rename from test/mitmproxy/builtins/test_stickycookie.py rename to test/mitmproxy/addons/test_stickycookie.py index c70b03d8c..29c9e198b 100644 --- a/test/mitmproxy/builtins/test_stickycookie.py +++ b/test/mitmproxy/addons/test_stickycookie.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import stickycookie +from mitmproxy.addons import stickycookie from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_streambodies.py b/test/mitmproxy/addons/test_streambodies.py similarity index 94% rename from test/mitmproxy/builtins/test_streambodies.py rename to test/mitmproxy/addons/test_streambodies.py index 4a8c24740..cf416c864 100644 --- a/test/mitmproxy/builtins/test_streambodies.py +++ b/test/mitmproxy/addons/test_streambodies.py @@ -3,7 +3,7 @@ from mitmproxy import master from mitmproxy import options from mitmproxy import proxy -from mitmproxy.builtins import streambodies +from mitmproxy.addons import streambodies class TestStreamBodies(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_termlog.py b/test/mitmproxy/addons/test_termlog.py similarity index 92% rename from test/mitmproxy/builtins/test_termlog.py rename to test/mitmproxy/addons/test_termlog.py index 49a8be83c..a9f18a51a 100644 --- a/test/mitmproxy/builtins/test_termlog.py +++ b/test/mitmproxy/addons/test_termlog.py @@ -1,7 +1,7 @@ from .. import mastertest import io -from mitmproxy.builtins import termlog +from mitmproxy.addons import termlog from mitmproxy import log from mitmproxy import dump diff --git a/test/mitmproxy/builtins/test_wsgiapp.py b/test/mitmproxy/addons/test_wsgiapp.py similarity index 81% rename from test/mitmproxy/builtins/test_wsgiapp.py rename to test/mitmproxy/addons/test_wsgiapp.py index a39ec5c30..760ee460b 100644 --- a/test/mitmproxy/builtins/test_wsgiapp.py +++ b/test/mitmproxy/addons/test_wsgiapp.py @@ -1,17 +1,17 @@ import flask from .. import tservers -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp -testapp = flask.Flask(__name__) +tapp = flask.Flask(__name__) -@testapp.route("/") +@tapp.route("/") def hello(): return "testapp" -@testapp.route("/error") +@tapp.route("/error") def error(): raise ValueError("An exception...") @@ -23,7 +23,7 @@ def errapp(environ, start_response): class TestApp(tservers.HTTPProxyTest): def addons(self): return [ - wsgiapp.WSGIApp(testapp, "testapp", 80), + wsgiapp.WSGIApp(tapp, "testapp", 80), wsgiapp.WSGIApp(errapp, "errapp", 80) ] diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index bebd8dea6..51c36abf8 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -1,6 +1,6 @@ from test.mitmproxy import tutils, mastertest from mitmproxy import controller -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import options from mitmproxy import proxy from mitmproxy import master diff --git a/test/mitmproxy/test_addons.py b/test/mitmproxy/test_addonmanager.py similarity index 85% rename from test/mitmproxy/test_addons.py rename to test/mitmproxy/test_addonmanager.py index dcf14398b..7a50148e0 100644 --- a/test/mitmproxy/test_addons.py +++ b/test/mitmproxy/test_addonmanager.py @@ -1,4 +1,4 @@ -from mitmproxy import addons +from mitmproxy import addonmanager from mitmproxy import options from mitmproxy import master from mitmproxy import proxy @@ -15,7 +15,7 @@ class TAddon: def test_simple(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) - a = addons.Addons(m) + a = addonmanager.AddonManager(m) a.add(TAddon("one")) assert a.get("one") assert not a.get("two") diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index ee5080e8b..7551c1c84 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -5,7 +5,7 @@ import shlex from mitmproxy import options from mitmproxy import contentviews from mitmproxy import proxy -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import master import netlib.utils diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index 6679625bc..7616b5a78 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -5,7 +5,7 @@ import time import netlib.tutils from mitmproxy import controller from mitmproxy import options -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy.models import HTTPResponse, HTTPFlow from mitmproxy.proxy.config import HostMatcher, parse_server_spec from netlib import tcp, http, socks diff --git a/test/mitmproxy/tools/benchtool.py b/test/mitmproxy/tools/benchtool.py index bc68645cd..9e2ab8eea 100644 --- a/test/mitmproxy/tools/benchtool.py +++ b/test/mitmproxy/tools/benchtool.py @@ -38,7 +38,7 @@ def main(profiler, clock_type, concurrency): if profiler == "yappi": yappi.set_clock_type(clock_type) - yappi.start(builtins=True) + yappi.start(addons=True) print("Start mitmdump...") mitmdump(["-k", "-q", "-S", "1024example"]) diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py index 87eb9c351..336dc86d8 100644 --- a/test/netlib/http/test_request.py +++ b/test/netlib/http/test_request.py @@ -15,7 +15,7 @@ class TestRequestData: class TestRequestCore: """ - Tests for builtins and the attributes that are directly proxied from the data structure + Tests for addons and the attributes that are directly proxied from the data structure """ def test_repr(self): request = treq() diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py index 0953f2785..725f2b332 100644 --- a/test/netlib/http/test_response.py +++ b/test/netlib/http/test_response.py @@ -19,7 +19,7 @@ class TestResponseData: class TestResponseCore: """ - Tests for builtins and the attributes that are directly proxied from the data structure + Tests for addons and the attributes that are directly proxied from the data structure """ def test_repr(self): response = tresp()