Convert examples and example tests for new-style scripts

Remove the test that just loads all the example scripts for now - it's a very
low-value test, and we need to think of something better.
This commit is contained in:
Aldo Cortesi
2016-07-14 16:20:27 +12:00
parent a6821aad8e
commit b94f5fd361
14 changed files with 105 additions and 246 deletions

View File

@@ -62,7 +62,7 @@ class ViewPigLatin(contentviews.View):
pig_view = ViewPigLatin()
def start():
def configure(options):
contentviews.add(pig_view)

View File

@@ -6,7 +6,7 @@ from mitmproxy import filt
state = {}
def start():
def configure(options):
if len(sys.argv) != 2:
raise ValueError("Usage: -s 'filt.py FILTER'")
state["filter"] = filt.parse(sys.argv[1])

View File

@@ -6,7 +6,7 @@ from mitmproxy.flow import FlowWriter
state = {}
def start():
def configure(options):
if len(sys.argv) != 2:
raise ValueError('Usage: -s "flowriter.py filename"')

View File

@@ -61,7 +61,7 @@ class Context(object):
context = Context()
def start():
def configure(options):
"""
On start we create a HARLog instance. You will have to adapt this to
suit your actual needs of HAR generation. As it will probably be

View File

@@ -7,7 +7,7 @@ from mitmproxy.models import decoded
iframe_url = None
def start():
def configure(options):
if len(sys.argv) != 2:
raise ValueError('Usage: -s "iframe_injector.py url"')
global iframe_url

View File

@@ -8,7 +8,7 @@ from mitmproxy.models import decoded
state = {}
def start():
def configure(options):
if len(sys.argv) != 3:
raise ValueError('Usage: -s "modify_response_body.py old new"')
# You may want to use Python's argparse for more sophisticated argument

View File

@@ -16,7 +16,7 @@ def hello_world():
# Register the app using the magic domain "proxapp" on port 80. Requests to
# this domain and port combination will now be routed to the WSGI app instance.
def start():
def configure(options):
mitmproxy.ctx.master.apps.add(app, "proxapp", 80)
# SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design.

View File

@@ -4,11 +4,11 @@ import mitmproxy
"""
def start():
def configure(options):
"""
Called once on script startup, before any other events.
Called once on script startup before any other events, and whenever options changes.
"""
mitmproxy.ctx.log("start")
mitmproxy.ctx.log("configure")
def clientconnect(root_layer):

View File

@@ -113,7 +113,7 @@ class TlsFeedback(TlsLayer):
tls_strategy = None
def start():
def configure(options):
global tls_strategy
if len(sys.argv) == 2:
tls_strategy = ProbabilisticStrategy(float(sys.argv[1]))