MCPcopy
hub / github.com/mitmproxy/mitmproxy / _eq

Function _eq

test/mitmproxy/proxy/tutils.py:28–55  ·  view source on GitHub ↗

Compare two commands/events, and possibly update placeholders.

(a: PlaybookEntry, b: PlaybookEntry)

Source from the content-addressed store, hash-verified

26
27
28def _eq(a: PlaybookEntry, b: PlaybookEntry) -> bool:
29 """Compare two commands/events, and possibly update placeholders."""
30 if type(a) is not type(b):
31 return False
32
33 a_dict = a.__dict__
34 b_dict = b.__dict__
35 # we can assume a.keys() == b.keys()
36 for k in a_dict:
37 if k == "blocking":
38 continue
39 x = a_dict[k]
40 y = b_dict[k]
41
42 # if there's a placeholder, make it x.
43 if isinstance(y, _Placeholder):
44 x, y = y, x
45 if isinstance(x, _Placeholder):
46 try:
47 x = x.setdefault(y)
48 except TypeError as e:
49 raise TypeError(
50 f"Placeholder type error for {type(a).__name__}.{k}: {e}"
51 )
52 if x != y:
53 return False
54
55 return True
56
57
58def eq(

Callers 2

eq_maybeFunction · 0.90
eqFunction · 0.85

Calls 1

setdefaultMethod · 0.45

Tested by 1

eq_maybeFunction · 0.72