diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-03-24 10:32:37 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-03-25 10:48:12 +1300 |
commit | d69a411303298c944d5941e0f3e435ff96800a69 (patch) | |
tree | f621dc841e3a08d1285339ffd2b6d35208fe5e95 | |
parent | 541c1e8b9f0e2e12bd770100888129639cc94827 (diff) | |
download | mitmproxy-d69a411303298c944d5941e0f3e435ff96800a69.tar.gz mitmproxy-d69a411303298c944d5941e0f3e435ff96800a69.tar.bz2 mitmproxy-d69a411303298c944d5941e0f3e435ff96800a69.zip |
addons: an addonmanager.Loader is now passed to the load() event
-rw-r--r-- | mitmproxy/addonmanager.py | 29 | ||||
-rw-r--r-- | mitmproxy/addons/script.py | 6 |
2 files changed, 32 insertions, 3 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index b3a71f1b..1fc8e4dc 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -1,3 +1,5 @@ +import typing + from mitmproxy import exceptions from mitmproxy import eventsequence from mitmproxy import controller @@ -9,6 +11,30 @@ def _get_name(itm): return getattr(itm, "name", itm.__class__.__name__.lower()) +class Loader: + """ + A loader object is passed to the load() event when addons start up. + """ + def __init__(self, master): + self.master = master + + def add_option( + self, + name: str, + typespec: type, + default: typing.Any, + help: str, + choices: typing.Optional[typing.Sequence[str]] = None + ) -> None: + self.master.options.add_option( + name, + typespec, + default, + help, + choices + ) + + class AddonManager: def __init__(self, master): self.chain = [] @@ -41,8 +67,9 @@ class AddonManager: """ self.chain.extend(addons) with self.master.handlecontext(): + l = Loader(self.master) for i in addons: - self.invoke_addon(i, "load", self.master.options) + self.invoke_addon(i, "load", l) def remove(self, addon): """ diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index cb98704a..ca1085d0 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -6,6 +6,7 @@ import threading import traceback import types +from mitmproxy import addonmanager from mitmproxy import exceptions from mitmproxy import ctx from mitmproxy import eventsequence @@ -184,10 +185,11 @@ class Script: def load_script(self): self.ns = load_script(self.path, self.args) - ret = self.run("load", self.last_options) + l = addonmanager.Loader(ctx.master) + ret = self.run("load", l) if ret: self.ns = ret - self.run("load", self.last_options) + self.run("load", l) def tick(self): if self.should_reload.is_set(): |