|
|
|
@ -34,10 +34,9 @@ from . import messages as proto
|
|
|
|
|
from . import tools
|
|
|
|
|
from . import mapping
|
|
|
|
|
from . import nem
|
|
|
|
|
from . import protobuf
|
|
|
|
|
from . import stellar
|
|
|
|
|
from .debuglink import DebugLink
|
|
|
|
|
from .protobuf import MessageType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info.major < 3:
|
|
|
|
|
raise Exception("Trezorlib does not support Python 2 anymore.")
|
|
|
|
@ -83,38 +82,6 @@ def get_buttonrequest_value(code):
|
|
|
|
|
return [k for k in dir(proto.ButtonRequestType) if getattr(proto.ButtonRequestType, k) == code][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_protobuf(pb, indent=0, sep=' ' * 4):
|
|
|
|
|
def pformat_value(value, indent):
|
|
|
|
|
level = sep * indent
|
|
|
|
|
leadin = sep * (indent + 1)
|
|
|
|
|
if isinstance(value, MessageType):
|
|
|
|
|
return format_protobuf(value, indent, sep)
|
|
|
|
|
if isinstance(value, list):
|
|
|
|
|
lines = []
|
|
|
|
|
lines.append('[')
|
|
|
|
|
lines += [leadin + pformat_value(x, indent + 1) + ',' for x in value]
|
|
|
|
|
lines.append(level + ']')
|
|
|
|
|
return '\n'.join(lines)
|
|
|
|
|
if isinstance(value, dict):
|
|
|
|
|
lines = []
|
|
|
|
|
lines.append('{')
|
|
|
|
|
for key, val in sorted(value.items()):
|
|
|
|
|
if val is None or val == []:
|
|
|
|
|
continue
|
|
|
|
|
if key == 'address_n' and isinstance(val, list):
|
|
|
|
|
lines.append(leadin + key + ': ' + repr(val) + ',')
|
|
|
|
|
else:
|
|
|
|
|
lines.append(leadin + key + ': ' + pformat_value(val, indent + 1) + ',')
|
|
|
|
|
lines.append(level + '}')
|
|
|
|
|
return '\n'.join(lines)
|
|
|
|
|
if isinstance(value, bytearray):
|
|
|
|
|
return 'bytearray(0x{})'.format(binascii.hexlify(value).decode('ascii'))
|
|
|
|
|
|
|
|
|
|
return repr(value)
|
|
|
|
|
|
|
|
|
|
return pb.__class__.__name__ + ' ' + pformat_value(pb.__dict__, indent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pprint(msg):
|
|
|
|
|
msg_class = msg.__class__.__name__
|
|
|
|
|
msg_size = msg.ByteSize()
|
|
|
|
@ -122,7 +89,7 @@ def pprint(msg):
|
|
|
|
|
or isinstance(msg, proto.Features):
|
|
|
|
|
return "<%s> (%d bytes)" % (msg_class, msg_size)
|
|
|
|
|
else:
|
|
|
|
|
return "<%s> (%d bytes):\n%s" % (msg_class, msg_size, format_protobuf(msg))
|
|
|
|
|
return "<%s> (%d bytes):\n%s" % (msg_class, msg_size, protobuf.format_message(msg))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log(msg):
|
|
|
|
|