fix pylint warnings

pull/1/head
Pavol Rusnak 8 years ago
parent cbbd7004a8
commit 3a108ee8a5
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -1,5 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
import binascii
import hashlib
import mnemonic
__doc__ = ''' __doc__ = '''
Use this script to cross-check that TREZOR generated valid Use this script to cross-check that TREZOR generated valid
@ -13,10 +16,6 @@ __doc__ = '''
without an internet connection). without an internet connection).
''' '''
import binascii
import hashlib
import mnemonic
# Python2 vs Python3 # Python2 vs Python3
try: try:
input = raw_input input = raw_input

@ -1,10 +1,9 @@
from __future__ import print_function from __future__ import print_function
import unittest import unittest
import config
from trezorlib.client import TrezorDebugClient from trezorlib.client import TrezorDebugClient
from trezorlib.tx_api import TXAPIBitcoin from trezorlib.tx_api import TXAPIBitcoin
import config
class TrezorTest(unittest.TestCase): class TrezorTest(unittest.TestCase):
def setUp(self): def setUp(self):

@ -110,9 +110,9 @@ def main():
sys.stderr.write('Please confirm action on your device.\n') sys.stderr.write('Please confirm action on your device.\n')
passw = client.decrypt_keyvalue(data['bip32_path'], passw = client.decrypt_keyvalue(data['bip32_path'],
data['label'], data['label'],
binascii.unhexlify(data['password_encrypted_hex']), binascii.unhexlify(data['password_encrypted_hex']),
False, True) False, True)
print(passw) print(passw)

@ -13,7 +13,7 @@ from trezorlib.client import TrezorClient, TrezorClientDebug
def parse_args(commands): def parse_args(commands):
parser = argparse.ArgumentParser(description='Commandline tool for TREZOR devices.') parser = argparse.ArgumentParser(description='Commandline tool for TREZOR devices.')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Prints communication to device') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Prints communication to device')
parser.add_argument('-t', '--transport', dest='transport', choices=['usb', 'udp', 'serial', 'pipe', 'socket', 'bridge'], default='usb', help="Transport used for talking with the device") parser.add_argument('-t', '--transport', dest='transport', choices=['usb', 'udp', 'serial', 'pipe', 'socket', 'bridge'], default='usb', help="Transport used for talking with the device")
parser.add_argument('-p', '--path', dest='path', default='', help="Path used by the transport (usually serial port)") parser.add_argument('-p', '--path', dest='path', default='', help="Path used by the transport (usually serial port)")
# parser.add_argument('-dt', '--debuglink-transport', dest='debuglink_transport', choices=['usb', 'serial', 'pipe', 'socket'], default='usb', help="Debuglink transport") # parser.add_argument('-dt', '--debuglink-transport', dest='debuglink_transport', choices=['usb', 'serial', 'pipe', 'socket'], default='usb', help="Debuglink transport")
# parser.add_argument('-dp', '--debuglink-path', dest='debuglink_path', default='', help="Path used by the transport (usually serial port)") # parser.add_argument('-dp', '--debuglink-path', dest='debuglink_path', default='', help="Path used by the transport (usually serial port)")
@ -80,7 +80,7 @@ def get_transport(transport_string, path, **kwargs):
from trezorlib.transport_fake import FakeTransport from trezorlib.transport_fake import FakeTransport
return FakeTransport(path, **kwargs) return FakeTransport(path, **kwargs)
raise NotImplemented("Unknown transport") raise NotImplementedError("Unknown transport")
class Commands(object): class Commands(object):
def __init__(self, client): def __init__(self, client):
@ -88,7 +88,7 @@ class Commands(object):
@classmethod @classmethod
def _list_commands(cls): def _list_commands(cls):
return [ x for x in dir(cls) if not x.startswith('_') ] return [x for x in dir(cls) if not x.startswith('_')]
def list(self, args): def list(self, args):
# Fake method for advertising 'list' command # Fake method for advertising 'list' command
@ -110,7 +110,7 @@ class Commands(object):
return self.client.features return self.client.features
def list_coins(self, args): def list_coins(self, args):
return [ coin.coin_name for coin in self.client.features.coins ] return [coin.coin_name for coin in self.client.features.coins]
def ping(self, args): def ping(self, args):
return self.client.ping(args.msg, button_protection=args.button_protection, pin_protection=args.pin_protection, passphrase_protection=args.passphrase_protection) return self.client.ping(args.msg, button_protection=args.button_protection, pin_protection=args.pin_protection, passphrase_protection=args.passphrase_protection)
@ -122,11 +122,11 @@ class Commands(object):
def set_label(self, args): def set_label(self, args):
return self.client.apply_settings(label=args.label) return self.client.apply_settings(label=args.label)
def set_homescreen(self,args): def set_homescreen(self, args):
if args.filename: if args.filename:
from PIL import Image from PIL import Image
im = Image.open(args.filename) im = Image.open(args.filename)
if im.size != (128,64): if im.size != (128, 64):
raise Exception('Wrong size of the image') raise Exception('Wrong size of the image')
im = im.convert('1') im = im.convert('1')
pix = im.load() pix = im.load()
@ -150,7 +150,7 @@ class Commands(object):
def recovery_device(self, args): def recovery_device(self, args):
return self.client.recovery_device(args.words, args.passphrase_protection, return self.client.recovery_device(args.words, args.passphrase_protection,
args.pin_protection, args.label, 'english') args.pin_protection, args.label, 'english')
def load_device(self, args): def load_device(self, args):
if not args.mnemonic and not args.xprv: if not args.mnemonic and not args.xprv:
@ -159,11 +159,13 @@ class Commands(object):
if args.mnemonic: if args.mnemonic:
mnemonic = ' '.join(args.mnemonic) mnemonic = ' '.join(args.mnemonic)
return self.client.load_device_by_mnemonic(mnemonic, args.pin, return self.client.load_device_by_mnemonic(mnemonic, args.pin,
args.passphrase_protection, args.label, 'english', args.skip_checksum) args.passphrase_protection,
args.label, 'english',
args.skip_checksum)
else: else:
return self.client.load_device_by_xprv(args.xprv, args.pin, return self.client.load_device_by_xprv(args.xprv, args.pin,
args.passphrase_protection, args.label, 'english') args.passphrase_protection,
args.label, 'english')
def reset_device(self, args): def reset_device(self, args):
return self.client.reset_device(True, args.strength, args.passphrase_protection, return self.client.reset_device(True, args.strength, args.passphrase_protection,
@ -296,14 +298,14 @@ class Commands(object):
set_label.arguments = ( set_label.arguments = (
(('-l', '--label',), {'type': str, 'default': ''}), (('-l', '--label',), {'type': str, 'default': ''}),
# (('-c', '--clear'), {'action': 'store_true', 'default': False}) # (('-c', '--clear'), {'action': 'store_true', 'default': False})
) )
set_homescreen.arguments = ( set_homescreen.arguments = (
(('-f', '--filename',), {'type': str, 'default': ''}), (('-f', '--filename',), {'type': str, 'default': ''}),
) )
change_pin.arguments = ( change_pin.arguments = (
(('-r', '--remove'), {'action': 'store_true', 'default': False}), (('-r', '--remove'), {'action': 'store_true', 'default': False}),
) )
wipe_device.arguments = () wipe_device.arguments = ()

@ -99,7 +99,7 @@ def serialize(node, version=0x0488B21E):
s += node.chain_code s += node.chain_code
if node.private_key: if node.private_key:
s += '\x00' + node.private_key s += '\x00' + node.private_key
else : else:
s += node.public_key s += node.public_key
s += tools.Hash(s)[:4] s += tools.Hash(s)[:4]
return tools.b58encode(s) return tools.b58encode(s)

@ -51,7 +51,7 @@ class DebugLink(object):
# We have to encode that into encoded pin, # We have to encode that into encoded pin,
# because application must send back positions # because application must send back positions
# on keypad, not a real PIN. # on keypad, not a real PIN.
pin_encoded = ''.join([ str(matrix.index(p) + 1) for p in 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 return pin_encoded

@ -37,15 +37,14 @@ Provide serialization and de-serialization of Google's protobuf Messages into/fr
# Note that preservation of unknown fields is currently not available for Python (c) google docs # Note that preservation of unknown fields is currently not available for Python (c) google docs
# extensions is not supported from 0.0.5 (due to gpb2.3 changes) # extensions is not supported from 0.0.5 (due to gpb2.3 changes)
__version__='0.0.5'
__author__='Paul Dovbush <dpp@dpp.su>'
import json import json
from google.protobuf.descriptor import FieldDescriptor as FD from google.protobuf.descriptor import FieldDescriptor as FD
import binascii import binascii
from . import types_pb2 as types from . import types_pb2 as types
__version__ = '0.0.5'
__author__ = 'Paul Dovbush <dpp@dpp.su>'
class ParseError(Exception): pass class ParseError(Exception): pass
@ -82,7 +81,7 @@ def pb2json(pb):
js = {} js = {}
# fields = pb.DESCRIPTOR.fields #all fields # fields = pb.DESCRIPTOR.fields #all fields
fields = pb.ListFields() #only filled (including extensions) fields = pb.ListFields() #only filled (including extensions)
for field,value in fields: for field, value in fields:
if field.type == FD.TYPE_MESSAGE: if field.type == FD.TYPE_MESSAGE:
ftype = pb2json ftype = pb2json
elif field.type == FD.TYPE_ENUM: elif field.type == FD.TYPE_ENUM:

@ -1,10 +1,8 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
import math import math
import operator
from PyQt4.QtGui import (QPushButton, QLineEdit, QSizePolicy, QRegExpValidator, QLabel, from PyQt4.QtGui import (QPushButton, QLineEdit, QSizePolicy, QRegExpValidator, QLabel,
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout) QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt
class PinButton(QPushButton): class PinButton(QPushButton):

@ -77,7 +77,7 @@ class Transport(object):
return None return None
data = self._read() data = self._read()
if data == None: if data is None:
return None return None
return self._parse_message(data) return self._parse_message(data)

@ -1,9 +1,8 @@
'''BridgeTransport implements transport TREZOR Bridge (aka trezord).''' '''BridgeTransport implements transport TREZOR Bridge (aka trezord).'''
import requests
import json import json
import requests
from . import protobuf_json from . import protobuf_json
from . import mapping
from . import messages_pb2 as proto from . import messages_pb2 as proto
from .transport import Transport from .transport import Transport
@ -21,7 +20,7 @@ class BridgeTransport(Transport):
self.session = None self.session = None
self.response = None self.response = None
self.conn = requests.Session(); self.conn = requests.Session()
super(BridgeTransport, self).__init__(device, *args, **kwargs) super(BridgeTransport, self).__init__(device, *args, **kwargs)
@ -81,7 +80,7 @@ class BridgeTransport(Transport):
self.response = r.json() self.response = r.json()
def _read(self): def _read(self):
if self.response == None: if self.response is None:
raise Exception('No response stored') raise Exception('No response stored')
cls = getattr(proto, self.response['type']) cls = getattr(proto, self.response['type'])
inst = cls() inst = cls()

@ -5,7 +5,7 @@ import time
from .transport import Transport, ConnectionError from .transport import Transport, ConnectionError
DEVICE_IDS = [ DEVICE_IDS = [
# (0x10c4, 0xea80), # TREZOR Shield # (0x10c4, 0xea80), # TREZOR Shield
(0x534c, 0x0001), # TREZOR (0x534c, 0x0001), # TREZOR
] ]

@ -1,12 +1,11 @@
from __future__ import print_function from __future__ import print_function
'''PipeTransport implements fake wire transport over local named pipe.
Use this transport for talking with trezor simulator.'''
import os import os
from select import select from select import select
from .transport import Transport from .transport import Transport
"""PipeTransport implements fake wire transport over local named pipe.
Use this transport for talking with trezor simulator."""
class PipeTransport(Transport): class PipeTransport(Transport):
def __init__(self, device, is_device, *args, **kwargs): def __init__(self, device, is_device, *args, **kwargs):
self.is_device = is_device # Set True if act as device self.is_device = is_device # Set True if act as device

@ -4,8 +4,8 @@ from __future__ import print_function
# Local serial port loopback: socat PTY,link=COM8 PTY,link=COM9 # Local serial port loopback: socat PTY,link=COM8 PTY,link=COM9
import serial
from select import select from select import select
import serial
from .transport import Transport from .transport import Transport
class SerialTransport(Transport): class SerialTransport(Transport):

@ -1,17 +1,19 @@
import binascii import binascii
import json
from decimal import Decimal from decimal import Decimal
# from filecache import filecache, DAY # from filecache import filecache, DAY
from . import types_pb2 as proto_types
import requests import requests
from . import types_pb2 as proto_types
def fetch_json(url):
try:
r = requests.get(url, headers={'User-agent': 'Mozilla/5.0'})
return r.json()
except:
raise Exception('URL error: %s' % url)
def insight_tx(url, rawdata=False): def insight_tx(url, rawdata=False):
if not rawdata: if not rawdata:
try: data = fetch_json(url)
r = requests.get(url, headers = {'User-agent': 'Mozilla/5.0'})
data = r.json()
except:
raise Exception('URL error: %s' % url)
else: else:
data = url data = url
@ -42,11 +44,7 @@ def insight_tx(url, rawdata=False):
def smartbit_tx(url, rawdata=False): def smartbit_tx(url, rawdata=False):
if not rawdata: if not rawdata:
try: data = fetch_json(url)
r = requests.get(url, headers = {'User-agent': 'Mozilla/5.0'})
data = r.json()
except:
raise Exception('URL error: %s' % url)
else: else:
data = url data = url

Loading…
Cancel
Save