aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addonmanager.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-07-29 21:47:27 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-07-29 21:47:27 +0200
commitd5c9f131217e0be2f323e4d47c767641924e5002 (patch)
treed31f3387a5b200a3d0a806a090e18dd248552341 /mitmproxy/addonmanager.py
parent9ffd42edeacb19c3961840289bb25eaeca5991a5 (diff)
downloadmitmproxy-d5c9f131217e0be2f323e4d47c767641924e5002.tar.gz
mitmproxy-d5c9f131217e0be2f323e4d47c767641924e5002.tar.bz2
mitmproxy-d5c9f131217e0be2f323e4d47c767641924e5002.zip
gracefully ignore imports with hook names
Diffstat (limited to 'mitmproxy/addonmanager.py')
-rw-r--r--mitmproxy/addonmanager.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py
index ec82d650..9094288b 100644
--- a/mitmproxy/addonmanager.py
+++ b/mitmproxy/addonmanager.py
@@ -1,3 +1,4 @@
+import types
import typing
import traceback
import contextlib
@@ -229,11 +230,18 @@ class AddonManager:
for a in traverse([addon]):
func = getattr(a, name, None)
if func:
- if not callable(func):
+ if callable(func):
+ func(*args, **kwargs)
+ elif isinstance(func, types.ModuleType):
+ # we gracefully exclude module imports with the same name as hooks.
+ # For example, a user may have "from mitmproxy import log" in an addon,
+ # which has the same name as the "log" hook. In this particular case,
+ # we end up in an error loop because we "log" this error.
+ pass
+ else:
raise exceptions.AddonManagerError(
- "Addon handler %s not callable" % name
+ "Addon handler {} ({}) not callable".format(name, a)
)
- func(*args, **kwargs)
def trigger(self, name, *args, **kwargs):
"""