add aborter object to app
This commit is contained in:
parent
a25d234cdd
commit
eb5dd9f5ef
5 changed files with 92 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ from functools import update_wrapper
|
|||
from threading import RLock
|
||||
|
||||
import werkzeug.utils
|
||||
from werkzeug.exceptions import abort as _wz_abort
|
||||
from werkzeug.routing import BuildError
|
||||
from werkzeug.urls import url_quote
|
||||
from werkzeug.utils import redirect as _wz_redirect
|
||||
|
|
@ -24,6 +25,7 @@ from .signals import message_flashed
|
|||
if t.TYPE_CHECKING: # pragma: no cover
|
||||
from werkzeug.wrappers import Response as BaseResponse
|
||||
from .wrappers import Response
|
||||
import typing_extensions as te
|
||||
|
||||
|
||||
def get_env() -> str:
|
||||
|
|
@ -364,6 +366,31 @@ def redirect(
|
|||
return _wz_redirect(location, code=code, Response=Response)
|
||||
|
||||
|
||||
def abort( # type: ignore[misc]
|
||||
code: t.Union[int, "BaseResponse"], *args: t.Any, **kwargs: t.Any
|
||||
) -> "te.NoReturn":
|
||||
"""Raise an :exc:`~werkzeug.exceptions.HTTPException` for the given
|
||||
status code.
|
||||
|
||||
If :data:`~flask.current_app` is available, it will call its
|
||||
:attr:`~flask.Flask.aborter` object, otherwise it will use
|
||||
:func:`werkzeug.exceptions.abort`.
|
||||
|
||||
:param code: The status code for the exception, which must be
|
||||
registered in ``app.aborter``.
|
||||
:param args: Passed to the exception.
|
||||
:param kwargs: Passed to the exception.
|
||||
|
||||
.. versionadded:: 2.2
|
||||
Calls ``current_app.aborter`` if available instead of always
|
||||
using Werkzeug's default ``abort``.
|
||||
"""
|
||||
if current_app:
|
||||
current_app.aborter(code, *args, **kwargs)
|
||||
|
||||
_wz_abort(code, *args, **kwargs)
|
||||
|
||||
|
||||
def get_template_attribute(template_name: str, attribute: str) -> t.Any:
|
||||
"""Loads a macro (or variable) a template exports. This can be used to
|
||||
invoke a macro from within Python code. If you for example have a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue