From 00426534982ab7fba5617ad6422c13483a8e6521 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 28 May 2016 13:21:07 +1200 Subject: [PATCH] Be stricter about the handler call signature Uses this to catch an error in mitmweb --- mitmproxy/controller.py | 8 +++++++- mitmproxy/web/__init__.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 57c01f59f..ac7c6cbc4 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -161,7 +161,13 @@ NO_REPLY = object() def handler(f): @functools.wraps(f) def wrapper(*args, **kwargs): - message = args[-1] + if len(args) == 1: + message = args[0] + elif len(args) == 2: + message = args[1] + else: + raise ControlError("Handler takes one argument: a message") + if not hasattr(message, "reply"): raise ControlError("Message %s has no reply attribute"%message) diff --git a/mitmproxy/web/__init__.py b/mitmproxy/web/__init__.py index d90830d68..7fef6df18 100644 --- a/mitmproxy/web/__init__.py +++ b/mitmproxy/web/__init__.py @@ -211,7 +211,6 @@ class WebMaster(flow.FlowMaster): super(WebMaster, self).handle_error(f) self._process_flow(f) - @controller.handler def add_event(self, e, level="info"): super(WebMaster, self).add_event(e, level) self.state.add_event(e, level)