Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89d942451f | ||
|
|
4d6205e6fe | ||
|
|
1684b0b986 | ||
|
|
4f5faa4a3c | ||
|
|
cbb77b536a | ||
|
|
35c76253bf | ||
|
|
8d86c3c598 | ||
|
|
97635111af | ||
|
|
7f3fe40cd4 | ||
|
|
ea34bcd849 | ||
|
|
05f758583b | ||
|
|
760c74a293 | ||
|
|
9def46beb8 | ||
|
|
04be8e95a5 | ||
|
|
78ced20fc7 |
@@ -1 +1 @@
|
|||||||
__version__ = "20.12.1"
|
__version__ = "20.12.4"
|
||||||
|
|||||||
23
sanic/app.py
23
sanic/app.py
@@ -12,6 +12,7 @@ from ssl import Purpose, SSLContext, create_default_context
|
|||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from typing import Any, Dict, Optional, Type, Union
|
from typing import Any, Dict, Optional, Type, Union
|
||||||
from urllib.parse import urlencode, urlunparse
|
from urllib.parse import urlencode, urlunparse
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
from sanic import reloader_helpers
|
from sanic import reloader_helpers
|
||||||
from sanic.asgi import ASGIApp
|
from sanic.asgi import ASGIApp
|
||||||
@@ -494,9 +495,7 @@ class Sanic:
|
|||||||
websocket_handler = partial(
|
websocket_handler = partial(
|
||||||
self._websocket_handler, handler, subprotocols=subprotocols
|
self._websocket_handler, handler, subprotocols=subprotocols
|
||||||
)
|
)
|
||||||
websocket_handler.__name__ = (
|
websocket_handler.__name__ = handler.__name__
|
||||||
"websocket_handler_" + handler.__name__
|
|
||||||
)
|
|
||||||
routes.extend(
|
routes.extend(
|
||||||
self.router.add(
|
self.router.add(
|
||||||
uri=uri,
|
uri=uri,
|
||||||
@@ -747,6 +746,24 @@ class Sanic:
|
|||||||
kw.update(name=view_name)
|
kw.update(name=view_name)
|
||||||
|
|
||||||
uri, route = self.router.find_route_by_view_name(view_name, **kw)
|
uri, route = self.router.find_route_by_view_name(view_name, **kw)
|
||||||
|
|
||||||
|
# TODO(laggardkernel): this fix should be removed in v21.3.
|
||||||
|
# Try again without the unnecessary prefix "websocket_handler_",
|
||||||
|
# which was added by accident on non-blueprint handlers. GH-2021
|
||||||
|
if not (uri and route) and view_name.startswith("websocket_handler_"):
|
||||||
|
view_name = view_name[18:]
|
||||||
|
uri, route = self.router.find_route_by_view_name(view_name, **kw)
|
||||||
|
if uri and route:
|
||||||
|
warn(
|
||||||
|
"The bug of adding unnecessary `websocket_handler_` "
|
||||||
|
"prefix in param `view_name` for non-blueprint handlers "
|
||||||
|
"is fixed. This backward support will be removed in "
|
||||||
|
"v21.3. Please update `Sanic.url_for()` callings in your "
|
||||||
|
"code soon.",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
|
|
||||||
if not (uri and route):
|
if not (uri and route):
|
||||||
raise URLBuildError(
|
raise URLBuildError(
|
||||||
f"Endpoint with name `{view_name}` was not found"
|
f"Endpoint with name `{view_name}` was not found"
|
||||||
|
|||||||
@@ -265,9 +265,12 @@ class Request:
|
|||||||
:type errors: str
|
:type errors: str
|
||||||
:return: RequestParameters
|
:return: RequestParameters
|
||||||
"""
|
"""
|
||||||
if not self.parsed_args[
|
if (
|
||||||
(keep_blank_values, strict_parsing, encoding, errors)
|
keep_blank_values,
|
||||||
]:
|
strict_parsing,
|
||||||
|
encoding,
|
||||||
|
errors,
|
||||||
|
) not in self.parsed_args:
|
||||||
if self.query_string:
|
if self.query_string:
|
||||||
self.parsed_args[
|
self.parsed_args[
|
||||||
(keep_blank_values, strict_parsing, encoding, errors)
|
(keep_blank_values, strict_parsing, encoding, errors)
|
||||||
@@ -321,9 +324,12 @@ class Request:
|
|||||||
:type errors: str
|
:type errors: str
|
||||||
:return: list
|
:return: list
|
||||||
"""
|
"""
|
||||||
if not self.parsed_not_grouped_args[
|
if (
|
||||||
(keep_blank_values, strict_parsing, encoding, errors)
|
keep_blank_values,
|
||||||
]:
|
strict_parsing,
|
||||||
|
encoding,
|
||||||
|
errors,
|
||||||
|
) not in self.parsed_not_grouped_args:
|
||||||
if self.query_string:
|
if self.query_string:
|
||||||
self.parsed_not_grouped_args[
|
self.parsed_not_grouped_args[
|
||||||
(keep_blank_values, strict_parsing, encoding, errors)
|
(keep_blank_values, strict_parsing, encoding, errors)
|
||||||
|
|||||||
3
setup.py
3
setup.py
@@ -57,7 +57,8 @@ setup_kwargs = {
|
|||||||
"author": "Sanic Community",
|
"author": "Sanic Community",
|
||||||
"author_email": "admhpkns@gmail.com",
|
"author_email": "admhpkns@gmail.com",
|
||||||
"description": (
|
"description": (
|
||||||
"A web server and web framework that's written to go fast. Build fast. Run fast."
|
"A web server and web framework that's written to go fast. "
|
||||||
|
"Build fast. Run fast."
|
||||||
),
|
),
|
||||||
"long_description": long_description,
|
"long_description": long_description,
|
||||||
"packages": ["sanic"],
|
"packages": ["sanic"],
|
||||||
|
|||||||
@@ -289,6 +289,17 @@ def test_query_string(app):
|
|||||||
assert request.args.getlist("test1") == ["1"]
|
assert request.args.getlist("test1") == ["1"]
|
||||||
assert request.args.get("test3", default="My value") == "My value"
|
assert request.args.get("test3", default="My value") == "My value"
|
||||||
|
|
||||||
|
def test_popped_stays_popped(app):
|
||||||
|
@app.route("/")
|
||||||
|
async def handler(request):
|
||||||
|
return text("OK")
|
||||||
|
|
||||||
|
request, response = app.test_client.get(
|
||||||
|
"/", params=[("test1", "1")]
|
||||||
|
)
|
||||||
|
|
||||||
|
assert request.args.pop("test1") == ["1"]
|
||||||
|
assert "test1" not in request.args
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_query_string_asgi(app):
|
async def test_query_string_asgi(app):
|
||||||
|
|||||||
@@ -348,3 +348,13 @@ def test_methodview_naming(methodview_app):
|
|||||||
|
|
||||||
assert viewone_url == "/view_one"
|
assert viewone_url == "/view_one"
|
||||||
assert viewtwo_url == "/view_two"
|
assert viewtwo_url == "/view_two"
|
||||||
|
|
||||||
|
|
||||||
|
def test_url_for_with_websocket_handlers(app):
|
||||||
|
# Test for a specific bugfix in GH-2021
|
||||||
|
@app.websocket("/ws")
|
||||||
|
async def my_handler(request, ws):
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert app.url_for("my_handler") == "/ws"
|
||||||
|
assert app.url_for("websocket_handler_my_handler") == "/ws"
|
||||||
|
|||||||
Reference in New Issue
Block a user