Skip to content

Commit

Permalink
2.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCommCraft committed Apr 26, 2024
1 parent f9ce526 commit 13cd721
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion scratchcommunication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module for communicating with scratch projects.
"""

__version_number__ = '2.5.2'
__version_number__ = '2.6.1'

from .session import *
from .cloud import *
Expand Down
2 changes: 1 addition & 1 deletion scratchcommunication/cloudrequests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Module for communicating with the scratch project.
"""

from .requests import RequestHandler
from .requests import RequestHandler, ErrorMessage
22 changes: 17 additions & 5 deletions scratchcommunication/cloudrequests/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ def start(self, *, thread : bool = None, daemon_thread : bool = False, duration
name, args, kwargs = parse_normal_request(raw_req, req_name)
else:
raise PermissionError("Python syntax is not allowed for this.")
except Exception:
response = "The command syntax was wrong."
warnings.warn("Received a request with an invalid syntax.", RuntimeWarning)
else:
try:
self.execute_request(name, args=args, kwargs=kwargs, client=client)
response = None
except Exception:
response = "There was an error."
warnings.warn("Received a request with an invalid syntax.", SyntaxWarning)
except Exception:
response = "Something went wrong."
warnings.warn("Something went wrong with a request.", RuntimeWarning)
if response:
client.send(response)
except Exception:
Expand Down Expand Up @@ -116,7 +121,11 @@ def execute_request(self, name, *, args : Sequence[Any], kwargs : Mapping[str, A
if inspect.signature(request_handling_function).return_annotation != inspect.Signature.empty:
return_converter = inspect.signature(request_handling_function).return_annotation
def respond():
client.send(str(return_converter(request_handling_function(*args, **kwargs))))
try:
response = str(return_converter(request_handling_function(*args, **kwargs)))
except ErrorMessage as e:
response = " ".join(e.args)
client.send(response)
if request_handling_function.thread:
thread = StoppableThread(target=respond)
thread.start()
Expand Down Expand Up @@ -211,7 +220,10 @@ def parse_normal_request(msg : str, name : str):
return name, args, {}



class ErrorMessage(Exception):
"""
Error with a message
"""



Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with open("README.md", encoding="utf-8") as f:
long_description = f.read()

VERSION = '2.5.2'
VERSION = '2.6.1'

setup(
name='scratchcommunication',
Expand Down

0 comments on commit 13cd721

Please sign in to comment.