Skip to content

Commit

Permalink
Merge pull request #128 from doronz88/refactor/allocated_reprs
Browse files Browse the repository at this point in the history
allocated: add `__repr__` to all inherited classes
  • Loading branch information
doronz88 authored Apr 1, 2022
2 parents 653d35d + 19b4c70 commit 257afb2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/darwin/ioregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _deallocate(self):
self._client.symbols.IOObjectRelease(self._service)

def __repr__(self):
return f'<IOService NAME:{self.name}>'
return f'<{self.__class__.__name__} NAME:{self.name}>'


class BacklightControlService(IOService):
Expand Down
8 changes: 6 additions & 2 deletions src/rpcclient/rpcclient/darwin/scpreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@


class SCPreference(Allocated):
def __init__(self, client, ref):
def __init__(self, client, preferences_id: str, ref):
super().__init__()
self._client = client
self._ref = ref
self._preferences_id = preferences_id

@property
def keys(self) -> typing.List[str]:
Expand Down Expand Up @@ -82,6 +83,9 @@ def _commit(self):
raise RpcClientException('SCPreferencesCommitChanges failed')
self._client.symbols.SCPreferencesSynchronize(self._ref)

def __repr__(self):
return f'<{self.__class__.__name__} NAME:{self._preferences_id}>'


class SCPreferences:
"""
Expand All @@ -100,7 +104,7 @@ def open(self, preferences_id: str) -> SCPreference:
ref = self._client.symbols.SCPreferencesCreate(0, self._client.cf('rpcserver'), self._client.cf(preferences_id))
if not ref:
raise RpcClientException(f'SCPreferencesCreate failed for: {preferences_id}')
return SCPreference(self._client, ref)
return SCPreference(self._client, preferences_id, ref)

def get_keys(self, preferences_id: str) -> typing.List[str]:
""" get all keys from given preferences_id """
Expand Down
6 changes: 6 additions & 0 deletions src/rpcclient/rpcclient/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def __init__(self, path, dirp, client):
def __iter__(self) -> Iterator[DirEntry]:
raise NotImplementedError()

def __repr__(self):
return f'<{self.__class__.__name__} PATH:{self.path} DIRP:{self._dirp}>'


class File(Allocated):
CHUNK_SIZE = 1024
Expand Down Expand Up @@ -151,6 +154,9 @@ def readall(self, chunk_size: int = CHUNK_SIZE) -> bytes:
buf += chunk.peek(err)
return buf

def __repr__(self):
return f'<{self.__class__.__name__} FD:{self.fd}>'


class Fs:
""" filesystem utils """
Expand Down
3 changes: 3 additions & 0 deletions src/rpcclient/rpcclient/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def recvall(self, size: int) -> bytes:
buf += chunk.peek(err)
return buf

def __repr__(self):
return f'<{self.__class__.__name__} FD:{self.fd}>'


class Network:
def __init__(self, client):
Expand Down

0 comments on commit 257afb2

Please sign in to comment.