From 29f928e4f288084398436e0b3a4f899ccda577d6 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 10 Aug 2018 16:05:14 +0200 Subject: [PATCH] style: bare excepts, left-over bad imports --- tools/encfs_aes_getpass.py | 4 +--- tools/mem_flashblock.py | 1 - tools/rng_entropy_collector.py | 1 - trezorctl | 4 ++-- trezorlib/cosi.py | 4 ++-- trezorlib/ethereum.py | 2 +- trezorlib/firmware.py | 4 ++-- trezorlib/nem.py | 2 +- trezorlib/protocol_v1.py | 4 +--- trezorlib/protocol_v2.py | 8 +++----- trezorlib/qt/pinmatrix.py | 3 +-- trezorlib/stellar.py | 2 +- trezorlib/transport/bridge.py | 2 +- trezorlib/transport/udp.py | 2 +- trezorlib/tx_api.py | 6 +++--- 15 files changed, 20 insertions(+), 29 deletions(-) diff --git a/tools/encfs_aes_getpass.py b/tools/encfs_aes_getpass.py index 31a526f0d..56c8314e8 100755 --- a/tools/encfs_aes_getpass.py +++ b/tools/encfs_aes_getpass.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -from __future__ import print_function - ''' Use TREZOR as a hardware key for opening EncFS filesystem! @@ -62,7 +60,7 @@ def choose_device(devices): try: device_id = int(input()) return devices[device_id] - except: + except Exception: raise ValueError("Invalid choice, exiting...") diff --git a/tools/mem_flashblock.py b/tools/mem_flashblock.py index 6de4f7a8a..1df65dead 100755 --- a/tools/mem_flashblock.py +++ b/tools/mem_flashblock.py @@ -2,7 +2,6 @@ from trezorlib.debuglink import DebugLink from trezorlib.client import TrezorClient from trezorlib.transport import enumerate_devices -import binascii import sys sectoraddrs = [0x8000000, 0x8004000, 0x8008000, 0x800c000, diff --git a/tools/rng_entropy_collector.py b/tools/rng_entropy_collector.py index 1f4dcbcde..421ecd59c 100755 --- a/tools/rng_entropy_collector.py +++ b/tools/rng_entropy_collector.py @@ -4,7 +4,6 @@ # that has DEBUG_RNG == 1 as that will disable the user button # push confirmation -from __future__ import print_function import io import sys from trezorlib.client import TrezorClient diff --git a/trezorctl b/trezorctl index cb65ea328..c1c30d0bc 100755 --- a/trezorctl +++ b/trezorctl @@ -96,10 +96,10 @@ def cli(ctx, path, verbose, is_json): def get_device(): try: device = get_transport(path, prefix_search=False) - except: + except Exception: try: device = get_transport(path, prefix_search=True) - except: + except Exception: click.echo("Failed to find a TREZOR device.") if path is not None: click.echo("Using path: {}".format(path)) diff --git a/trezorlib/cosi.py b/trezorlib/cosi.py index e2a95f363..216f27517 100644 --- a/trezorlib/cosi.py +++ b/trezorlib/cosi.py @@ -21,7 +21,7 @@ from typing import Iterable, Tuple from . import messages 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. # Unsure if we want that. @@ -90,7 +90,7 @@ def sign_with_privkey(digest: bytes, privkey: Ed25519PrivateKey, return Ed25519Signature(_ed25519.encodeint(S)) -### Client functions ### +# ====== Client functions ====== # @expect(messages.CosiCommitment) diff --git a/trezorlib/ethereum.py b/trezorlib/ethereum.py index 41a147f71..fcf1d91b5 100644 --- a/trezorlib/ethereum.py +++ b/trezorlib/ethereum.py @@ -6,7 +6,7 @@ def int_to_big_endian(value): return value.to_bytes((value.bit_length() + 7) // 8, 'big') -### Client functions ### +# ====== Client functions ====== # @expect(proto.EthereumAddress, field="address") diff --git a/trezorlib/firmware.py b/trezorlib/firmware.py index 905c9bc88..779ca1408 100644 --- a/trezorlib/firmware.py +++ b/trezorlib/firmware.py @@ -130,12 +130,12 @@ def validate_firmware(filename): try: cosi.verify(header.signature, digest, global_pk) print("Signature OK") - except: + except Exception: print("Signature FAILED") raise -### Client functions ### +# ====== Client functions ====== # @tools.session diff --git a/trezorlib/nem.py b/trezorlib/nem.py index ee4ca1e44..c72e42182 100644 --- a/trezorlib/nem.py +++ b/trezorlib/nem.py @@ -167,7 +167,7 @@ def create_sign_tx(transaction): return msg -### Client functions ### +# ====== Client functions ====== # @expect(proto.NEMAddress, field="address") diff --git a/trezorlib/protocol_v1.py b/trezorlib/protocol_v1.py index 592f4f230..fe2cf796e 100644 --- a/trezorlib/protocol_v1.py +++ b/trezorlib/protocol_v1.py @@ -14,8 +14,6 @@ # You should have received a copy of the License along with this library. # If not, see . -from __future__ import absolute_import - from io import BytesIO import logging import struct @@ -79,7 +77,7 @@ class ProtocolV1: try: headerlen = struct.calcsize('>HL') msg_type, datalen = struct.unpack('>HL', chunk[3:3 + headerlen]) - except: + except Exception: raise RuntimeError('Cannot parse header') data = chunk[3 + headerlen:] diff --git a/trezorlib/protocol_v2.py b/trezorlib/protocol_v2.py index a9474ee21..97934767b 100644 --- a/trezorlib/protocol_v2.py +++ b/trezorlib/protocol_v2.py @@ -14,8 +14,6 @@ # You should have received a copy of the License along with this library. # If not, see . -from __future__ import absolute_import - from io import BytesIO import logging import struct @@ -110,7 +108,7 @@ class ProtocolV2: try: headerlen = struct.calcsize('>BLLL') magic, session, msg_type, datalen = struct.unpack('>BLLL', chunk[:headerlen]) - except: + except Exception: raise RuntimeError('Cannot parse header') if magic != 0x01: raise RuntimeError('Unexpected magic character') @@ -122,7 +120,7 @@ class ProtocolV2: try: headerlen = struct.calcsize('>BLL') magic, session, sequence = struct.unpack('>BLL', chunk[:headerlen]) - except: + except Exception: raise RuntimeError('Cannot parse header') if magic != 0x02: raise RuntimeError('Unexpected magic characters') @@ -134,7 +132,7 @@ class ProtocolV2: try: headerlen = struct.calcsize('>BL') magic, session = struct.unpack('>BL', chunk[:headerlen]) - except: + except Exception: raise RuntimeError('Cannot parse header') if magic != 0x03: raise RuntimeError('Unexpected magic character') diff --git a/trezorlib/qt/pinmatrix.py b/trezorlib/qt/pinmatrix.py index 3603b589d..e6850cf0c 100644 --- a/trezorlib/qt/pinmatrix.py +++ b/trezorlib/qt/pinmatrix.py @@ -14,7 +14,6 @@ # You should have received a copy of the License along with this library. # If not, see . -from __future__ import print_function import sys import math @@ -22,7 +21,7 @@ try: from PyQt4.QtGui import (QPushButton, QLineEdit, QSizePolicy, QRegExpValidator, QLabel, QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout) from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR -except: +except ImportError: from PyQt5.QtWidgets import (QPushButton, QLineEdit, QSizePolicy, QLabel, QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout) from PyQt5.QtGui import QRegExpValidator diff --git a/trezorlib/stellar.py b/trezorlib/stellar.py index 62e080313..803246d8b 100644 --- a/trezorlib/stellar.py +++ b/trezorlib/stellar.py @@ -338,7 +338,7 @@ def _crc16_checksum(bytes): return crc & 0xffff -### Client functions ### +# ====== Client functions ====== # @expect(messages.StellarPublicKey, field="public_key") diff --git a/trezorlib/transport/bridge.py b/trezorlib/transport/bridge.py index b225acc03..98c03647f 100644 --- a/trezorlib/transport/bridge.py +++ b/trezorlib/transport/bridge.py @@ -59,7 +59,7 @@ class BridgeTransport(Transport): if r.status_code != 200: raise TransportException('trezord: Could not enumerate devices' + get_error(r)) return [BridgeTransport(dev) for dev in r.json()] - except: + except Exception: return [] def open(self): diff --git a/trezorlib/transport/udp.py b/trezorlib/transport/udp.py index 25b4f8110..02a1fdda2 100644 --- a/trezorlib/transport/udp.py +++ b/trezorlib/transport/udp.py @@ -95,7 +95,7 @@ class UdpTransport(Transport): try: self.socket.sendall(b'PINGPING') resp = self.socket.recv(8) - except: + except Exception: pass return resp == b'PONGPONG' diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index f72ad63ab..c827c86ca 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -52,7 +52,7 @@ class TxApi(object): try: # looking into cache first j = json.load(open(cache_file), parse_float=str) return j - except: + except Exception: pass if not self.url: @@ -62,12 +62,12 @@ class TxApi(object): url = self.get_url(resource, resourceid) r = requests.get(url, headers={'User-agent': 'Mozilla/5.0'}) j = r.json(parse_float=str) - except: + except Exception: raise RuntimeError('URL error: %s' % url) if cache_dir and cache_file: try: # saving into cache json.dump(j, open(cache_file, 'w')) - except: + except Exception: pass return j