-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added logging module and removed prints exposed context add/remove to IPCMessenger added IPCMessenger to OT3API class
- Loading branch information
Showing
8 changed files
with
226 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
from typing import Callable, Any | ||
from asyncio import iscoroutine | ||
|
||
from jsonrpc.dispatcher import Dispatcher #type: ignore[import] | ||
|
||
from .errors import InvalidCoroutineFunction | ||
|
||
class JSONRPCDispatcher(Dispatcher): #type: ignore | ||
def __init__(self, *args: str, **kwargs: int ) -> None: | ||
def __init__(self, *args: str, context=None, **kwargs: int) -> None: | ||
"""Constructor""" | ||
super().__init__(*args, **kwargs) | ||
self._context = context | ||
super(JSONRPCDispatcher, self).__init__(*args, **kwargs) | ||
|
||
def is_valid(method: Callable[[Any], Any]) -> bool: | ||
"""Returns true if this method can be added.""" | ||
return True | ||
def add_method(self, *args, **kwargs) -> None: | ||
# reject non-async methods | ||
#if not iscoroutine(f): | ||
# raise InvalidCoroutineFunction(f.__name__) | ||
super(JSONRPCDispatcher, self).add_method(*args, **kwargs) | ||
|
||
ipc_dispatcher: JSONRPCDispatcher = JSONRPCDispatcher() | ||
ipc_dispatcher: JSONRPCDispatcher = Dispatcher() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Errors and exceptions.""" | ||
|
||
from jsonrpc.exceptions import JSONRPCError | ||
|
||
from typing import Optional | ||
|
||
|
||
class JSONRPCVersionNotSupported(JSONRPCError): | ||
""" json-rpc version is not supported error. """ | ||
|
||
CODE = -32605 | ||
MESSAGE = "Invalid json-rpc version." | ||
|
||
|
||
class BaseException(Exception): | ||
"""Base json-rpc exception object.""" | ||
def __init__( | ||
self, | ||
method_name: str, | ||
message: Optional[str] = None | ||
) -> None: | ||
"""Constructor.""" | ||
self._name = str | ||
self._message = message or '' | ||
|
||
def __repr__(self) -> str: | ||
"""String representation of this exception.""" | ||
return f"<{self.__class__.__name__}: method: {self._name} message: {self._message}>" | ||
|
||
|
||
class InvalidCoroutineFunction(BaseException): | ||
"""Error raised when the function being added to the dispatcher is not async.""" | ||
def __init__(self, method) -> None: | ||
super().__init__(method, message="Method is not async") | ||
|
||
|
||
class contextAlreadyRegisteredException(BaseException): | ||
"""Error raised when try to register an already registered context.""" | ||
def __init__(self, method) -> None: | ||
super().__init__(method, message="Context arg already registered") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.