MCPcopy
hub / github.com/mitmproxy/mitmproxy / expect

Function expect

mitmproxy/proxy/utils.py:10–36  ·  view source on GitHub ↗

Only allow the given event type. If another event is passed, an AssertionError is raised.

(*event_types)

Source from the content-addressed store, hash-verified

8
9
10def expect(*event_types):
11 """
12 Only allow the given event type.
13 If another event is passed, an AssertionError is raised.
14 """
15
16 def decorator(f):
17 if __debug__ is True:
18
19 @functools.wraps(f)
20 def _check_event_type(self, event: events.Event):
21 if isinstance(event, event_types):
22 return f(self, event)
23 else:
24 event_types_str = (
25 "|".join(e.__name__ for e in event_types) or "no events"
26 )
27 raise AssertionError(
28 f"Unexpected event type at {f.__qualname__}: "
29 f"Expected {event_types_str}, got {event}."
30 )
31
32 return _check_event_type
33 else: # pragma: no cover
34 return f
35
36 return decorator
37
38
39class ReceiveBuffer:

Callers 15

utilsSpec.tsxFile · 0.85
urlStateSpec.tsxFile · 0.85
utilsSpec.tsxFile · 0.85
HeaderSpec.tsxFile · 0.85
ProxyAppSpec.tsxFile · 0.85
FlowTableSpec.tsxFile · 0.85
CommandBarSpec.tsxFile · 0.85
FlowViewSpec.tsxFile · 0.85
EventLogSpec.tsxFile · 0.85
testFlowColumnFunction · 0.85

Calls

no outgoing calls

Tested by 1

testFlowColumnFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…