Resolve tests
This commit is contained in:
parent
9e23e75fb4
commit
209579f280
13
sanic/app.py
13
sanic/app.py
|
@ -59,7 +59,6 @@ from sanic.server import (
|
||||||
Signal,
|
Signal,
|
||||||
serve,
|
serve,
|
||||||
serve_multiple,
|
serve_multiple,
|
||||||
trigger_events,
|
|
||||||
)
|
)
|
||||||
from sanic.websocket import ConnectionClosed, WebSocketProtocol
|
from sanic.websocket import ConnectionClosed, WebSocketProtocol
|
||||||
|
|
||||||
|
@ -908,7 +907,7 @@ class Sanic(BaseSanic):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Trigger before_start events
|
# Trigger before_start events
|
||||||
await trigger_events(
|
await self.trigger_events(
|
||||||
server_settings.get("before_start", []),
|
server_settings.get("before_start", []),
|
||||||
server_settings.get("loop"),
|
server_settings.get("loop"),
|
||||||
)
|
)
|
||||||
|
@ -917,6 +916,16 @@ class Sanic(BaseSanic):
|
||||||
asyncio_server_kwargs=asyncio_server_kwargs, **server_settings
|
asyncio_server_kwargs=asyncio_server_kwargs, **server_settings
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def trigger_events(self, events, loop):
|
||||||
|
"""Trigger events (functions or async)
|
||||||
|
:param events: one or more sync or async functions to execute
|
||||||
|
:param loop: event loop
|
||||||
|
"""
|
||||||
|
for event in events:
|
||||||
|
result = event(loop)
|
||||||
|
if isawaitable(result):
|
||||||
|
await result
|
||||||
|
|
||||||
async def _run_request_middleware(self, request, request_name=None):
|
async def _run_request_middleware(self, request, request_name=None):
|
||||||
# The if improves speed. I don't know why
|
# The if improves speed. I don't know why
|
||||||
named_middleware = self.named_request_middleware.get(
|
named_middleware = self.named_request_middleware.get(
|
||||||
|
|
|
@ -147,7 +147,7 @@ class Request:
|
||||||
] = defaultdict(list)
|
] = defaultdict(list)
|
||||||
self.uri_template: Optional[str] = None
|
self.uri_template: Optional[str] = None
|
||||||
self.request_middleware_started = False
|
self.request_middleware_started = False
|
||||||
self._cookies: Dict[str, str] = {}
|
self._cookies: Optional[Dict[str, str]] = None
|
||||||
self._match_info = {}
|
self._match_info = {}
|
||||||
self.stream: Optional[Http] = None
|
self.stream: Optional[Http] = None
|
||||||
self.endpoint: Optional[str] = None
|
self.endpoint: Optional[str] = None
|
||||||
|
@ -183,8 +183,7 @@ class Request:
|
||||||
response = await self.app._run_response_middleware(
|
response = await self.app._run_response_middleware(
|
||||||
self, response, request_name=self.name
|
self, response, request_name=self.name
|
||||||
)
|
)
|
||||||
# Redefining this as a tuple here satisfies mypy
|
except CancelledErrors:
|
||||||
except tuple(*CancelledErrors):
|
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
error_logger.exception(
|
error_logger.exception(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user