fix style complaints

This commit is contained in:
matejcik
2018-12-10 16:30:56 +01:00
parent 2cb64991c3
commit 5cfdc7734b
3 changed files with 20 additions and 5 deletions

View File

@@ -114,6 +114,11 @@ class Device:
raise NotImplementedError() raise NotImplementedError()
def close(self): def close(self):
"""Close connection to device.
By default, close the underlying connection. Overriding classes
can perform their own cleanup.
"""
self.conn.close() self.conn.close()
def __enter__(self): def __enter__(self):

View File

@@ -1,6 +1,6 @@
"""TREZOR-related definitions.""" """TREZOR-related definitions."""
# pylint: disable=unused-import,import-error # pylint: disable=unused-import,import-error,no-name-in-module,no-member
import os import os
import logging import logging
@@ -21,8 +21,8 @@ if semver.match(trezorlib.__version__, ">=0.11.0"):
from trezorlib.misc import sign_identity, get_ecdh_session_key from trezorlib.misc import sign_identity, get_ecdh_session_key
else: else:
from trezorlib.client import (TrezorClient, CallException as TrezorFailure, from trezorlib.client import (TrezorClient, PinException,
PinException) CallException as TrezorFailure)
from trezorlib.messages import IdentityType from trezorlib.messages import IdentityType
from trezorlib import messages from trezorlib import messages
from trezorlib.transport import get_transport from trezorlib.transport import get_transport
@@ -32,11 +32,19 @@ else:
get_ecdh_session_key = TrezorClient.get_ecdh_session_key get_ecdh_session_key = TrezorClient.get_ecdh_session_key
class Client(TrezorClient): class Client(TrezorClient):
"""Compatibility wrapper for older TrezorClient type.
This class redirects callback_* style methods to the UI implementation,
and stores state so that we can reuse it.
"""
def __init__(self, transport, ui, state=None): def __init__(self, transport, ui, state=None):
"""C-tor."""
super().__init__(transport, state=state) super().__init__(transport, state=state)
self.ui = ui self.ui = ui
def callback_PinMatrixRequest(self, msg): def callback_PinMatrixRequest(self, msg):
"""Redirect PinMatrixRequest to UI."""
try: try:
pin = self.ui.get_pin(msg.type) pin = self.ui.get_pin(msg.type)
if not pin.isdigit(): if not pin.isdigit():
@@ -48,6 +56,7 @@ else:
raise raise
def callback_PassphraseRequest(self, msg): def callback_PassphraseRequest(self, msg):
"""Redirect PassphraseRequest to UI."""
try: try:
if msg.on_device is True: if msg.on_device is True:
return messages.PassphraseAck() return messages.PassphraseAck()
@@ -66,7 +75,8 @@ else:
raise raise
def callback_PassphraseStateRequest(self, msg): def callback_PassphraseStateRequest(self, msg):
self.state = msg.state """Store state provided by device so that we can reuse it later."""
self.state = msg.state # pylint: disable=attribute-defined-outside-init
return messages.PassphraseStateAck() return messages.PassphraseStateAck()

View File

@@ -49,8 +49,8 @@ class UI:
options=self.options_getter()) options=self.options_getter())
def button_request(self, _code=None): def button_request(self, _code=None):
"""Called by TrezorClient when device interaction is required."""
# XXX: show notification to the user? # XXX: show notification to the user?
pass
def create_default_options_getter(): def create_default_options_getter():