From d219578d439be84810ee58cef6a8777ae1f12d8c Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Tue, 19 Nov 2024 17:50:17 +0100 Subject: [PATCH] refactor(python): rename NewTrezorConnection to TrezorConnection [no changelog] --- python/src/trezorlib/cli/__init__.py | 8 ++++---- python/src/trezorlib/cli/debug.py | 6 +++--- python/src/trezorlib/cli/device.py | 4 ++-- python/src/trezorlib/cli/firmware.py | 8 ++++---- python/src/trezorlib/cli/trezorctl.py | 10 +++++----- python/src/trezorlib/transport/thp/channel_database.py | 4 ++-- tests/click_tests/record_layout.py | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/python/src/trezorlib/cli/__init__.py b/python/src/trezorlib/cli/__init__.py index 951d0f4a5b..b27a323328 100644 --- a/python/src/trezorlib/cli/__init__.py +++ b/python/src/trezorlib/cli/__init__.py @@ -101,7 +101,7 @@ def get_passphrase( raise exceptions.Cancelled from None -class NewTrezorConnection: +class TrezorConnection: def __init__( self, @@ -297,7 +297,7 @@ def with_session( @click.pass_obj @functools.wraps(func) def function_with_session( - obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs" + obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs" ) -> "R": session = obj.get_session(derive_cardano) try: @@ -316,7 +316,7 @@ def with_management_session( @click.pass_obj @functools.wraps(func) def function_with_management_session( - obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs" + obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs" ) -> "R": session = obj.get_management_session() try: @@ -341,7 +341,7 @@ def with_client( @click.pass_obj @functools.wraps(func) def trezorctl_command_with_client( - obj: NewTrezorConnection, *args: "P.args", **kwargs: "P.kwargs" + obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs" ) -> "R": with obj.client_context() as client: # session_was_resumed = obj.session_id == client.session_id diff --git a/python/src/trezorlib/cli/debug.py b/python/src/trezorlib/cli/debug.py index a0db79a52f..eaeb003af7 100644 --- a/python/src/trezorlib/cli/debug.py +++ b/python/src/trezorlib/cli/debug.py @@ -26,7 +26,7 @@ from ..transport.session import Session from . import with_management_session if TYPE_CHECKING: - from . import NewTrezorConnection + from . import TrezorConnection @click.group(name="debug") @@ -85,7 +85,7 @@ def cli() -> None: @click.argument("directory", required=False) @click.option("-s", "--stop", is_flag=True, help="Stop the recording") @click.pass_obj -def record(obj: "NewTrezorConnection", directory: Union[str, None], stop: bool) -> None: +def record(obj: "TrezorConnection", directory: Union[str, None], stop: bool) -> None: """Record screen changes into a specified directory. Recording can be stopped with `-s / --stop` option. @@ -94,7 +94,7 @@ def record(obj: "NewTrezorConnection", directory: Union[str, None], stop: bool) def record_screen_from_connection( - obj: "NewTrezorConnection", directory: Union[str, None] + obj: "TrezorConnection", directory: Union[str, None] ) -> None: """Record screen helper to transform TrezorConnection into TrezorClientDebugLink.""" transport = obj.get_transport() diff --git a/python/src/trezorlib/cli/device.py b/python/src/trezorlib/cli/device.py index 257133b911..2e7d166046 100644 --- a/python/src/trezorlib/cli/device.py +++ b/python/src/trezorlib/cli/device.py @@ -29,7 +29,7 @@ from . import ChoiceType, with_management_session if t.TYPE_CHECKING: from ..protobuf import MessageType from ..transport.session import Session - from . import NewTrezorConnection + from . import TrezorConnection RECOVERY_DEVICE_INPUT_METHOD = { "scrambled": messages.RecoveryDeviceInputMethod.ScrambledWords, @@ -315,7 +315,7 @@ def sd_protect(session: "Session", operation: messages.SdProtectOperationType) - @cli.command() @click.pass_obj -def reboot_to_bootloader(obj: "NewTrezorConnection") -> str: +def reboot_to_bootloader(obj: "TrezorConnection") -> str: """Reboot device into bootloader mode. Currently only supported on Trezor Model One. diff --git a/python/src/trezorlib/cli/firmware.py b/python/src/trezorlib/cli/firmware.py index 73449f380b..26b0ac3172 100644 --- a/python/src/trezorlib/cli/firmware.py +++ b/python/src/trezorlib/cli/firmware.py @@ -42,7 +42,7 @@ from . import ChoiceType, with_management_session if TYPE_CHECKING: from ..client import TrezorClient from ..transport.session import Session - from . import NewTrezorConnection + from . import TrezorConnection MODEL_CHOICE = ChoiceType( { @@ -521,7 +521,7 @@ def cli() -> None: @click.pass_obj # fmt: on def verify( - obj: "NewTrezorConnection", + obj: "TrezorConnection", filename: BinaryIO, check_device: bool, fingerprint: Optional[str], @@ -566,7 +566,7 @@ def verify( @click.pass_obj # fmt: on def download( - obj: "NewTrezorConnection", + obj: "TrezorConnection", output: Optional[BinaryIO], model: Optional[TrezorModel], version: Optional[str], @@ -632,7 +632,7 @@ def download( # fmt: on @click.pass_obj def update( - obj: "NewTrezorConnection", + obj: "TrezorConnection", filename: Optional[BinaryIO], url: Optional[str], version: Optional[str], diff --git a/python/src/trezorlib/cli/trezorctl.py b/python/src/trezorlib/cli/trezorctl.py index 2ecdacd30d..a45406f5cd 100755 --- a/python/src/trezorlib/cli/trezorctl.py +++ b/python/src/trezorlib/cli/trezorctl.py @@ -32,7 +32,7 @@ from ..transport.thp import channel_database from ..transport.udp import UdpTransport from . import ( AliasedGroup, - NewTrezorConnection, + TrezorConnection, benchmark, binance, btc, @@ -218,7 +218,7 @@ def cli_main( raise click.ClickException(f"Not a valid session id: {session_id}") # ctx.obj = TrezorConnection(path, bytes_session_id, passphrase_on_host, script) - ctx.obj = NewTrezorConnection(path, bytes_session_id, passphrase_on_host, script) + ctx.obj = TrezorConnection(path, bytes_session_id, passphrase_on_host, script) # Optionally record the screen into a specified directory. if record: @@ -259,7 +259,7 @@ def print_result(res: Any, is_json: bool, script: bool, **kwargs: Any) -> None: @cli.set_result_callback() @click.pass_obj -def stop_recording_action(obj: NewTrezorConnection, *args: Any, **kwargs: Any) -> None: +def stop_recording_action(obj: TrezorConnection, *args: Any, **kwargs: Any) -> None: """Stop recording screen changes when the recording was started by `cli_main`. (When user used the `-r / --record` option of `trezorctl` command.) @@ -346,7 +346,7 @@ def ping(session: "Session", message: str, button_protection: bool) -> str: @cli.command() @click.pass_obj def get_session( - obj: NewTrezorConnection, passphrase: str = "", derive_cardano: bool = False + obj: TrezorConnection, passphrase: str = "", derive_cardano: bool = False ) -> str: """Get a session ID for subsequent commands. @@ -414,7 +414,7 @@ def usb_reset() -> None: @cli.command() @click.option("-t", "--timeout", type=float, default=10, help="Timeout in seconds") @click.pass_obj -def wait_for_emulator(obj: NewTrezorConnection, timeout: float) -> None: +def wait_for_emulator(obj: TrezorConnection, timeout: float) -> None: """Wait until Trezor Emulator comes up. Tries to connect to emulator and returns when it succeeds. diff --git a/python/src/trezorlib/transport/thp/channel_database.py b/python/src/trezorlib/transport/thp/channel_database.py index ce4385b5a3..e096b06ddc 100644 --- a/python/src/trezorlib/transport/thp/channel_database.py +++ b/python/src/trezorlib/transport/thp/channel_database.py @@ -8,8 +8,8 @@ from .protocol_and_channel import ProtocolAndChannel LOG = logging.getLogger(__name__) -if False: - from appdirs import user_cache_dir, user_config_dir +if True: + from platformdirs import user_cache_dir, user_config_dir APP_NAME = "@trezor" # TODO DATA_PATH = os.path.join(user_cache_dir(appname=APP_NAME), "channel_data.json") diff --git a/tests/click_tests/record_layout.py b/tests/click_tests/record_layout.py index d93391912c..71a590e797 100644 --- a/tests/click_tests/record_layout.py +++ b/tests/click_tests/record_layout.py @@ -63,7 +63,7 @@ MODULES = ( CALLS_DONE = [] DEBUGLINK = None -get_client_orig = cli.NewTrezorConnection.get_client +get_client_orig = cli.TrezorConnection.get_client def get_client(conn): @@ -75,7 +75,7 @@ def get_client(conn): return client -cli.NewTrezorConnection.get_client = get_client +cli.TrezorConnection.get_client = get_client def scan_layouts(dest):