diff --git a/sanic/asgi.py b/sanic/asgi.py index 742bda75..15b1c146 100644 --- a/sanic/asgi.py +++ b/sanic/asgi.py @@ -104,19 +104,23 @@ class Lifespan: if "before_server_start" in self.asgi_app.sanic_app.listeners: warnings.warn( - 'You have set a listener for "before_server_start" in ASGI mode. ' - 'It will be executed as early as possible, but not before ' - 'the ASGI server is started.' + 'You have set a listener for "before_server_start" ' + "in ASGI mode. " + "It will be executed as early as possible, but not before " + "the ASGI server is started." ) if "after_server_stop" in self.asgi_app.sanic_app.listeners: warnings.warn( - 'You have set a listener for "after_server_stop" in ASGI mode. ' - 'It will be executed as late as possible, but not after ' - 'the ASGI server is stopped.' + 'You have set a listener for "after_server_stop" ' + "in ASGI mode. " + "It will be executed as late as possible, but not after " + "the ASGI server is stopped." ) async def pre_startup(self) -> None: - for handler in self.asgi_app.sanic_app.listeners["before_server_start"]: + for handler in self.asgi_app.sanic_app.listeners[ + "before_server_start" + ]: response = handler( self.asgi_app.sanic_app, self.asgi_app.sanic_app.loop ) @@ -124,7 +128,9 @@ class Lifespan: await response async def startup(self) -> None: - for handler in self.asgi_app.sanic_app.listeners["before_server_start"]: + for handler in self.asgi_app.sanic_app.listeners[ + "before_server_start" + ]: response = handler( self.asgi_app.sanic_app, self.asgi_app.sanic_app.loop ) @@ -290,7 +296,9 @@ class ASGIApp: type(response), ) exception = ServerError("Invalid response type") - response = self.sanic_app.error_handler.response(self.request, exception) + response = self.sanic_app.error_handler.response( + self.request, exception + ) headers = [ (str(name).encode("latin-1"), str(value).encode("latin-1")) for name, value in response.headers.items() @@ -307,7 +315,10 @@ class ASGIApp: if response.cookies: cookies = SimpleCookie() cookies.load(response.cookies) - headers += [(b"set-cookie", cookie.encode("utf-8")) for name, cookie in response.cookies.items()] + headers += [ + (b"set-cookie", cookie.encode("utf-8")) + for name, cookie in response.cookies.items() + ] await self.transport.send( {