Skip to content
Closed

AI junk #6127

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Unreleased
it's disabled in config. Previously, only disabling worked. :issue:`5916`
- ``Flask.select_jinja_autoescape`` uses case-insensitive comparison instead
of only lower case file extensions. :pr:`6012`
- Add ``query`` route shortcut and ``MethodView`` dispatch support for the
HTTP ``QUERY`` method. :issue:`6065`


Version 3.1.3
Expand Down
8 changes: 8 additions & 0 deletions src/flask/sansio/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ def patch(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
"""
return self._method_route("PATCH", rule, options)

@setupmethod
def query(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
"""Shortcut for :meth:`route` with ``methods=["QUERY"]``.

.. versionadded:: 3.2
"""
return self._method_route("QUERY", rule, options)

@setupmethod
def route(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
"""Decorate a view function to register it with the given URL
Expand Down
15 changes: 14 additions & 1 deletion src/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
F = t.TypeVar("F", bound=t.Callable[..., t.Any])

http_method_funcs = frozenset(
["get", "post", "head", "options", "delete", "put", "trace", "patch"]
[
"get",
"post",
"head",
"options",
"delete",
"put",
"trace",
"patch",
"query",
]
)


Expand Down Expand Up @@ -142,6 +152,9 @@ class MethodView(View):

This can be useful for defining a REST API.

.. versionchanged:: 3.2
The ``query`` method is recognized for HTTP ``QUERY`` requests.

:attr:`methods` is automatically set based on the methods defined on
the class.

Expand Down
19 changes: 19 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ def post(self):
common_test(app)


def test_query_method_view(app, client):
class Index(flask.views.MethodView):
def query(self):
return "QUERY"

app.add_url_rule("/", view_func=Index.as_view("index"))

assert client.open("/", method="QUERY").data == b"QUERY"
assert Index.methods == {"QUERY"}


def test_query_route_shortcut(app, client):
@app.query("/")
def index():
return "QUERY"

assert client.open("/", method="QUERY").data == b"QUERY"


def test_view_patching(app):
class Index(flask.views.MethodView):
def get(self):
Expand Down
Loading