mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
style: bare excepts, left-over bad imports
This commit is contained in:
parent
8226742ea3
commit
29f928e4f2
@ -1,6 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Use TREZOR as a hardware key for opening EncFS filesystem!
|
Use TREZOR as a hardware key for opening EncFS filesystem!
|
||||||
|
|
||||||
@ -62,7 +60,7 @@ def choose_device(devices):
|
|||||||
try:
|
try:
|
||||||
device_id = int(input())
|
device_id = int(input())
|
||||||
return devices[device_id]
|
return devices[device_id]
|
||||||
except:
|
except Exception:
|
||||||
raise ValueError("Invalid choice, exiting...")
|
raise ValueError("Invalid choice, exiting...")
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from trezorlib.debuglink import DebugLink
|
from trezorlib.debuglink import DebugLink
|
||||||
from trezorlib.client import TrezorClient
|
from trezorlib.client import TrezorClient
|
||||||
from trezorlib.transport import enumerate_devices
|
from trezorlib.transport import enumerate_devices
|
||||||
import binascii
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sectoraddrs = [0x8000000, 0x8004000, 0x8008000, 0x800c000,
|
sectoraddrs = [0x8000000, 0x8004000, 0x8008000, 0x800c000,
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
# that has DEBUG_RNG == 1 as that will disable the user button
|
# that has DEBUG_RNG == 1 as that will disable the user button
|
||||||
# push confirmation
|
# push confirmation
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
from trezorlib.client import TrezorClient
|
from trezorlib.client import TrezorClient
|
||||||
|
@ -96,10 +96,10 @@ def cli(ctx, path, verbose, is_json):
|
|||||||
def get_device():
|
def get_device():
|
||||||
try:
|
try:
|
||||||
device = get_transport(path, prefix_search=False)
|
device = get_transport(path, prefix_search=False)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
device = get_transport(path, prefix_search=True)
|
device = get_transport(path, prefix_search=True)
|
||||||
except:
|
except Exception:
|
||||||
click.echo("Failed to find a TREZOR device.")
|
click.echo("Failed to find a TREZOR device.")
|
||||||
if path is not None:
|
if path is not None:
|
||||||
click.echo("Using path: {}".format(path))
|
click.echo("Using path: {}".format(path))
|
||||||
|
@ -21,7 +21,7 @@ from typing import Iterable, Tuple
|
|||||||
from . import messages
|
from . import messages
|
||||||
from .tools import expect
|
from .tools import expect
|
||||||
|
|
||||||
from trezorlib import _ed25519
|
from . import _ed25519
|
||||||
|
|
||||||
# XXX, these could be NewType's, but that would infect users of the cosi module with these types as well.
|
# XXX, these could be NewType's, but that would infect users of the cosi module with these types as well.
|
||||||
# Unsure if we want that.
|
# Unsure if we want that.
|
||||||
@ -90,7 +90,7 @@ def sign_with_privkey(digest: bytes, privkey: Ed25519PrivateKey,
|
|||||||
return Ed25519Signature(_ed25519.encodeint(S))
|
return Ed25519Signature(_ed25519.encodeint(S))
|
||||||
|
|
||||||
|
|
||||||
### Client functions ###
|
# ====== Client functions ====== #
|
||||||
|
|
||||||
|
|
||||||
@expect(messages.CosiCommitment)
|
@expect(messages.CosiCommitment)
|
||||||
|
@ -6,7 +6,7 @@ def int_to_big_endian(value):
|
|||||||
return value.to_bytes((value.bit_length() + 7) // 8, 'big')
|
return value.to_bytes((value.bit_length() + 7) // 8, 'big')
|
||||||
|
|
||||||
|
|
||||||
### Client functions ###
|
# ====== Client functions ====== #
|
||||||
|
|
||||||
|
|
||||||
@expect(proto.EthereumAddress, field="address")
|
@expect(proto.EthereumAddress, field="address")
|
||||||
|
@ -130,12 +130,12 @@ def validate_firmware(filename):
|
|||||||
try:
|
try:
|
||||||
cosi.verify(header.signature, digest, global_pk)
|
cosi.verify(header.signature, digest, global_pk)
|
||||||
print("Signature OK")
|
print("Signature OK")
|
||||||
except:
|
except Exception:
|
||||||
print("Signature FAILED")
|
print("Signature FAILED")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
### Client functions ###
|
# ====== Client functions ====== #
|
||||||
|
|
||||||
|
|
||||||
@tools.session
|
@tools.session
|
||||||
|
@ -167,7 +167,7 @@ def create_sign_tx(transaction):
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
### Client functions ###
|
# ====== Client functions ====== #
|
||||||
|
|
||||||
|
|
||||||
@expect(proto.NEMAddress, field="address")
|
@expect(proto.NEMAddress, field="address")
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# You should have received a copy of the License along with this library.
|
||||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
@ -79,7 +77,7 @@ class ProtocolV1:
|
|||||||
try:
|
try:
|
||||||
headerlen = struct.calcsize('>HL')
|
headerlen = struct.calcsize('>HL')
|
||||||
msg_type, datalen = struct.unpack('>HL', chunk[3:3 + headerlen])
|
msg_type, datalen = struct.unpack('>HL', chunk[3:3 + headerlen])
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError('Cannot parse header')
|
raise RuntimeError('Cannot parse header')
|
||||||
|
|
||||||
data = chunk[3 + headerlen:]
|
data = chunk[3 + headerlen:]
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# You should have received a copy of the License along with this library.
|
||||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
@ -110,7 +108,7 @@ class ProtocolV2:
|
|||||||
try:
|
try:
|
||||||
headerlen = struct.calcsize('>BLLL')
|
headerlen = struct.calcsize('>BLLL')
|
||||||
magic, session, msg_type, datalen = struct.unpack('>BLLL', chunk[:headerlen])
|
magic, session, msg_type, datalen = struct.unpack('>BLLL', chunk[:headerlen])
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError('Cannot parse header')
|
raise RuntimeError('Cannot parse header')
|
||||||
if magic != 0x01:
|
if magic != 0x01:
|
||||||
raise RuntimeError('Unexpected magic character')
|
raise RuntimeError('Unexpected magic character')
|
||||||
@ -122,7 +120,7 @@ class ProtocolV2:
|
|||||||
try:
|
try:
|
||||||
headerlen = struct.calcsize('>BLL')
|
headerlen = struct.calcsize('>BLL')
|
||||||
magic, session, sequence = struct.unpack('>BLL', chunk[:headerlen])
|
magic, session, sequence = struct.unpack('>BLL', chunk[:headerlen])
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError('Cannot parse header')
|
raise RuntimeError('Cannot parse header')
|
||||||
if magic != 0x02:
|
if magic != 0x02:
|
||||||
raise RuntimeError('Unexpected magic characters')
|
raise RuntimeError('Unexpected magic characters')
|
||||||
@ -134,7 +132,7 @@ class ProtocolV2:
|
|||||||
try:
|
try:
|
||||||
headerlen = struct.calcsize('>BL')
|
headerlen = struct.calcsize('>BL')
|
||||||
magic, session = struct.unpack('>BL', chunk[:headerlen])
|
magic, session = struct.unpack('>BL', chunk[:headerlen])
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError('Cannot parse header')
|
raise RuntimeError('Cannot parse header')
|
||||||
if magic != 0x03:
|
if magic != 0x03:
|
||||||
raise RuntimeError('Unexpected magic character')
|
raise RuntimeError('Unexpected magic character')
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# You should have received a copy of the License along with this library.
|
||||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ try:
|
|||||||
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, QT_VERSION_STR
|
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR
|
||||||
except:
|
except ImportError:
|
||||||
from PyQt5.QtWidgets import (QPushButton, QLineEdit, QSizePolicy, QLabel,
|
from PyQt5.QtWidgets import (QPushButton, QLineEdit, QSizePolicy, QLabel,
|
||||||
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
|
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
|
||||||
from PyQt5.QtGui import QRegExpValidator
|
from PyQt5.QtGui import QRegExpValidator
|
||||||
|
@ -338,7 +338,7 @@ def _crc16_checksum(bytes):
|
|||||||
return crc & 0xffff
|
return crc & 0xffff
|
||||||
|
|
||||||
|
|
||||||
### Client functions ###
|
# ====== Client functions ====== #
|
||||||
|
|
||||||
|
|
||||||
@expect(messages.StellarPublicKey, field="public_key")
|
@expect(messages.StellarPublicKey, field="public_key")
|
||||||
|
@ -59,7 +59,7 @@ class BridgeTransport(Transport):
|
|||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise TransportException('trezord: Could not enumerate devices' + get_error(r))
|
raise TransportException('trezord: Could not enumerate devices' + get_error(r))
|
||||||
return [BridgeTransport(dev) for dev in r.json()]
|
return [BridgeTransport(dev) for dev in r.json()]
|
||||||
except:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
@ -95,7 +95,7 @@ class UdpTransport(Transport):
|
|||||||
try:
|
try:
|
||||||
self.socket.sendall(b'PINGPING')
|
self.socket.sendall(b'PINGPING')
|
||||||
resp = self.socket.recv(8)
|
resp = self.socket.recv(8)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return resp == b'PONGPONG'
|
return resp == b'PONGPONG'
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class TxApi(object):
|
|||||||
try: # looking into cache first
|
try: # looking into cache first
|
||||||
j = json.load(open(cache_file), parse_float=str)
|
j = json.load(open(cache_file), parse_float=str)
|
||||||
return j
|
return j
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not self.url:
|
if not self.url:
|
||||||
@ -62,12 +62,12 @@ class TxApi(object):
|
|||||||
url = self.get_url(resource, resourceid)
|
url = self.get_url(resource, resourceid)
|
||||||
r = requests.get(url, headers={'User-agent': 'Mozilla/5.0'})
|
r = requests.get(url, headers={'User-agent': 'Mozilla/5.0'})
|
||||||
j = r.json(parse_float=str)
|
j = r.json(parse_float=str)
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError('URL error: %s' % url)
|
raise RuntimeError('URL error: %s' % url)
|
||||||
if cache_dir and cache_file:
|
if cache_dir and cache_file:
|
||||||
try: # saving into cache
|
try: # saving into cache
|
||||||
json.dump(j, open(cache_file, 'w'))
|
json.dump(j, open(cache_file, 'w'))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return j
|
return j
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user