From c638bf91b2cb793a109b721cd714fef98a5538cb Mon Sep 17 00:00:00 2001 From: TheCommCraft Date: Tue, 11 Jun 2024 16:19:25 +0200 Subject: [PATCH] 2.10.2 --- scratchcommunication/__init__.py | 2 +- scratchcommunication/cloud.py | 1 - scratchcommunication/cloud_socket.py | 2 +- scratchcommunication/cloudrequests/requests.py | 14 ++++++++++---- setup.py | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/scratchcommunication/__init__.py b/scratchcommunication/__init__.py index 264f4e6..8602a5c 100644 --- a/scratchcommunication/__init__.py +++ b/scratchcommunication/__init__.py @@ -2,7 +2,7 @@ Module for communicating with scratch projects. """ -__version_number__ = '2.10.1' +__version_number__ = '2.10.2' from .session import * from .cloud import * diff --git a/scratchcommunication/cloud.py b/scratchcommunication/cloud.py index 49f7a31..7e39c21 100644 --- a/scratchcommunication/cloud.py +++ b/scratchcommunication/cloud.py @@ -9,7 +9,6 @@ from websocket import WebSocket, WebSocketConnectionClosedException, WebSocketTimeoutException NoneType = type(None) -CloudConnection = None class EventDispatcher(Protocol): def __call__(self, data : dict, **entries) -> None: diff --git a/scratchcommunication/cloud_socket.py b/scratchcommunication/cloud_socket.py index cb9b0c2..20cdf10 100644 --- a/scratchcommunication/cloud_socket.py +++ b/scratchcommunication/cloud_socket.py @@ -283,7 +283,7 @@ def __enter__(self): return self def __exit__(self, exc_type, exc_value, traceback): - pass + self.stop() @staticmethod def _decode(data : int) -> str: diff --git a/scratchcommunication/cloudrequests/requests.py b/scratchcommunication/cloudrequests/requests.py index 3506961..06adc56 100644 --- a/scratchcommunication/cloudrequests/requests.py +++ b/scratchcommunication/cloudrequests/requests.py @@ -27,11 +27,11 @@ def request(self, func : FunctionType = None, *, name : str = None, auto_convert Decorator for adding requests. """ if func: - func.__name__ = name or func.__name__ + func.__req_name__ = name or func.__name__ func.auto_convert = auto_convert func.allow_python_syntax = allow_python_syntax func.thread = thread - self.requests[func.__name__] = func + self.requests[func.__req_name__] = func return return lambda x : self.request(x, name=name, auto_convert=auto_convert, allow_python_syntax=allow_python_syntax) @@ -39,11 +39,11 @@ def add_request(self, func : FunctionType, *, name : str = None, auto_convert : """ Method for adding requests. """ - func.__name__ = name or func.__name__ + func.__req_name__ = name or func.__name__ func.auto_convert = auto_convert func.allow_python_syntax = allow_python_syntax func.thread = thread - self.requests[func.__name__] = func + self.requests[func.__req_name__] = func def start(self, *, thread : bool = None, daemon_thread : bool = False, duration : Union[float, int, None] = None): """ @@ -128,6 +128,12 @@ def stop(self): with self.cloud_socket.any_update: self.cloud_socket.any_update.notify_all() self.thread.join(5) + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.stop() KW = Parameter.KEYWORD_ONLY diff --git a/setup.py b/setup.py index eab98ab..0bb72a9 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ with open("README.md", encoding="utf-8") as f: long_description = f.read() -VERSION = '2.10.1' +VERSION = '2.10.2' setup( name='scratchcommunication',