Skip to content

Commit

Permalink
refactor: exception names and uses
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 17, 2022
1 parent 7fea82c commit 5cb4de4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/rpcclient/rpcclient/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}')
Expand Down
4 changes: 2 additions & 2 deletions src/rpcclient/rpcclient/darwin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/rpcclient/rpcclient/darwin/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/rpcclient/rpcclient/darwin/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions src/rpcclient/rpcclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class RpcClientException(Exception):
pass


class InvalidServerVersionMagic(RpcClientException):
class InvalidServerVersionMagicError(RpcClientException):
pass


Expand All @@ -22,7 +22,7 @@ class BadReturnValueError(RpcClientException):
pass


class NoSuchPreference(RpcClientException):
class NoSuchPreferenceError(RpcClientException):
pass


Expand All @@ -42,7 +42,7 @@ class FailedToConnectError(RpcClientException):
pass


class UnrecognizedSelector(RpcClientException):
class UnrecognizedSelectorError(RpcClientException):
pass


Expand Down

0 comments on commit 5cb4de4

Please sign in to comment.