From 0b6ec2706412b9691254040c234be766a6818ebe Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 9 May 2018 18:11:38 +0200 Subject: [PATCH] logging: get rid of pprint and VerboseWireMixin (and also TrezorClientVerbose) --- trezorlib/client.py | 23 +++++------------------ trezorlib/debuglink.py | 8 +------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/trezorlib/client.py b/trezorlib/client.py index 8a0bb46a9e..e4da85ff0b 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -210,14 +210,6 @@ class BaseClient(object): mapping.register_message(msg) -class VerboseWireMixin(object): - def call_raw(self, msg): - log("SENDING " + pprint(msg)) - resp = super(VerboseWireMixin, self).call_raw(msg) - log("RECEIVED " + pprint(resp)) - return resp - - class TextUIMixin(object): # This class demonstrates easy test-based UI # integration between the device and wallet. @@ -362,7 +354,7 @@ class DebugLinkMixin(object): # Evaluate missed responses in 'with' statement if self.expected_responses is not None and len(self.expected_responses): raise RuntimeError("Some of expected responses didn't come from device: %s" % - [pprint(x) for x in self.expected_responses]) + [repr(x) for x in self.expected_responses]) # Cleanup self.expected_responses = None @@ -408,18 +400,18 @@ class DebugLinkMixin(object): expected = self.expected_responses.pop(0) except IndexError: raise AssertionException(proto.FailureType.UnexpectedMessage, - "Got %s, but no message has been expected" % pprint(msg)) + "Got %s, but no message has been expected" % repr(msg)) if msg.__class__ != expected.__class__: raise AssertionException(proto.FailureType.UnexpectedMessage, - "Expected %s, got %s" % (pprint(expected), pprint(msg))) + "Expected %s, got %s" % (repr(expected), repr(msg))) for field, value in expected.__dict__.items(): if value is None or value == []: continue if getattr(msg, field) != value: raise AssertionException(proto.FailureType.UnexpectedMessage, - "Expected %s, got %s" % (pprint(expected), pprint(msg))) + "Expected %s, got %s" % (repr(expected), repr(msg))) def callback_ButtonRequest(self, msg): log("ButtonRequest code: " + get_buttonrequest_value(msg.code)) @@ -1165,11 +1157,6 @@ class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient): super().__init__(transport=transport, *args, **kwargs) -class TrezorClientVerbose(ProtocolMixin, TextUIMixin, VerboseWireMixin, BaseClient): - def __init__(self, transport, *args, **kwargs): - super().__init__(transport=transport, *args, **kwargs) - - -class TrezorClientDebugLink(ProtocolMixin, DebugLinkMixin, VerboseWireMixin, BaseClient): +class TrezorClientDebugLink(ProtocolMixin, DebugLinkMixin, BaseClient): def __init__(self, transport, *args, **kwargs): super().__init__(transport=transport, *args, **kwargs) diff --git a/trezorlib/debuglink.py b/trezorlib/debuglink.py index af130f8690..bfe44c1c3d 100644 --- a/trezorlib/debuglink.py +++ b/trezorlib/debuglink.py @@ -29,10 +29,6 @@ def button_press(yes_no): print("User pressed", '"y"' if yes_no else '"n"') -def pprint(msg): - return "<%s> (%d bytes):\n%s" % (msg.__class__.__name__, msg.ByteSize(), msg) - - class DebugLink(object): def __init__(self, transport, pin_func=pin_info, button_func=button_press): self.transport = transport @@ -45,12 +41,10 @@ class DebugLink(object): self.transport.session_end() def _call(self, msg, nowait=False): - print("DEBUGLINK SEND", pprint(msg)) self.transport.write(msg) if nowait: - return + return None ret = self.transport.read() - print("DEBUGLINK RECV", pprint(ret)) return ret def read_pin(self):