aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addonmanager.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-09 13:52:58 +1300
committerAldo Cortesi <aldo@corte.si>2017-03-14 08:32:19 +1300
commit0c6663d0d5335e666598807c2e5d8f105803eac0 (patch)
treee6782b2e102aca959ad6e30739f816dbad89cbb9 /mitmproxy/addonmanager.py
parentee65894d40f5a9f73125a8d3e73ba50540939e5b (diff)
downloadmitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.gz
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.bz2
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.zip
Enable custom options for addons
- Add an options parameter to the start() event. This is to be used by addons on startup to add custom options. - Add a running() event that is called once the proxy is up and running. - With the new paradigm we can't log during master __init__, so add a tiny termstatus addon to print proxy status to terminal once we're running.
Diffstat (limited to 'mitmproxy/addonmanager.py')
-rw-r--r--mitmproxy/addonmanager.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py
index db8e0cd7..43e76510 100644
--- a/mitmproxy/addonmanager.py
+++ b/mitmproxy/addonmanager.py
@@ -1,4 +1,5 @@
from mitmproxy import exceptions
+from mitmproxy import eventsequence
import pprint
@@ -10,7 +11,7 @@ class AddonManager:
def __init__(self, master):
self.chain = []
self.master = master
- master.options.changed.connect(self._options_update)
+ master.options.changed.connect(self.configure_all)
def clear(self):
"""
@@ -29,22 +30,14 @@ class AddonManager:
if name == _get_name(i):
return i
- def _options_update(self, options, updated):
- for i in self.chain:
- with self.master.handlecontext():
- self.invoke_with_context(i, "configure", options, updated)
+ def configure_all(self, options, updated):
+ self.invoke_all_with_context("configure", options, updated)
def startup(self, s):
"""
Run startup events on addon.
"""
- self.invoke_with_context(s, "start")
- self.invoke_with_context(
- s,
- "configure",
- self.master.options,
- self.master.options.keys()
- )
+ self.invoke_with_context(s, "start", self.master.options)
def add(self, *addons):
"""
@@ -62,8 +55,7 @@ class AddonManager:
self.invoke_with_context(addon, "done")
def done(self):
- for i in self.chain:
- self.invoke_with_context(i, "done")
+ self.invoke_all_with_context("done")
def __len__(self):
return len(self.chain)
@@ -75,7 +67,14 @@ class AddonManager:
with self.master.handlecontext():
self.invoke(addon, name, *args, **kwargs)
+ def invoke_all_with_context(self, name, *args, **kwargs):
+ with self.master.handlecontext():
+ for i in self.chain:
+ self.invoke(i, name, *args, **kwargs)
+
def invoke(self, addon, name, *args, **kwargs):
+ if name not in eventsequence.Events: # prama: no cover
+ raise NotImplementedError("Unknown event")
func = getattr(addon, name, None)
if func:
if not callable(func):