forked from orbit-oss/flask
Merge branch '2.1.x'
This commit is contained in:
commit
9e2e1de2fc
11 changed files with 118 additions and 116 deletions
|
|
@ -3,24 +3,14 @@ import typing as t
|
|||
from collections import defaultdict
|
||||
from functools import update_wrapper
|
||||
|
||||
from . import typing as ft
|
||||
from .scaffold import _endpoint_from_view_func
|
||||
from .scaffold import _sentinel
|
||||
from .scaffold import Scaffold
|
||||
from .scaffold import setupmethod
|
||||
from .typing import AfterRequestCallable
|
||||
from .typing import BeforeFirstRequestCallable
|
||||
from .typing import BeforeRequestCallable
|
||||
from .typing import TeardownCallable
|
||||
from .typing import TemplateContextProcessorCallable
|
||||
from .typing import TemplateFilterCallable
|
||||
from .typing import TemplateGlobalCallable
|
||||
from .typing import TemplateTestCallable
|
||||
from .typing import URLDefaultCallable
|
||||
from .typing import URLValuePreprocessorCallable
|
||||
|
||||
if t.TYPE_CHECKING: # pragma: no cover
|
||||
from .app import Flask
|
||||
from .typing import ErrorHandlerCallable
|
||||
|
||||
DeferredSetupFunction = t.Callable[["BlueprintSetupState"], t.Callable]
|
||||
|
||||
|
|
@ -428,7 +418,7 @@ class Blueprint(Scaffold):
|
|||
@setupmethod
|
||||
def app_template_filter(
|
||||
self, name: t.Optional[str] = None
|
||||
) -> t.Callable[[TemplateFilterCallable], TemplateFilterCallable]:
|
||||
) -> t.Callable[[ft.TemplateFilterCallable], ft.TemplateFilterCallable]:
|
||||
"""Register a custom template filter, available application wide. Like
|
||||
:meth:`Flask.template_filter` but for a blueprint.
|
||||
|
||||
|
|
@ -436,7 +426,7 @@ class Blueprint(Scaffold):
|
|||
function name will be used.
|
||||
"""
|
||||
|
||||
def decorator(f: TemplateFilterCallable) -> TemplateFilterCallable:
|
||||
def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:
|
||||
self.add_app_template_filter(f, name=name)
|
||||
return f
|
||||
|
||||
|
|
@ -444,7 +434,7 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def add_app_template_filter(
|
||||
self, f: TemplateFilterCallable, name: t.Optional[str] = None
|
||||
self, f: ft.TemplateFilterCallable, name: t.Optional[str] = None
|
||||
) -> None:
|
||||
"""Register a custom template filter, available application wide. Like
|
||||
:meth:`Flask.add_template_filter` but for a blueprint. Works exactly
|
||||
|
|
@ -462,7 +452,7 @@ class Blueprint(Scaffold):
|
|||
@setupmethod
|
||||
def app_template_test(
|
||||
self, name: t.Optional[str] = None
|
||||
) -> t.Callable[[TemplateTestCallable], TemplateTestCallable]:
|
||||
) -> t.Callable[[ft.TemplateTestCallable], ft.TemplateTestCallable]:
|
||||
"""Register a custom template test, available application wide. Like
|
||||
:meth:`Flask.template_test` but for a blueprint.
|
||||
|
||||
|
|
@ -472,7 +462,7 @@ class Blueprint(Scaffold):
|
|||
function name will be used.
|
||||
"""
|
||||
|
||||
def decorator(f: TemplateTestCallable) -> TemplateTestCallable:
|
||||
def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:
|
||||
self.add_app_template_test(f, name=name)
|
||||
return f
|
||||
|
||||
|
|
@ -480,7 +470,7 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def add_app_template_test(
|
||||
self, f: TemplateTestCallable, name: t.Optional[str] = None
|
||||
self, f: ft.TemplateTestCallable, name: t.Optional[str] = None
|
||||
) -> None:
|
||||
"""Register a custom template test, available application wide. Like
|
||||
:meth:`Flask.add_template_test` but for a blueprint. Works exactly
|
||||
|
|
@ -500,7 +490,7 @@ class Blueprint(Scaffold):
|
|||
@setupmethod
|
||||
def app_template_global(
|
||||
self, name: t.Optional[str] = None
|
||||
) -> t.Callable[[TemplateGlobalCallable], TemplateGlobalCallable]:
|
||||
) -> t.Callable[[ft.TemplateGlobalCallable], ft.TemplateGlobalCallable]:
|
||||
"""Register a custom template global, available application wide. Like
|
||||
:meth:`Flask.template_global` but for a blueprint.
|
||||
|
||||
|
|
@ -510,7 +500,7 @@ class Blueprint(Scaffold):
|
|||
function name will be used.
|
||||
"""
|
||||
|
||||
def decorator(f: TemplateGlobalCallable) -> TemplateGlobalCallable:
|
||||
def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:
|
||||
self.add_app_template_global(f, name=name)
|
||||
return f
|
||||
|
||||
|
|
@ -518,7 +508,7 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def add_app_template_global(
|
||||
self, f: TemplateGlobalCallable, name: t.Optional[str] = None
|
||||
self, f: ft.TemplateGlobalCallable, name: t.Optional[str] = None
|
||||
) -> None:
|
||||
"""Register a custom template global, available application wide. Like
|
||||
:meth:`Flask.add_template_global` but for a blueprint. Works exactly
|
||||
|
|
@ -536,7 +526,9 @@ class Blueprint(Scaffold):
|
|||
self.record_once(register_template)
|
||||
|
||||
@setupmethod
|
||||
def before_app_request(self, f: BeforeRequestCallable) -> BeforeRequestCallable:
|
||||
def before_app_request(
|
||||
self, f: ft.BeforeRequestCallable
|
||||
) -> ft.BeforeRequestCallable:
|
||||
"""Like :meth:`Flask.before_request`. Such a function is executed
|
||||
before each request, even if outside of a blueprint.
|
||||
"""
|
||||
|
|
@ -547,15 +539,15 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def before_app_first_request(
|
||||
self, f: BeforeFirstRequestCallable
|
||||
) -> BeforeFirstRequestCallable:
|
||||
self, f: ft.BeforeFirstRequestCallable
|
||||
) -> ft.BeforeFirstRequestCallable:
|
||||
"""Like :meth:`Flask.before_first_request`. Such a function is
|
||||
executed before the first request to the application.
|
||||
"""
|
||||
self.record_once(lambda s: s.app.before_first_request_funcs.append(f))
|
||||
return f
|
||||
|
||||
def after_app_request(self, f: AfterRequestCallable) -> AfterRequestCallable:
|
||||
def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:
|
||||
"""Like :meth:`Flask.after_request` but for a blueprint. Such a function
|
||||
is executed after each request, even if outside of the blueprint.
|
||||
"""
|
||||
|
|
@ -565,7 +557,7 @@ class Blueprint(Scaffold):
|
|||
return f
|
||||
|
||||
@setupmethod
|
||||
def teardown_app_request(self, f: TeardownCallable) -> TeardownCallable:
|
||||
def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:
|
||||
"""Like :meth:`Flask.teardown_request` but for a blueprint. Such a
|
||||
function is executed when tearing down each request, even if outside of
|
||||
the blueprint.
|
||||
|
|
@ -577,8 +569,8 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def app_context_processor(
|
||||
self, f: TemplateContextProcessorCallable
|
||||
) -> TemplateContextProcessorCallable:
|
||||
self, f: ft.TemplateContextProcessorCallable
|
||||
) -> ft.TemplateContextProcessorCallable:
|
||||
"""Like :meth:`Flask.context_processor` but for a blueprint. Such a
|
||||
function is executed each request, even if outside of the blueprint.
|
||||
"""
|
||||
|
|
@ -593,7 +585,7 @@ class Blueprint(Scaffold):
|
|||
handler is used for all requests, even if outside of the blueprint.
|
||||
"""
|
||||
|
||||
def decorator(f: "ErrorHandlerCallable") -> "ErrorHandlerCallable":
|
||||
def decorator(f: ft.ErrorHandlerCallable) -> ft.ErrorHandlerCallable:
|
||||
self.record_once(lambda s: s.app.errorhandler(code)(f))
|
||||
return f
|
||||
|
||||
|
|
@ -601,8 +593,8 @@ class Blueprint(Scaffold):
|
|||
|
||||
@setupmethod
|
||||
def app_url_value_preprocessor(
|
||||
self, f: URLValuePreprocessorCallable
|
||||
) -> URLValuePreprocessorCallable:
|
||||
self, f: ft.URLValuePreprocessorCallable
|
||||
) -> ft.URLValuePreprocessorCallable:
|
||||
"""Same as :meth:`url_value_preprocessor` but application wide."""
|
||||
self.record_once(
|
||||
lambda s: s.app.url_value_preprocessors.setdefault(None, []).append(f)
|
||||
|
|
@ -610,7 +602,7 @@ class Blueprint(Scaffold):
|
|||
return f
|
||||
|
||||
@setupmethod
|
||||
def app_url_defaults(self, f: URLDefaultCallable) -> URLDefaultCallable:
|
||||
def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:
|
||||
"""Same as :meth:`url_defaults` but application wide."""
|
||||
self.record_once(
|
||||
lambda s: s.app.url_default_functions.setdefault(None, []).append(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue