mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-12 23:52:39 +00:00
logging: get rid of pprint and VerboseWireMixin
(and also TrezorClientVerbose)
This commit is contained in:
parent
ca8ebacab9
commit
0b6ec27064
@ -210,14 +210,6 @@ class BaseClient(object):
|
|||||||
mapping.register_message(msg)
|
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):
|
class TextUIMixin(object):
|
||||||
# This class demonstrates easy test-based UI
|
# This class demonstrates easy test-based UI
|
||||||
# integration between the device and wallet.
|
# integration between the device and wallet.
|
||||||
@ -362,7 +354,7 @@ class DebugLinkMixin(object):
|
|||||||
# Evaluate missed responses in 'with' statement
|
# Evaluate missed responses in 'with' statement
|
||||||
if self.expected_responses is not None and len(self.expected_responses):
|
if self.expected_responses is not None and len(self.expected_responses):
|
||||||
raise RuntimeError("Some of expected responses didn't come from device: %s" %
|
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
|
# Cleanup
|
||||||
self.expected_responses = None
|
self.expected_responses = None
|
||||||
@ -408,18 +400,18 @@ class DebugLinkMixin(object):
|
|||||||
expected = self.expected_responses.pop(0)
|
expected = self.expected_responses.pop(0)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise AssertionException(proto.FailureType.UnexpectedMessage,
|
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__:
|
if msg.__class__ != expected.__class__:
|
||||||
raise AssertionException(proto.FailureType.UnexpectedMessage,
|
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():
|
for field, value in expected.__dict__.items():
|
||||||
if value is None or value == []:
|
if value is None or value == []:
|
||||||
continue
|
continue
|
||||||
if getattr(msg, field) != value:
|
if getattr(msg, field) != value:
|
||||||
raise AssertionException(proto.FailureType.UnexpectedMessage,
|
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):
|
def callback_ButtonRequest(self, msg):
|
||||||
log("ButtonRequest code: " + get_buttonrequest_value(msg.code))
|
log("ButtonRequest code: " + get_buttonrequest_value(msg.code))
|
||||||
@ -1165,11 +1157,6 @@ class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
|
|||||||
super().__init__(transport=transport, *args, **kwargs)
|
super().__init__(transport=transport, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TrezorClientVerbose(ProtocolMixin, TextUIMixin, VerboseWireMixin, BaseClient):
|
class TrezorClientDebugLink(ProtocolMixin, DebugLinkMixin, BaseClient):
|
||||||
def __init__(self, transport, *args, **kwargs):
|
|
||||||
super().__init__(transport=transport, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class TrezorClientDebugLink(ProtocolMixin, DebugLinkMixin, VerboseWireMixin, BaseClient):
|
|
||||||
def __init__(self, transport, *args, **kwargs):
|
def __init__(self, transport, *args, **kwargs):
|
||||||
super().__init__(transport=transport, *args, **kwargs)
|
super().__init__(transport=transport, *args, **kwargs)
|
||||||
|
@ -29,10 +29,6 @@ def button_press(yes_no):
|
|||||||
print("User pressed", '"y"' if yes_no else '"n"')
|
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):
|
class DebugLink(object):
|
||||||
def __init__(self, transport, pin_func=pin_info, button_func=button_press):
|
def __init__(self, transport, pin_func=pin_info, button_func=button_press):
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
@ -45,12 +41,10 @@ class DebugLink(object):
|
|||||||
self.transport.session_end()
|
self.transport.session_end()
|
||||||
|
|
||||||
def _call(self, msg, nowait=False):
|
def _call(self, msg, nowait=False):
|
||||||
print("DEBUGLINK SEND", pprint(msg))
|
|
||||||
self.transport.write(msg)
|
self.transport.write(msg)
|
||||||
if nowait:
|
if nowait:
|
||||||
return
|
return None
|
||||||
ret = self.transport.read()
|
ret = self.transport.read()
|
||||||
print("DEBUGLINK RECV", pprint(ret))
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def read_pin(self):
|
def read_pin(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user