diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-03-16 10:29:02 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-03-16 11:07:00 +1300 |
commit | 228a22b3c044b23bd75e4558778722bf3f44cf24 (patch) | |
tree | dd6f7f45de4d70a5a899d95c7ec63b91d76d7f92 /mitmproxy/test | |
parent | 169068c7ec97ae0dfb64cfa5e5b1588c6e62297d (diff) | |
download | mitmproxy-228a22b3c044b23bd75e4558778722bf3f44cf24.tar.gz mitmproxy-228a22b3c044b23bd75e4558778722bf3f44cf24.tar.bz2 mitmproxy-228a22b3c044b23bd75e4558778722bf3f44cf24.zip |
Add a light-weight custom event system, use it for keepserving
This patch implements the lightweight event system I propose in #2144, adds a
custom event "processing_complete" that is triggered after file read, client
replay and server replay, and introduces a KeepServing addon to handle this for
mitmdump.
Diffstat (limited to 'mitmproxy/test')
-rw-r--r-- | mitmproxy/test/taddons.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py index 8d6baa12..c3b65e92 100644 --- a/mitmproxy/test/taddons.py +++ b/mitmproxy/test/taddons.py @@ -6,16 +6,36 @@ from mitmproxy import proxy from mitmproxy import eventsequence +class _AddonWrapper: + def __init__(self, master, addons): + self.master = master + self.addons = addons + + def trigger(self, event, *args, **kwargs): + self.master.events.append((event, args, kwargs)) + return self.addons.trigger(event, *args, **kwargs) + + def __getattr__(self, attr): + return getattr(self.addons, attr) + + class RecordingMaster(mitmproxy.master.Master): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.event_log = [] + self.addons = _AddonWrapper(self, self.addons) + self.events = [] + self.logs = [] + + def has_event(self, name): + for i in self.events: + if i[0] == name: + return True def add_log(self, e, level): - self.event_log.append((level, e)) + self.logs.append((level, e)) def clear(self): - self.event_log = [] + self.logs = [] class context: |