mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
fix pylint warnings
This commit is contained in:
parent
cbbd7004a8
commit
3a108ee8a5
@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import binascii
|
||||
import hashlib
|
||||
import mnemonic
|
||||
|
||||
__doc__ = '''
|
||||
Use this script to cross-check that TREZOR generated valid
|
||||
@ -13,10 +16,6 @@ __doc__ = '''
|
||||
without an internet connection).
|
||||
'''
|
||||
|
||||
import binascii
|
||||
import hashlib
|
||||
import mnemonic
|
||||
|
||||
# Python2 vs Python3
|
||||
try:
|
||||
input = raw_input
|
||||
|
@ -1,10 +1,9 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import config
|
||||
|
||||
from trezorlib.client import TrezorDebugClient
|
||||
from trezorlib.tx_api import TXAPIBitcoin
|
||||
import config
|
||||
|
||||
class TrezorTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -110,9 +110,9 @@ def main():
|
||||
|
||||
sys.stderr.write('Please confirm action on your device.\n')
|
||||
passw = client.decrypt_keyvalue(data['bip32_path'],
|
||||
data['label'],
|
||||
binascii.unhexlify(data['password_encrypted_hex']),
|
||||
False, True)
|
||||
data['label'],
|
||||
binascii.unhexlify(data['password_encrypted_hex']),
|
||||
False, True)
|
||||
|
||||
print(passw)
|
||||
|
||||
|
26
trezorctl
26
trezorctl
@ -13,7 +13,7 @@ from trezorlib.client import TrezorClient, TrezorClientDebug
|
||||
def parse_args(commands):
|
||||
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('-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('-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)")
|
||||
@ -80,7 +80,7 @@ def get_transport(transport_string, path, **kwargs):
|
||||
from trezorlib.transport_fake import FakeTransport
|
||||
return FakeTransport(path, **kwargs)
|
||||
|
||||
raise NotImplemented("Unknown transport")
|
||||
raise NotImplementedError("Unknown transport")
|
||||
|
||||
class Commands(object):
|
||||
def __init__(self, client):
|
||||
@ -88,7 +88,7 @@ class Commands(object):
|
||||
|
||||
@classmethod
|
||||
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):
|
||||
# Fake method for advertising 'list' command
|
||||
@ -110,7 +110,7 @@ class Commands(object):
|
||||
return self.client.features
|
||||
|
||||
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):
|
||||
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):
|
||||
return self.client.apply_settings(label=args.label)
|
||||
|
||||
def set_homescreen(self,args):
|
||||
def set_homescreen(self, args):
|
||||
if args.filename:
|
||||
from PIL import Image
|
||||
im = Image.open(args.filename)
|
||||
if im.size != (128,64):
|
||||
if im.size != (128, 64):
|
||||
raise Exception('Wrong size of the image')
|
||||
im = im.convert('1')
|
||||
pix = im.load()
|
||||
@ -150,7 +150,7 @@ class Commands(object):
|
||||
|
||||
def recovery_device(self, args):
|
||||
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):
|
||||
if not args.mnemonic and not args.xprv:
|
||||
@ -159,11 +159,13 @@ class Commands(object):
|
||||
if args.mnemonic:
|
||||
mnemonic = ' '.join(args.mnemonic)
|
||||
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:
|
||||
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):
|
||||
return self.client.reset_device(True, args.strength, args.passphrase_protection,
|
||||
@ -296,14 +298,14 @@ class Commands(object):
|
||||
|
||||
set_label.arguments = (
|
||||
(('-l', '--label',), {'type': str, 'default': ''}),
|
||||
# (('-c', '--clear'), {'action': 'store_true', 'default': False})
|
||||
# (('-c', '--clear'), {'action': 'store_true', 'default': False})
|
||||
)
|
||||
|
||||
set_homescreen.arguments = (
|
||||
(('-f', '--filename',), {'type': str, 'default': ''}),
|
||||
)
|
||||
change_pin.arguments = (
|
||||
(('-r', '--remove'), {'action': 'store_true', 'default': False}),
|
||||
(('-r', '--remove'), {'action': 'store_true', 'default': False}),
|
||||
)
|
||||
|
||||
wipe_device.arguments = ()
|
||||
|
@ -99,7 +99,7 @@ def serialize(node, version=0x0488B21E):
|
||||
s += node.chain_code
|
||||
if node.private_key:
|
||||
s += '\x00' + node.private_key
|
||||
else :
|
||||
else:
|
||||
s += node.public_key
|
||||
s += tools.Hash(s)[:4]
|
||||
return tools.b58encode(s)
|
||||
|
@ -51,7 +51,7 @@ class DebugLink(object):
|
||||
# We have to encode that into encoded pin,
|
||||
# because application must send back positions
|
||||
# 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)
|
||||
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
|
||||
# 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
|
||||
from google.protobuf.descriptor import FieldDescriptor as FD
|
||||
import binascii
|
||||
from . import types_pb2 as types
|
||||
|
||||
__version__ = '0.0.5'
|
||||
__author__ = 'Paul Dovbush <dpp@dpp.su>'
|
||||
|
||||
class ParseError(Exception): pass
|
||||
|
||||
|
||||
@ -82,7 +81,7 @@ def pb2json(pb):
|
||||
js = {}
|
||||
# fields = pb.DESCRIPTOR.fields #all fields
|
||||
fields = pb.ListFields() #only filled (including extensions)
|
||||
for field,value in fields:
|
||||
for field, value in fields:
|
||||
if field.type == FD.TYPE_MESSAGE:
|
||||
ftype = pb2json
|
||||
elif field.type == FD.TYPE_ENUM:
|
||||
|
@ -1,10 +1,8 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import math
|
||||
import operator
|
||||
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
|
||||
|
||||
class PinButton(QPushButton):
|
||||
|
@ -77,7 +77,7 @@ class Transport(object):
|
||||
return None
|
||||
|
||||
data = self._read()
|
||||
if data == None:
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
return self._parse_message(data)
|
||||
|
@ -1,9 +1,8 @@
|
||||
'''BridgeTransport implements transport TREZOR Bridge (aka trezord).'''
|
||||
|
||||
import requests
|
||||
import json
|
||||
import requests
|
||||
from . import protobuf_json
|
||||
from . import mapping
|
||||
from . import messages_pb2 as proto
|
||||
from .transport import Transport
|
||||
|
||||
@ -21,7 +20,7 @@ class BridgeTransport(Transport):
|
||||
|
||||
self.session = None
|
||||
self.response = None
|
||||
self.conn = requests.Session();
|
||||
self.conn = requests.Session()
|
||||
|
||||
super(BridgeTransport, self).__init__(device, *args, **kwargs)
|
||||
|
||||
@ -81,7 +80,7 @@ class BridgeTransport(Transport):
|
||||
self.response = r.json()
|
||||
|
||||
def _read(self):
|
||||
if self.response == None:
|
||||
if self.response is None:
|
||||
raise Exception('No response stored')
|
||||
cls = getattr(proto, self.response['type'])
|
||||
inst = cls()
|
||||
|
@ -5,7 +5,7 @@ import time
|
||||
from .transport import Transport, ConnectionError
|
||||
|
||||
DEVICE_IDS = [
|
||||
# (0x10c4, 0xea80), # TREZOR Shield
|
||||
# (0x10c4, 0xea80), # TREZOR Shield
|
||||
(0x534c, 0x0001), # TREZOR
|
||||
]
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
from __future__ import print_function
|
||||
|
||||
'''PipeTransport implements fake wire transport over local named pipe.
|
||||
Use this transport for talking with trezor simulator.'''
|
||||
|
||||
import os
|
||||
from select import select
|
||||
from .transport import Transport
|
||||
|
||||
"""PipeTransport implements fake wire transport over local named pipe.
|
||||
Use this transport for talking with trezor simulator."""
|
||||
|
||||
class PipeTransport(Transport):
|
||||
def __init__(self, device, is_device, *args, **kwargs):
|
||||
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
|
||||
|
||||
import serial
|
||||
from select import select
|
||||
import serial
|
||||
from .transport import Transport
|
||||
|
||||
class SerialTransport(Transport):
|
||||
|
@ -1,17 +1,19 @@
|
||||
import binascii
|
||||
import json
|
||||
from decimal import Decimal
|
||||
# from filecache import filecache, DAY
|
||||
from . import types_pb2 as proto_types
|
||||
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):
|
||||
if not rawdata:
|
||||
try:
|
||||
r = requests.get(url, headers = {'User-agent': 'Mozilla/5.0'})
|
||||
data = r.json()
|
||||
except:
|
||||
raise Exception('URL error: %s' % url)
|
||||
data = fetch_json(url)
|
||||
else:
|
||||
data = url
|
||||
|
||||
@ -42,11 +44,7 @@ def insight_tx(url, rawdata=False):
|
||||
|
||||
def smartbit_tx(url, rawdata=False):
|
||||
if not rawdata:
|
||||
try:
|
||||
r = requests.get(url, headers = {'User-agent': 'Mozilla/5.0'})
|
||||
data = r.json()
|
||||
except:
|
||||
raise Exception('URL error: %s' % url)
|
||||
data = fetch_json(url)
|
||||
else:
|
||||
data = url
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user