Change dumps to AnyStr (#2193)
This commit is contained in:
parent
7b7a572f9b
commit
94d496afe1
12
sanic/app.py
12
sanic/app.py
|
@ -21,6 +21,7 @@ from traceback import format_exc
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
AnyStr,
|
||||||
Awaitable,
|
Awaitable,
|
||||||
Callable,
|
Callable,
|
||||||
Coroutine,
|
Coroutine,
|
||||||
|
@ -138,7 +139,7 @@ class Sanic(BaseSanic):
|
||||||
log_config: Optional[Dict[str, Any]] = None,
|
log_config: Optional[Dict[str, Any]] = None,
|
||||||
configure_logging: bool = True,
|
configure_logging: bool = True,
|
||||||
register: Optional[bool] = None,
|
register: Optional[bool] = None,
|
||||||
dumps: Optional[Callable[..., str]] = None,
|
dumps: Optional[Callable[..., AnyStr]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(name=name)
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
@ -193,7 +194,7 @@ class Sanic(BaseSanic):
|
||||||
self.router.ctx.app = self
|
self.router.ctx.app = self
|
||||||
|
|
||||||
if dumps:
|
if dumps:
|
||||||
BaseHTTPResponse._dumps = dumps
|
BaseHTTPResponse._dumps = dumps # type: ignore
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loop(self):
|
def loop(self):
|
||||||
|
@ -737,15 +738,14 @@ class Sanic(BaseSanic):
|
||||||
request.route = route
|
request.route = route
|
||||||
|
|
||||||
if (
|
if (
|
||||||
request.stream.request_body # type: ignore
|
request.stream
|
||||||
|
and request.stream.request_body
|
||||||
and not route.ctx.ignore_body
|
and not route.ctx.ignore_body
|
||||||
):
|
):
|
||||||
|
|
||||||
if hasattr(handler, "is_stream"):
|
if hasattr(handler, "is_stream"):
|
||||||
# Streaming handler: lift the size limit
|
# Streaming handler: lift the size limit
|
||||||
request.stream.request_max_size = float( # type: ignore
|
request.stream.request_max_size = float("inf")
|
||||||
"inf"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Non-streaming handler: preload body
|
# Non-streaming handler: preload body
|
||||||
await request.receive_body()
|
await request.receive_body()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user