From 2a68029b21d691bcf36be08665d8a5e4a5eab8d0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 28 Jun 2017 17:26:20 +0200 Subject: [PATCH] improve command repr --- mitmproxy/proxy/protocol2/commands.py | 4 +++- mitmproxy/proxy/protocol2/layer.py | 4 ++-- mitmproxy/proxy/protocol2/test/tutils.py | 8 +++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mitmproxy/proxy/protocol2/commands.py b/mitmproxy/proxy/protocol2/commands.py index 99dc8bd7b..a8f60b151 100644 --- a/mitmproxy/proxy/protocol2/commands.py +++ b/mitmproxy/proxy/protocol2/commands.py @@ -26,7 +26,9 @@ class Command: """ def __repr__(self): - return f"{type(self).__name__}({repr(self.__dict__)})" + x = self.__dict__.copy() + x.pop("blocking", None) + return f"{type(self).__name__}({repr(x)})" class ConnectionCommand(Command): diff --git a/mitmproxy/proxy/protocol2/layer.py b/mitmproxy/proxy/protocol2/layer.py index 9ea141d88..b40390bf5 100644 --- a/mitmproxy/proxy/protocol2/layer.py +++ b/mitmproxy/proxy/protocol2/layer.py @@ -27,8 +27,8 @@ class Layer(metaclass=ABCMeta): self._paused = None self._paused_event_queue: typing.Deque[events.Event] = collections.deque() - def _debug(self, x): - pass # print(x) + def _debug(self, *args): + pass # print(*args) @abstractmethod def _handle_event(self, event: Event) -> commands.TCommandGenerator: diff --git a/mitmproxy/proxy/protocol2/test/tutils.py b/mitmproxy/proxy/protocol2/test/tutils.py index e47104724..3773d56d0 100644 --- a/mitmproxy/proxy/protocol2/test/tutils.py +++ b/mitmproxy/proxy/protocol2/test/tutils.py @@ -100,8 +100,8 @@ class playbook: pass else: if isinstance(x, events.CommandReply): - if isinstance(x.command, int) and 0 <= i + x.command < len(self.actual): - x.command = self.actual[i + x.command] + if isinstance(x.command, int) and abs(x.command) < len(self.actual): + x.command = self.actual[x.command] self.actual.append(x) self.actual.extend( @@ -116,9 +116,7 @@ class playbook: if not success: def _str(x): # add arrows to diff - ret = f"{'>' if isinstance(x, events.Event) else '<'} {x}" - # remove "blocking" attr which is also ignored during equality checks. - return re.sub(r", 'blocking': <.+?>", "", ret) + return f"{'>' if isinstance(x, events.Event) else '<'} {x}" diff = difflib.ndiff( [_str(x) for x in self.playbook],