addons.Addons -> addonmanager, builtins -> addons

This commit is contained in:
Aldo Cortesi 2016-10-19 14:25:11 +13:00
parent 966418725b
commit 22eebfd574
65 changed files with 81 additions and 79 deletions

View File

@ -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:

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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(),
]

View File

@ -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):

View File

@ -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):

View File

@ -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")
}
),
],

View File

@ -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(),
]

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
import mock
from mitmproxy.builtins import clientplayback
from mitmproxy.addons import clientplayback
from mitmproxy import options
from .. import tutils, mastertest

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,4 @@
from mitmproxy.builtins import onboarding
from mitmproxy.addons import onboarding
from .. import tservers

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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)
]

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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"])

View File

@ -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()

View File

@ -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()