From 140d27ef96371c5564afef646dc76a440b375d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Wed, 25 Oct 2023 00:22:00 +0100 Subject: [PATCH] ruff format --- examples/amending_request_object.py | 1 + examples/http_redirect.py | 1 + examples/run_async_advanced.py | 1 + sanic/headers.py | 3 +-- sanic/mixins/exceptions.py | 2 +- sanic/mixins/middleware.py | 6 +++--- sanic/models/server_types.py | 8 ++------ sanic/server/websockets/frame.py | 4 +--- tests/test_cancellederror.py | 1 - tests/test_headers.py | 2 +- 10 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/amending_request_object.py b/examples/amending_request_object.py index 63f8d1d5..3c5bb59d 100644 --- a/examples/amending_request_object.py +++ b/examples/amending_request_object.py @@ -25,5 +25,6 @@ def key_exist_handler(request): return text("num does not exist in request") + if __name__ == "__main__": app.run(host="0.0.0.0", port=8000, debug=True) diff --git a/examples/http_redirect.py b/examples/http_redirect.py index 34dc43ab..2a8c69c5 100644 --- a/examples/http_redirect.py +++ b/examples/http_redirect.py @@ -69,5 +69,6 @@ async def runner(app: Sanic, app_server: AsyncioServer): app.is_running = False app.is_stopping = True + if __name__ == "__main__": https.run(port=HTTPS_PORT, debug=True) diff --git a/examples/run_async_advanced.py b/examples/run_async_advanced.py index c782d49a..917beefa 100644 --- a/examples/run_async_advanced.py +++ b/examples/run_async_advanced.py @@ -35,6 +35,7 @@ async def after_server_stop(app, loop): async def test(request): return response.json({"answer": "42"}) + if __name__ == "__main__": asyncio.set_event_loop(uvloop.new_event_loop()) serv_coro = app.create_server( diff --git a/sanic/headers.py b/sanic/headers.py index 5a7e1664..123755a5 100644 --- a/sanic/headers.py +++ b/sanic/headers.py @@ -349,8 +349,7 @@ def parse_content_header(value: str) -> Tuple[str, Options]: options: Dict[str, Union[int, str]] = {} else: options = { - m.group(1) - .lower(): (m.group(2) or m.group(3)) + m.group(1).lower(): (m.group(2) or m.group(3)) .replace("%22", '"') .replace("%0D%0A", "\n") for m in _param.finditer(value[pos:]) diff --git a/sanic/mixins/exceptions.py b/sanic/mixins/exceptions.py index e52efb56..0f290a98 100644 --- a/sanic/mixins/exceptions.py +++ b/sanic/mixins/exceptions.py @@ -14,7 +14,7 @@ class ExceptionMixin(metaclass=SanicMeta): def exception( self, *exceptions: Union[Type[Exception], List[Type[Exception]]], - apply: bool = True + apply: bool = True, ) -> Callable: """Decorator used to register an exception handler for the current application or blueprint instance. diff --git a/sanic/mixins/middleware.py b/sanic/mixins/middleware.py index 358c1b8d..89179af8 100644 --- a/sanic/mixins/middleware.py +++ b/sanic/mixins/middleware.py @@ -25,7 +25,7 @@ class MiddlewareMixin(metaclass=SanicMeta): attach_to: str = "request", apply: bool = True, *, - priority: int = 0 + priority: int = 0, ) -> MiddlewareType: ... @@ -36,7 +36,7 @@ class MiddlewareMixin(metaclass=SanicMeta): attach_to: str = "request", apply: bool = True, *, - priority: int = 0 + priority: int = 0, ) -> Callable[[MiddlewareType], MiddlewareType]: ... @@ -46,7 +46,7 @@ class MiddlewareMixin(metaclass=SanicMeta): attach_to: str = "request", apply: bool = True, *, - priority: int = 0 + priority: int = 0, ) -> Union[MiddlewareType, Callable[[MiddlewareType], MiddlewareType]]: """Decorator for registering middleware. diff --git a/sanic/models/server_types.py b/sanic/models/server_types.py index fe9d3d1f..5656f85f 100644 --- a/sanic/models/server_types.py +++ b/sanic/models/server_types.py @@ -44,12 +44,8 @@ class ConnInfo: self.server_name = "" self.cert: Dict[str, Any] = {} self.network_paths: List[Any] = [] - sslobj: Optional[SSLObject] = transport.get_extra_info( - "ssl_object" - ) # type: ignore - sslctx: Optional[SSLContext] = transport.get_extra_info( - "ssl_context" - ) # type: ignore + sslobj: Optional[SSLObject] = transport.get_extra_info("ssl_object") # type: ignore + sslctx: Optional[SSLContext] = transport.get_extra_info("ssl_context") # type: ignore if sslobj: self.ssl = True self.server_name = getattr(sslobj, "sanic_server_name", None) or "" diff --git a/sanic/server/websockets/frame.py b/sanic/server/websockets/frame.py index dacc187c..cb63b7c3 100644 --- a/sanic/server/websockets/frame.py +++ b/sanic/server/websockets/frame.py @@ -57,9 +57,7 @@ class WebsocketFrameAssembler: self.read_mutex = asyncio.Lock() self.write_mutex = asyncio.Lock() - self.completed_queue = asyncio.Queue( - maxsize=1 - ) # type: asyncio.Queue[Data] + self.completed_queue = asyncio.Queue(maxsize=1) # type: asyncio.Queue[Data] # put() sets this event to tell get() that a message can be fetched. self.message_complete = asyncio.Event() diff --git a/tests/test_cancellederror.py b/tests/test_cancellederror.py index 7c741065..552747ff 100644 --- a/tests/test_cancellederror.py +++ b/tests/test_cancellederror.py @@ -1,4 +1,3 @@ - from asyncio import CancelledError diff --git a/tests/test_headers.py b/tests/test_headers.py index fbf13d25..3c07a98f 100644 --- a/tests/test_headers.py +++ b/tests/test_headers.py @@ -57,7 +57,7 @@ def raised_ceiling(): # Chrome, Firefox: # Content-Disposition: form-data; name="foo%22;bar\"; filename="😀" 'form-data; name="foo%22;bar\\"; filename="😀"', - ("form-data", {"name": 'foo";bar\\', "filename": "😀"}) + ("form-data", {"name": 'foo";bar\\', "filename": "😀"}), # cgi: ('form-data', {'name': 'foo%22;bar"; filename="😀'}) # werkzeug (pre 2.3.0): ('form-data', {'name': 'foo%22;bar"; filename='}) ),