diff --git a/tests/common.py b/tests/common.py index e31886562..317e30536 100644 --- a/tests/common.py +++ b/tests/common.py @@ -24,8 +24,8 @@ class TrezorTest(unittest.TestCase): self.client.wipe_device() - print "Setup finished" - print "--------------" + print("Setup finished") + print("--------------") def setup_mnemonic_nopin_nopassphrase(self): self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin='', passphrase_protection=False, label='test', language='english') diff --git a/tests/config.py b/tests/config.py index 45ae8a9e5..0bac30f0b 100644 --- a/tests/config.py +++ b/tests/config.py @@ -10,7 +10,7 @@ devices = HidTransport.enumerate() if len(devices) > 0: if devices[0][1] != None: - print 'Using TREZOR' + print('Using TREZOR') TRANSPORT = HidTransport TRANSPORT_ARGS = (devices[0],) TRANSPORT_KWARGS = {'debug_link': False} @@ -18,7 +18,7 @@ if len(devices) > 0: DEBUG_TRANSPORT_ARGS = (devices[0],) DEBUG_TRANSPORT_KWARGS = {'debug_link': True} else: - print 'Using Raspberry Pi' + print('Using Raspberry Pi') TRANSPORT = HidTransport TRANSPORT_ARGS = (devices[0],) TRANSPORT_KWARGS = {'debug_link': False} @@ -26,7 +26,7 @@ if len(devices) > 0: DEBUG_TRANSPORT_ARGS = ('trezor.bo:2000',) DEBUG_TRANSPORT_KWARGS = {} else: - print 'Using Emulator' + print('Using Emulator') TRANSPORT = PipeTransport TRANSPORT_ARGS = ('/tmp/pipe.trezor', False) TRANSPORT_KWARGS = {} diff --git a/tests/test_bip32_speed.py b/tests/test_bip32_speed.py index e98d20430..7a525c1b2 100644 --- a/tests/test_bip32_speed.py +++ b/tests/test_bip32_speed.py @@ -15,7 +15,7 @@ class TestBip32Speed(common.TrezorTest): self.client.get_address('Bitcoin', range(depth)) delay = time.time() - start expected = (depth + 1) * 0.26 - print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay + print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) self.assertLessEqual(delay, expected) def test_private_ckd(self): @@ -28,7 +28,7 @@ class TestBip32Speed(common.TrezorTest): self.client.get_address('Bitcoin', range(-depth, 0)) delay = time.time() - start expected = (depth + 1) * 0.26 - print "DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay + print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) self.assertLessEqual(delay, expected) def test_cache(self): @@ -44,8 +44,8 @@ class TestBip32Speed(common.TrezorTest): self.client.get_address('Bitcoin', [1, 2, 3, 4, 5, 6, 7, x]) cache_time = time.time() - start - print "NOCACHE TIME", nocache_time - print "CACHED TIME", cache_time + print("NOCACHE TIME", nocache_time) + print("CACHED TIME", cache_time) # Cached time expected to be at least 2x faster self.assertLessEqual(cache_time, nocache_time / 2.) diff --git a/tests/test_ecies.py b/tests/test_ecies.py index 2ca238204..b6564f9ce 100644 --- a/tests/test_ecies.py +++ b/tests/test_ecies.py @@ -14,14 +14,14 @@ def test_ecies_backforth(cls, test_string): # encrypt without signature enc = cls.client.encrypt_message(pubkey, test_string, display_only=False, coin_name='Bitcoin', n=[]) - print 'base64:', base64.b64encode(enc.nonce + enc.message + enc.hmac) + print('base64:', base64.b64encode(enc.nonce + enc.message + enc.hmac)) dec = cls.client.decrypt_message([1], enc.nonce, enc.message, enc.hmac) cls.assertEqual(dec.message, test_string) cls.assertEqual(dec.address, '') # encrypt with signature enc = cls.client.encrypt_message(pubkey, test_string, display_only=False, coin_name='Bitcoin', n=[5]) - print 'base64:', base64.b64encode(enc.nonce + enc.message + enc.hmac) + print('base64:', base64.b64encode(enc.nonce + enc.message + enc.hmac)) dec = cls.client.decrypt_message([1], enc.nonce, enc.message, enc.hmac) cls.assertEqual(dec.message, test_string) cls.assertEqual(dec.address, '1Csf6LVPkv24FBs6bpj4ELPszE6mGf6jeV') diff --git a/tests/test_msg_getentropy.py b/tests/test_msg_getentropy.py index 8cf7a6585..4a2c325fd 100644 --- a/tests/test_msg_getentropy.py +++ b/tests/test_msg_getentropy.py @@ -26,7 +26,7 @@ class TestMsgGetentropy(common.TrezorTest): self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Entropy()]) ent = self.client.get_entropy(l) self.assertTrue(len(ent) >= l) - print 'entropy = ', entropy(ent) + print('entropy = ', entropy(ent)) if __name__ == '__main__': unittest.main() diff --git a/tests/test_msg_recoverydevice.py b/tests/test_msg_recoverydevice.py index f187140a9..0ccbdfce5 100644 --- a/tests/test_msg_recoverydevice.py +++ b/tests/test_msg_recoverydevice.py @@ -36,7 +36,7 @@ class TestDeviceRecovery(common.TrezorTest): ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 - print mnemonic + print(mnemonic) # Workflow succesfully ended self.assertIsInstance(ret, proto.Success) @@ -83,7 +83,7 @@ class TestDeviceRecovery(common.TrezorTest): ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 - print mnemonic + print(mnemonic) # Workflow succesfully ended self.assertIsInstance(ret, proto.Success) diff --git a/tests/test_msg_signidentity.py b/tests/test_msg_signidentity.py index ff7ac5307..aeb73f3e1 100644 --- a/tests/test_msg_signidentity.py +++ b/tests/test_msg_signidentity.py @@ -17,10 +17,10 @@ def check_path(identity): if identity.port: uri += ':' + identity.port if identity.path: uri += identity.path m.update(uri) - print 'hash:', m.hexdigest() + print('hash:', m.hexdigest()) (a, b, c, d, _, _, _, _) = struct.unpack('<8I', m.digest()) address_n = [0x80000000 | 13, 0x80000000 | a, 0x80000000 | b, 0x80000000 | c, 0x80000000 | d] - print 'path:', 'm/' + '/'.join([str(x) for x in address_n]) + print('path:', 'm/' + '/'.join([str(x) for x in address_n])) class TestMsgSignidentity(common.TrezorTest): diff --git a/tests/test_protect_call.py b/tests/test_protect_call.py index fbe67fcda..d10c444fa 100644 --- a/tests/test_protect_call.py +++ b/tests/test_protect_call.py @@ -100,7 +100,7 @@ class TestProtectCall(common.TrezorTest): got = time.time() - start msg = "Pin delay expected to be at least %s seconds, got %s" % (expected, got) - print msg + print(msg) self.assertLessEqual(expected, got, msg) for attempt in range(1, 6): diff --git a/trezorlib/ckd_public.py b/trezorlib/ckd_public.py index bdf1eaac6..3a1204420 100644 --- a/trezorlib/ckd_public.py +++ b/trezorlib/ckd_public.py @@ -7,8 +7,8 @@ from ecdsa.util import string_to_number, number_to_string from ecdsa.curves import SECP256k1 from ecdsa.ellipticcurve import Point, INFINITY -import tools -import types_pb2 as proto_types +from . import tools +from . import types_pb2 as proto_types PRIME_DERIVATION_FLAG = 0x80000000 diff --git a/trezorlib/client.py b/trezorlib/client.py index b89fec885..1ac90cd82 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -4,15 +4,15 @@ import time import binascii import hashlib import unicodedata -import mapping import json import getpass import tools +import mapping import messages_pb2 as proto import types_pb2 as types import protobuf_json -from trezorlib.debuglink import DebugLink +from debuglink import DebugLink from mnemonic import Mnemonic diff --git a/trezorlib/debuglink.py b/trezorlib/debuglink.py index 374c19a6b..a9cbff340 100644 --- a/trezorlib/debuglink.py +++ b/trezorlib/debuglink.py @@ -1,11 +1,11 @@ -import messages_pb2 as proto -from transport import NotImplementedException +from . import messages_pb2 as proto +from .transport import NotImplementedException def pin_info(pin): - print "Device asks for PIN %s" % pin + print("Device asks for PIN %s" % pin) 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) @@ -21,18 +21,18 @@ class DebugLink(object): self.transport.close() def _call(self, msg, nowait=False): - print "DEBUGLINK SEND", pprint(msg) + print("DEBUGLINK SEND", pprint(msg)) self.transport.write(msg) if nowait: return ret = self.transport.read_blocking() - print "DEBUGLINK RECV", pprint(ret) + print("DEBUGLINK RECV", pprint(ret)) return ret def read_pin(self): obj = self._call(proto.DebugLinkGetState()) - print "Read PIN:", obj.pin - print "Read matrix:", obj.matrix + print("Read PIN:", obj.pin) + print("Read matrix:", obj.matrix) return (obj.pin, obj.matrix) @@ -51,7 +51,7 @@ class DebugLink(object): # on keypad, not a real PIN. pin_encoded = ''.join([ str(matrix.index(p) + 1) for p in pin]) - print "Encoded PIN:", pin_encoded + print("Encoded PIN:", pin_encoded) return pin_encoded def read_layout(self): @@ -83,7 +83,7 @@ class DebugLink(object): return obj.passphrase_protection def press_button(self, yes_no): - print "Pressing", yes_no + print("Pressing", yes_no) self.button_func(yes_no) self._call(proto.DebugLinkDecision(yes_no=yes_no), nowait=True) diff --git a/trezorlib/mapping.py b/trezorlib/mapping.py index c20661d63..3496d8ada 100644 --- a/trezorlib/mapping.py +++ b/trezorlib/mapping.py @@ -1,4 +1,4 @@ -import messages_pb2 as proto +from . import messages_pb2 as proto map_type_to_class = {} map_class_to_type = {} diff --git a/trezorlib/protobuf_json.py b/trezorlib/protobuf_json.py index 908b9065b..042ef428f 100644 --- a/trezorlib/protobuf_json.py +++ b/trezorlib/protobuf_json.py @@ -44,7 +44,7 @@ __author__='Paul Dovbush ' import json from google.protobuf.descriptor import FieldDescriptor as FD import binascii -import types_pb2 as types +from . import types_pb2 as types class ParseError(Exception): pass diff --git a/trezorlib/transport.py b/trezorlib/transport.py index ba0fb7697..07db89350 100644 --- a/trezorlib/transport.py +++ b/trezorlib/transport.py @@ -1,5 +1,5 @@ import struct -import mapping +from . import mapping class NotImplementedException(Exception): pass @@ -115,7 +115,6 @@ class Transport(object): if i >= 64: # timeout raise Exception("Timed out while waiting for the magic character") - #print "Aligning to magic characters" c = read_f.read(1) if read_f.read(1) != "#": diff --git a/trezorlib/transport_bridge.py b/trezorlib/transport_bridge.py index 1453f74c7..513482727 100644 --- a/trezorlib/transport_bridge.py +++ b/trezorlib/transport_bridge.py @@ -1,11 +1,11 @@ '''BridgeTransport implements transport TREZOR Bridge (aka trezord).''' import requests -import protobuf_json import json -import mapping -from transport import Transport -import messages_pb2 as proto +from . import protobuf_json +from . import mapping +from . import messages_pb2 as proto +from .transport import Transport TREZORD_HOST = 'https://localback.net:21324' CONFIG_URL = 'https://mytrezor.com/data/plugin/config_signed.bin' diff --git a/trezorlib/transport_fake.py b/trezorlib/transport_fake.py index 82f44a2ce..d50bec7aa 100644 --- a/trezorlib/transport_fake.py +++ b/trezorlib/transport_fake.py @@ -2,7 +2,7 @@ # Local serial port loopback: socat PTY,link=COM8 PTY,link=COM9 -from transport import Transport, NotImplementedException +from .transport import Transport, NotImplementedException class FakeTransport(Transport): def __init__(self, device, *args, **kwargs): diff --git a/trezorlib/transport_hid.py b/trezorlib/transport_hid.py index 572687dc8..bdaf5cb08 100644 --- a/trezorlib/transport_hid.py +++ b/trezorlib/transport_hid.py @@ -2,7 +2,7 @@ import hid import time -from transport import Transport, ConnectionError +from .transport import Transport, ConnectionError DEVICE_IDS = [ # (0x10c4, 0xea80), # TREZOR Shield diff --git a/trezorlib/transport_pipe.py b/trezorlib/transport_pipe.py index 35a9a4e27..2f6789832 100644 --- a/trezorlib/transport_pipe.py +++ b/trezorlib/transport_pipe.py @@ -3,7 +3,7 @@ Use this transport for talking with trezor simulator.''' import os from select import select -from transport import Transport +from .transport import Transport class PipeTransport(Transport): def __init__(self, device, is_device, *args, **kwargs): @@ -16,8 +16,8 @@ class PipeTransport(Transport): self.filename_read = self.device+'.to' self.filename_write = self.device+'.from' - os.mkfifo(self.filename_read, 0600) - os.mkfifo(self.filename_write, 0600) + os.mkfifo(self.filename_read, 0o600) + os.mkfifo(self.filename_write, 0o600) else: self.filename_read = self.device+'.from' self.filename_write = self.device+'.to' @@ -47,7 +47,7 @@ class PipeTransport(Transport): self.write_f.write(msg) self.write_f.flush() except OSError: - print "Error while writing to socket" + print("Error while writing to socket") raise def _read(self): @@ -55,5 +55,5 @@ class PipeTransport(Transport): (msg_type, datalen) = self._read_headers(self.read_f) return (msg_type, self.read_f.read(datalen)) except IOError: - print "Failed to read from device" + print("Failed to read from device") raise diff --git a/trezorlib/transport_serial.py b/trezorlib/transport_serial.py index 79af28a4d..a69c0918e 100644 --- a/trezorlib/transport_serial.py +++ b/trezorlib/transport_serial.py @@ -4,7 +4,7 @@ import serial from select import select -from transport import Transport +from .transport import Transport class SerialTransport(Transport): def __init__(self, device, *args, **kwargs): @@ -27,7 +27,7 @@ class SerialTransport(Transport): self.serial.write(msg) self.serial.flush() except serial.SerialException: - print "Error while writing to socket" + print("Error while writing to socket") raise def _read(self): @@ -35,5 +35,5 @@ class SerialTransport(Transport): (msg_type, datalen) = self._read_headers(self.serial) return (msg_type, self.serial.read(datalen)) except serial.SerialException: - print "Failed to read from device" + print("Failed to read from device") raise diff --git a/trezorlib/transport_socket.py b/trezorlib/transport_socket.py index d320bbd3e..6a44f567c 100644 --- a/trezorlib/transport_socket.py +++ b/trezorlib/transport_socket.py @@ -2,7 +2,7 @@ import socket from select import select -from transport import Transport +from .transport import Transport class SocketTransportClient(Transport): def __init__(self, device, *args, **kwargs): @@ -37,7 +37,7 @@ class SocketTransportClient(Transport): (msg_type, datalen) = self._read_headers(self.filelike) return (msg_type, self.filelike.read(datalen)) except socket.error: - print "Failed to read from device" + print("Failed to read from device") return None class SocketTransport(Transport): @@ -63,7 +63,7 @@ class SocketTransport(Transport): self.socket.listen(5) def _disconnect_client(self): - print "Disconnecting client" + print("Disconnecting client") if self.client != None: self.client.close() self.client = None @@ -84,7 +84,7 @@ class SocketTransport(Transport): rlist, _, _ = select([self.socket], [], [], 0) if len(rlist) > 0: (self.client, ipaddr) = self.socket.accept() - print "Connected", ipaddr[0] + print("Connected", ipaddr[0]) self.filelike = self.client.makefile() return self.ready_to_read() return False @@ -97,7 +97,7 @@ class SocketTransport(Transport): self.filelike.write(msg) self.filelike.flush() except socket.error: - print "Socket error" + print("Socket error") self._disconnect_client() def _read(self): @@ -105,6 +105,6 @@ class SocketTransport(Transport): (msg_type, datalen) = self._read_headers(self.filelike) return (msg_type, self.filelike.read(datalen)) except Exception: - print "Failed to read from device" + print("Failed to read from device") self._disconnect_client() return None diff --git a/trezorlib/transport_udp.py b/trezorlib/transport_udp.py index c8aa10d32..eaf4b1b65 100644 --- a/trezorlib/transport_udp.py +++ b/trezorlib/transport_udp.py @@ -3,7 +3,7 @@ import socket from select import select import time -from transport import Transport, ConnectionError +from .transport import Transport, ConnectionError class FakeRead(object): # Let's pretend we have a file-like interface diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index fa5665b9c..2da2f4ad7 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -3,7 +3,7 @@ import urllib2 import json from decimal import Decimal # from filecache import filecache, DAY -import types_pb2 as proto_types +from . import types_pb2 as proto_types def insight_tx(url, rawdata=False): if not rawdata: