diff --git a/robyn/__init__.py b/robyn/__init__.py index f642e9b01..ff760a150 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -55,18 +55,20 @@ def _add_route(self, route_type, endpoint, handler): def before_request(self, endpoint): """ - [The @app.before_request decorator to add a get route] + The @app.before_request decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ + return self.middleware_router.add_before_request(endpoint) def after_request(self, endpoint): """ - [The @app.after_request decorator to add a get route] + The @app.after_request decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ + return self.middleware_router.add_after_request(endpoint) def add_directory( @@ -96,10 +98,11 @@ def shutdown_handler(self, handler): def start(self, url="127.0.0.1", port=5000): """ - [Starts the server] + Starts the server - :param port [int]: [reperesents the port number at which the server is listening] + :param port int: reperesents the port number at which the server is listening """ + if not self.dev: workers = self.workers socket = SocketHeld(url, port) @@ -139,9 +142,9 @@ def start(self, url="127.0.0.1", port=5000): def get(self, endpoint): """ - [The @app.get decorator to add a get route] + The @app.get decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -151,9 +154,9 @@ def inner(handler): def post(self, endpoint): """ - [The @app.post decorator to add a get route] + The @app.post decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -163,11 +166,10 @@ def inner(handler): def put(self, endpoint): """ - [The @app.put decorator to add a get route] + The @app.put decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ - def inner(handler): self._add_route("PUT", endpoint, handler) @@ -175,9 +177,9 @@ def inner(handler): def delete(self, endpoint): """ - [The @app.delete decorator to add a get route] + The @app.delete decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -199,9 +201,9 @@ def inner(handler): def head(self, endpoint): """ - [The @app.head decorator to add a get route] + The @app.head decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -211,9 +213,9 @@ def inner(handler): def options(self, endpoint): """ - [The @app.options decorator to add a get route] + The @app.options decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -223,9 +225,9 @@ def inner(handler): def connect(self, endpoint): """ - [The @app.connect decorator to add a get route] + The @app.connect decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): @@ -235,9 +237,9 @@ def inner(handler): def trace(self, endpoint): """ - [The @app.trace decorator to add a get route] + The @app.trace decorator to add a get route - :param endpoint [str]: [endpoint to server the route] + :param endpoint str: endpoint to server the route """ def inner(handler): diff --git a/robyn/__init__.pyi b/robyn/__init__.pyi index 7522fd34b..73c140126 100644 --- a/robyn/__init__.pyi +++ b/robyn/__init__.pyi @@ -18,6 +18,7 @@ from .robyn import Server, SocketHeld from .router import MiddlewareRouter, Router, WebSocketRouter from .ws import WS + class Robyn: """This is the python wrapper for the Robyn binaries.""" @@ -28,16 +29,16 @@ class Robyn: :param endpoint str: endpoint to server the route """ - ... - def after_request(self, endpoint: str): # -> (handler: Unknown) -> None: - """ - [The @app.after_request decorator to add a get route] - :param endpoint [str]: [endpoint to server the route] + def after_request(self, endpoint: str) -> Callable[..., None]: """ + The @app.after_request decorator to add a get route + :param endpoint str: endpoint to server the route + """ ... + def add_directory( self, route: str, @@ -95,6 +96,7 @@ class Robyn: """ ... + def head(self, endpoint: str) -> Callable[..., None]: """ The @app.head decorator to add a get route diff --git a/robyn/dev_event_handler.py b/robyn/dev_event_handler.py index eadca5280..9524517f3 100644 --- a/robyn/dev_event_handler.py +++ b/robyn/dev_event_handler.py @@ -22,10 +22,11 @@ def start_server_first_time(self): def on_any_event(self, event): """ - [This function is a callback that will start a new server on every even change] + This function is a callback that will start a new server on every even change - :param event [FSEvent]: [a data structure with info about the events] + :param event FSEvent: a data structure with info about the events """ + if len(self.processes) > 0: for process in self.processes: process.terminate() diff --git a/robyn/dev_event_handler.pyi b/robyn/dev_event_handler.pyi index 88bcb567a..6414e801f 100644 --- a/robyn/dev_event_handler.pyi +++ b/robyn/dev_event_handler.pyi @@ -5,7 +5,7 @@ class EventHandler(FileSystemEventHandler): def start_server_first_time(self) -> None: ... def on_any_event(self, event: FileSystemEvent) -> None: """ - [This function is a callback that will start a new server on every even change] + This function is a callback that will start a new server on every even change - :param event [FSEvent]: [a data structure with info about the events] + :param event FSEvent: a data structure with info about the events """ diff --git a/robyn/processpool.py b/robyn/processpool.py index 4534eb80a..cd457226c 100644 --- a/robyn/processpool.py +++ b/robyn/processpool.py @@ -20,14 +20,15 @@ def spawn_process( :param directories tuple: the list of all the directories and related data in a tuple :param headers tuple: All the global headers in a tuple - :param routes tuple: The routes touple, containing the description about every route. - :param middlewares tuple: The middleware router touple, containing the description about every route. + :param routes Tuple[Route]: The routes touple, containing the description about every route. + :param middlewares Tuple[Route]: The middleware router touple, containing the description about every route. :param web_sockets list: This is a list of all the web socket routes :param event_handlers Dict: This is an event dict that contains the event handlers :param socket SocketHeld: This is the main tcp socket, which is being shared across multiple processes. :param process_name string: This is the name given to the process to identify the process :param workers number: This is the name given to the process to identify the process """ + # platform_name = platform.machine() if sys.platform.startswith("win32") or sys.platform.startswith("linux-cross"): loop = asyncio.new_event_loop() diff --git a/robyn/responses.py b/robyn/responses.py index 2202a76fa..0b3cbe58e 100644 --- a/robyn/responses.py +++ b/robyn/responses.py @@ -3,9 +3,9 @@ def static_file(file_path): """ - [This function will help in serving a static_file] + This function will help in serving a static_file - :param file_path [str]: [file path to serve as a response] + :param file_path str: file path to serve as a response """ return { @@ -19,9 +19,10 @@ def static_file(file_path): def jsonify(input_dict): """ - [This function serializes input dict to a json string] + This function serializes input dict to a json string - :param input_dict [dict]: [response of the function] + :param input_dict dict: response of the function """ + return json.dumps(input_dict) diff --git a/robyn/responses.pyi b/robyn/responses.pyi index 098a7f57f..fc7da4a99 100644 --- a/robyn/responses.pyi +++ b/robyn/responses.pyi @@ -2,18 +2,18 @@ from typing import Any def static_file(file_path: str) -> dict[str, Any]: """ - [This function will help in serving a static_file] + This function will help in serving a static_file - :param file_path [str]: [file path to serve as a response] + :param file_path str: file path to serve as a response """ pass def jsonify(input_dict: dict) -> str: """ - [This function serializes input dict to a json string] + This function serializes input dict to a json string - :param input_dict [dict]: [response of the function] + :param input_dict dict: response of the function """ pass