diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-07-23 11:28:44 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-07-23 11:29:13 +1200 |
commit | 9294d19f908cdde86b390fb2fa93aad422da8522 (patch) | |
tree | 86e04324017d3c80ba51b1693d4f0a62142963d0 | |
parent | 05caa0a03d118a8f0fdf42bbe34ed74c8940c4a0 (diff) | |
download | mitmproxy-9294d19f908cdde86b390fb2fa93aad422da8522.tar.gz mitmproxy-9294d19f908cdde86b390fb2fa93aad422da8522.tar.bz2 mitmproxy-9294d19f908cdde86b390fb2fa93aad422da8522.zip |
scripts: .start can now return an Addon instance
-rw-r--r-- | mitmproxy/builtins/script.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_script.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/data/addonscripts/addon.py | 22 |
3 files changed, 39 insertions, 2 deletions
diff --git a/mitmproxy/builtins/script.py b/mitmproxy/builtins/script.py index 220fb9af..ed5f2ecd 100644 --- a/mitmproxy/builtins/script.py +++ b/mitmproxy/builtins/script.py @@ -99,7 +99,6 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler): return False if os.path.basename(event.src_path).startswith("."): return False - print(event.src_path) return True def on_modified(self, event): @@ -151,7 +150,10 @@ class Script: def load_script(self): self.ns = load_script(self.path, self.args) - self.run("start") + ret = self.run("start") + if ret: + self.ns = ret + self.run("start") def tick(self): if self.should_reload.is_set(): diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py index 1658088c..3f07b576 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/builtins/test_script.py @@ -116,6 +116,19 @@ class TestScript(mastertest.MasterTest): assert not fm.state.view[0].request.is_replay assert fm.state.view[1].request.is_replay + def test_addon(self): + s = state.State() + m = master.FlowMaster(options.Options(), None, s) + sc = script.Script( + tutils.test_data.path( + "data/addonscripts/addon.py" + ) + ) + m.addons.add(sc) + assert sc.ns.event_log == [ + 'scriptstart', 'addonstart', 'addonconfigure' + ] + class TestScriptLoader(mastertest.MasterTest): def test_simple(self): diff --git a/test/mitmproxy/data/addonscripts/addon.py b/test/mitmproxy/data/addonscripts/addon.py new file mode 100644 index 00000000..3b09d231 --- /dev/null +++ b/test/mitmproxy/data/addonscripts/addon.py @@ -0,0 +1,22 @@ +event_log = [] + + +class Addon: + @property + def event_log(self): + return event_log + + def start(self): + event_log.append("addonstart") + + def configure(self, options): + event_log.append("addonconfigure") + + +def configure(options): + event_log.append("addonconfigure") + + +def start(): + event_log.append("scriptstart") + return Addon() |