mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 19:08:44 +00:00
Explicitly list all events
This commit is contained in:
parent
9a32402a39
commit
8bb9285678
@ -6,6 +6,27 @@ import sys
|
||||
|
||||
from . import exceptions
|
||||
|
||||
Events = frozenset([
|
||||
"clientconnect",
|
||||
"clientdisconnect",
|
||||
"serverconnect",
|
||||
"serverdisconnect",
|
||||
|
||||
"tcp_open",
|
||||
"tcp_message",
|
||||
"tcp_error",
|
||||
"tcp_close",
|
||||
|
||||
"request",
|
||||
"response",
|
||||
"responseheaders",
|
||||
|
||||
"next_layer",
|
||||
|
||||
"error",
|
||||
"log",
|
||||
])
|
||||
|
||||
|
||||
class ControlError(Exception):
|
||||
pass
|
||||
@ -43,6 +64,8 @@ class Master(object):
|
||||
# exception is thrown.
|
||||
while True:
|
||||
mtype, obj = self.event_queue.get(timeout=timeout)
|
||||
if mtype not in Events:
|
||||
raise ControlError("Unknown event %s"%repr(mtype))
|
||||
handle_func = getattr(self, "handle_" + mtype)
|
||||
if not handle_func.func_dict.get("handler"):
|
||||
raise ControlError(
|
||||
|
@ -18,7 +18,7 @@ class TestMaster(object):
|
||||
def test_simple(self):
|
||||
class DummyMaster(controller.Master):
|
||||
@controller.handler
|
||||
def handle_panic(self, _):
|
||||
def handle_log(self, _):
|
||||
m.should_exit.set()
|
||||
|
||||
def tick(self, timeout):
|
||||
@ -29,7 +29,7 @@ class TestMaster(object):
|
||||
assert not m.should_exit.is_set()
|
||||
msg = TMsg()
|
||||
msg.reply = controller.DummyReply()
|
||||
m.event_queue.put(("panic", msg))
|
||||
m.event_queue.put(("log", msg))
|
||||
m.run()
|
||||
assert m.should_exit.is_set()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user