2022-01-24 04:07:52 +00:00
|
|
|
import typing as t
|
|
|
|
|
2022-11-07 18:06:49 +00:00
|
|
|
if t.TYPE_CHECKING: # pragma: no cover
|
2022-01-24 04:07:52 +00:00
|
|
|
from _typeshed.wsgi import WSGIApplication # noqa: F401
|
|
|
|
from werkzeug.datastructures import Headers # noqa: F401
|
2022-11-07 18:06:49 +00:00
|
|
|
from werkzeug.wrappers import Response # noqa: F401
|
2022-01-24 04:07:52 +00:00
|
|
|
|
|
|
|
# The possible types that are directly convertible or are a Response object.
|
|
|
|
ResponseValue = t.Union[
|
|
|
|
"Response",
|
2022-11-07 18:06:49 +00:00
|
|
|
str,
|
|
|
|
bytes,
|
|
|
|
t.List[t.Any],
|
|
|
|
# Only dict is actually accepted, but Mapping allows for TypedDict.
|
|
|
|
t.Mapping[str, t.Any],
|
|
|
|
t.Iterator[str],
|
|
|
|
t.Iterator[bytes],
|
2022-01-24 04:07:52 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# the possible types for an individual HTTP header
|
2022-11-07 18:06:49 +00:00
|
|
|
# This should be a Union, but mypy doesn't pass unless it's a TypeVar.
|
2022-01-24 04:07:52 +00:00
|
|
|
HeaderValue = t.Union[str, t.List[str], t.Tuple[str, ...]]
|
|
|
|
|
|
|
|
# the possible types for HTTP headers
|
|
|
|
HeadersValue = t.Union[
|
2022-11-07 18:06:49 +00:00
|
|
|
"Headers",
|
|
|
|
t.Mapping[str, HeaderValue],
|
|
|
|
t.Sequence[t.Tuple[str, HeaderValue]],
|
2022-01-24 04:07:52 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# The possible types returned by a route function.
|
|
|
|
ResponseReturnValue = t.Union[
|
|
|
|
ResponseValue,
|
|
|
|
t.Tuple[ResponseValue, HeadersValue],
|
2022-11-07 18:06:49 +00:00
|
|
|
t.Tuple[ResponseValue, int],
|
|
|
|
t.Tuple[ResponseValue, int, HeadersValue],
|
2022-01-24 04:07:52 +00:00
|
|
|
"WSGIApplication",
|
|
|
|
]
|
|
|
|
|
2022-11-07 18:06:49 +00:00
|
|
|
# Allow any subclass of werkzeug.Response, such as the one from Flask,
|
|
|
|
# as a callback argument. Using werkzeug.Response directly makes a
|
|
|
|
# callback annotated with flask.Response fail type checking.
|
|
|
|
ResponseClass = t.TypeVar("ResponseClass", bound="Response")
|
2022-01-24 04:07:52 +00:00
|
|
|
|
|
|
|
AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named
|
2022-11-07 18:06:49 +00:00
|
|
|
AfterRequestCallable = t.Union[
|
|
|
|
t.Callable[[ResponseClass], ResponseClass],
|
|
|
|
t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],
|
|
|
|
]
|
|
|
|
BeforeFirstRequestCallable = t.Union[
|
|
|
|
t.Callable[[], None], t.Callable[[], t.Awaitable[None]]
|
|
|
|
]
|
|
|
|
BeforeRequestCallable = t.Union[
|
|
|
|
t.Callable[[], t.Optional[ResponseReturnValue]],
|
|
|
|
t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],
|
|
|
|
]
|
|
|
|
ShellContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
|
|
|
|
TeardownCallable = t.Union[
|
|
|
|
t.Callable[[t.Optional[BaseException]], None],
|
|
|
|
t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],
|
|
|
|
]
|
2022-01-24 04:07:52 +00:00
|
|
|
TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
|
|
|
|
TemplateFilterCallable = t.Callable[..., t.Any]
|
|
|
|
TemplateGlobalCallable = t.Callable[..., t.Any]
|
|
|
|
TemplateTestCallable = t.Callable[..., bool]
|
|
|
|
URLDefaultCallable = t.Callable[[str, dict], None]
|
|
|
|
URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None]
|
|
|
|
|
2022-11-07 18:06:49 +00:00
|
|
|
# This should take Exception, but that either breaks typing the argument
|
|
|
|
# with a specific exception, or decorating multiple times with different
|
|
|
|
# exceptions (and using a union type on the argument).
|
|
|
|
# https://github.com/pallets/flask/issues/4095
|
|
|
|
# https://github.com/pallets/flask/issues/4295
|
|
|
|
# https://github.com/pallets/flask/issues/4297
|
|
|
|
ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue]
|
2022-01-24 04:07:52 +00:00
|
|
|
|
2022-11-07 18:06:49 +00:00
|
|
|
RouteCallable = t.Union[
|
|
|
|
t.Callable[..., ResponseReturnValue],
|
|
|
|
t.Callable[..., t.Awaitable[ResponseReturnValue]],
|
|
|
|
]
|