MCPcopy
hub / github.com/mitmproxy/mitmproxy / _iter_hooks

Method _iter_hooks

mitmproxy/addonmanager.py:243–262  ·  view source on GitHub ↗

Enumerate all hook callables belonging to the given addon

(self, addon, event: hooks.Hook)

Source from the content-addressed store, hash-verified

241 await self.trigger_event(hooks.UpdateHook([message]))
242
243 def _iter_hooks(self, addon, event: hooks.Hook):
244 """
245 Enumerate all hook callables belonging to the given addon
246 """
247 assert isinstance(event, hooks.Hook)
248 for a in traverse([addon]):
249 func = getattr(a, event.name, None)
250 if func:
251 if callable(func):
252 yield a, func
253 elif isinstance(func, types.ModuleType):
254 # we gracefully exclude module imports with the same name as hooks.
255 # For example, a user may have "from mitmproxy import log" in an addon,
256 # which has the same name as the "log" hook. In this particular case,
257 # we end up in an error loop because we "log" this error.
258 pass
259 else:
260 raise exceptions.AddonManagerError(
261 f"Addon handler {event.name} ({a}) not callable"
262 )
263
264 async def invoke_addon(self, addon, event: hooks.Hook):
265 """

Callers 2

invoke_addonMethod · 0.95
invoke_addon_syncMethod · 0.95

Calls 1

traverseFunction · 0.85

Tested by

no test coverage detected