Be stricter about the handler call signature

Uses this to catch an error in mitmweb
This commit is contained in:
Aldo Cortesi 2016-05-28 13:21:07 +12:00
parent 735bbe52e1
commit 0042653498
2 changed files with 7 additions and 2 deletions

View File

@ -161,7 +161,13 @@ NO_REPLY = object()
def handler(f): def handler(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(*args, **kwargs): 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"): if not hasattr(message, "reply"):
raise ControlError("Message %s has no reply attribute"%message) raise ControlError("Message %s has no reply attribute"%message)

View File

@ -211,7 +211,6 @@ class WebMaster(flow.FlowMaster):
super(WebMaster, self).handle_error(f) super(WebMaster, self).handle_error(f)
self._process_flow(f) self._process_flow(f)
@controller.handler
def add_event(self, e, level="info"): def add_event(self, e, level="info"):
super(WebMaster, self).add_event(e, level) super(WebMaster, self).add_event(e, level)
self.state.add_event(e, level) self.state.add_event(e, level)