From 5cb4de4ee7254240484087e9cab114d2ae6edd75 Mon Sep 17 00:00:00 2001 From: DoronZ Date: Fri, 18 Feb 2022 01:06:18 +0200 Subject: [PATCH] refactor: exception names and uses --- src/rpcclient/rpcclient/client_factory.py | 4 ++-- src/rpcclient/rpcclient/darwin/client.py | 4 ++-- src/rpcclient/rpcclient/darwin/media.py | 4 ++-- src/rpcclient/rpcclient/darwin/symbol.py | 4 ++-- src/rpcclient/rpcclient/exceptions.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/rpcclient/rpcclient/client_factory.py b/src/rpcclient/rpcclient/client_factory.py index f1116350..dd1b8afe 100644 --- a/src/rpcclient/rpcclient/client_factory.py +++ b/src/rpcclient/rpcclient/client_factory.py @@ -5,7 +5,7 @@ from rpcclient.darwin.client import DarwinClient from rpcclient.ios.client import IosClient from rpcclient.linux.client import LinuxClient -from rpcclient.exceptions import FailedToConnectError, InvalidServerVersionMagic +from rpcclient.exceptions import FailedToConnectError, InvalidServerVersionMagicError from rpcclient.macos.client import MacosClient from rpcclient.protocol import UNAME_VERSION_LEN, DEFAULT_PORT, SERVER_MAGIC_VERSION @@ -31,7 +31,7 @@ def create_client(hostname: str, port: int = DEFAULT_PORT): magic = recvall(sock, len(SERVER_MAGIC_VERSION)) if magic != SERVER_MAGIC_VERSION: - raise InvalidServerVersionMagic(f'got an invalid server magic: {magic.hex()}') + raise InvalidServerVersionMagicError(f'got an invalid server magic: {magic.hex()}') sysname = recvall(sock, UNAME_VERSION_LEN).split(b'\x00', 1)[0].decode().lower() logging.info(f'connection uname.sysname: {sysname}') diff --git a/src/rpcclient/rpcclient/darwin/client.py b/src/rpcclient/rpcclient/darwin/client.py index 38d9e9e6..0ce1be83 100644 --- a/src/rpcclient/rpcclient/darwin/client.py +++ b/src/rpcclient/rpcclient/darwin/client.py @@ -18,7 +18,7 @@ from rpcclient.darwin.processes import DarwinProcesses from rpcclient.darwin.structs import utsname from rpcclient.darwin.symbol import DarwinSymbol -from rpcclient.exceptions import RpcClientException +from rpcclient.exceptions import RpcClientException, MissingLibraryError IsaMagic = namedtuple('IsaMagic', 'mask value') ISA_MAGICS = [ @@ -38,7 +38,7 @@ def __init__(self, sock, sysname: str, hostname: str, port: int = None): self._dlsym_global_handle = -2 # RTLD_GLOBAL if 0 == self.dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", 2): - raise RpcClientException('failed to load CoreFoundation') + raise MissingLibraryError('failed to load CoreFoundation') self._cf_types = { self.symbols.CFDateGetTypeID(): 'date', diff --git a/src/rpcclient/rpcclient/darwin/media.py b/src/rpcclient/rpcclient/darwin/media.py index e10dd42b..9f224657 100644 --- a/src/rpcclient/rpcclient/darwin/media.py +++ b/src/rpcclient/rpcclient/darwin/media.py @@ -2,8 +2,8 @@ from rpcclient.common import path_to_str from rpcclient.darwin.consts import AVAudioSessionCategoryOptionDefaultToSpeaker -from rpcclient.exceptions import RpcClientException, BadReturnValueError from rpcclient.darwin.symbol import DarwinSymbol +from rpcclient.exceptions import BadReturnValueError, MissingLibraryError class Recorder: @@ -123,7 +123,7 @@ def _load_av_foundation(self): for option in options: if self._client.dlopen(option, 2): return - raise RpcClientException('failed to load AVFAudio') + raise MissingLibraryError('failed to load AVFAudio') @path_to_str('filename') def get_recorder(self, filename: str) -> Recorder: diff --git a/src/rpcclient/rpcclient/darwin/symbol.py b/src/rpcclient/rpcclient/darwin/symbol.py index d42e3959..15720d00 100644 --- a/src/rpcclient/rpcclient/darwin/symbol.py +++ b/src/rpcclient/rpcclient/darwin/symbol.py @@ -3,7 +3,7 @@ from typing import List, Mapping from rpcclient.darwin.consts import kCFNumberSInt64Type, kCFNumberDoubleType -from rpcclient.exceptions import CfSerializationError, UnrecognizedSelector +from rpcclient.exceptions import CfSerializationError, UnrecognizedSelectorError from rpcclient.symbol import Symbol @@ -12,7 +12,7 @@ def objc_call(self, selector, *params): """ call an objc method on a given object """ sel = self._client.symbols.sel_getUid(selector) if not self._client.symbols.objc_msgSend(self, self._client.symbols.sel_getUid("respondsToSelector:"), sel): - raise UnrecognizedSelector(f"unrecognized selector '{selector}' sent to class") + raise UnrecognizedSelectorError(f"unrecognized selector '{selector}' sent to class") return self._client.symbols.objc_msgSend(self, sel, *params) diff --git a/src/rpcclient/rpcclient/exceptions.py b/src/rpcclient/rpcclient/exceptions.py index 05067ee4..407d7c87 100644 --- a/src/rpcclient/rpcclient/exceptions.py +++ b/src/rpcclient/rpcclient/exceptions.py @@ -2,7 +2,7 @@ class RpcClientException(Exception): pass -class InvalidServerVersionMagic(RpcClientException): +class InvalidServerVersionMagicError(RpcClientException): pass @@ -22,7 +22,7 @@ class BadReturnValueError(RpcClientException): pass -class NoSuchPreference(RpcClientException): +class NoSuchPreferenceError(RpcClientException): pass @@ -42,7 +42,7 @@ class FailedToConnectError(RpcClientException): pass -class UnrecognizedSelector(RpcClientException): +class UnrecognizedSelectorError(RpcClientException): pass