mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -19,9 +19,9 @@ try:
|
||||
# adding a type ignore for mypy to let us access an attribute that may not exist
|
||||
if hasattr(jinja2, "pass_context"):
|
||||
pass_context = jinja2.pass_context
|
||||
else: # pragma: nocover
|
||||
else: # pragma: no cover
|
||||
pass_context = jinja2.contextfunction # type: ignore[attr-defined]
|
||||
except ModuleNotFoundError: # pragma: nocover
|
||||
except ModuleNotFoundError: # pragma: no cover
|
||||
jinja2 = None # type: ignore[assignment]
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class _TemplateResponse(HTMLResponse):
|
||||
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
||||
request = self.context.get("request", {})
|
||||
extensions = request.get("extensions", {})
|
||||
if "http.response.debug" in extensions:
|
||||
if "http.response.debug" in extensions: # pragma: no branch
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.debug",
|
||||
@@ -66,58 +66,46 @@ class Jinja2Templates:
|
||||
@typing.overload
|
||||
def __init__(
|
||||
self,
|
||||
directory: str
|
||||
| PathLike[typing.AnyStr]
|
||||
| typing.Sequence[str | PathLike[typing.AnyStr]],
|
||||
directory: str | PathLike[str] | typing.Sequence[str | PathLike[str]],
|
||||
*,
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]]
|
||||
| None = None,
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]] | None = None,
|
||||
**env_options: typing.Any,
|
||||
) -> None:
|
||||
...
|
||||
) -> None: ...
|
||||
|
||||
@typing.overload
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
env: jinja2.Environment,
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]]
|
||||
| None = None,
|
||||
) -> None:
|
||||
...
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]] | None = None,
|
||||
) -> None: ...
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
directory: str
|
||||
| PathLike[typing.AnyStr]
|
||||
| typing.Sequence[str | PathLike[typing.AnyStr]]
|
||||
| None = None,
|
||||
directory: str | PathLike[str] | typing.Sequence[str | PathLike[str]] | None = None,
|
||||
*,
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]]
|
||||
| None = None,
|
||||
context_processors: list[typing.Callable[[Request], dict[str, typing.Any]]] | None = None,
|
||||
env: jinja2.Environment | None = None,
|
||||
**env_options: typing.Any,
|
||||
) -> None:
|
||||
if env_options:
|
||||
warnings.warn(
|
||||
"Extra environment options are deprecated. Use a preconfigured jinja2.Environment instead.", # noqa: E501
|
||||
"Extra environment options are deprecated. Use a preconfigured jinja2.Environment instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
assert jinja2 is not None, "jinja2 must be installed to use Jinja2Templates"
|
||||
assert directory or env, "either 'directory' or 'env' arguments must be passed"
|
||||
assert bool(directory) ^ bool(env), "either 'directory' or 'env' arguments must be passed"
|
||||
self.context_processors = context_processors or []
|
||||
if directory is not None:
|
||||
self.env = self._create_env(directory, **env_options)
|
||||
elif env is not None:
|
||||
elif env is not None: # pragma: no branch
|
||||
self.env = env
|
||||
|
||||
self._setup_env_defaults(self.env)
|
||||
|
||||
def _create_env(
|
||||
self,
|
||||
directory: str
|
||||
| PathLike[typing.AnyStr]
|
||||
| typing.Sequence[str | PathLike[typing.AnyStr]],
|
||||
directory: str | PathLike[str] | typing.Sequence[str | PathLike[str]],
|
||||
**env_options: typing.Any,
|
||||
) -> jinja2.Environment:
|
||||
loader = jinja2.FileSystemLoader(directory)
|
||||
@@ -129,7 +117,7 @@ class Jinja2Templates:
|
||||
def _setup_env_defaults(self, env: jinja2.Environment) -> None:
|
||||
@pass_context
|
||||
def url_for(
|
||||
context: typing.Dict[str, typing.Any],
|
||||
context: dict[str, typing.Any],
|
||||
name: str,
|
||||
/,
|
||||
**path_params: typing.Any,
|
||||
@@ -152,8 +140,7 @@ class Jinja2Templates:
|
||||
headers: typing.Mapping[str, str] | None = None,
|
||||
media_type: str | None = None,
|
||||
background: BackgroundTask | None = None,
|
||||
) -> _TemplateResponse:
|
||||
...
|
||||
) -> _TemplateResponse: ...
|
||||
|
||||
@typing.overload
|
||||
def TemplateResponse(
|
||||
@@ -168,25 +155,19 @@ class Jinja2Templates:
|
||||
# Deprecated usage
|
||||
...
|
||||
|
||||
def TemplateResponse(
|
||||
self, *args: typing.Any, **kwargs: typing.Any
|
||||
) -> _TemplateResponse:
|
||||
def TemplateResponse(self, *args: typing.Any, **kwargs: typing.Any) -> _TemplateResponse:
|
||||
if args:
|
||||
if isinstance(
|
||||
args[0], str
|
||||
): # the first argument is template name (old style)
|
||||
if isinstance(args[0], str): # the first argument is template name (old style)
|
||||
warnings.warn(
|
||||
"The `name` is not the first parameter anymore. "
|
||||
"The first parameter should be the `Request` instance.\n"
|
||||
'Replace `TemplateResponse(name, {"request": request})` by `TemplateResponse(request, name)`.', # noqa: E501
|
||||
'Replace `TemplateResponse(name, {"request": request})` by `TemplateResponse(request, name)`.',
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
name = args[0]
|
||||
context = args[1] if len(args) > 1 else kwargs.get("context", {})
|
||||
status_code = (
|
||||
args[2] if len(args) > 2 else kwargs.get("status_code", 200)
|
||||
)
|
||||
status_code = args[2] if len(args) > 2 else kwargs.get("status_code", 200)
|
||||
headers = args[2] if len(args) > 2 else kwargs.get("headers")
|
||||
media_type = args[3] if len(args) > 3 else kwargs.get("media_type")
|
||||
background = args[4] if len(args) > 4 else kwargs.get("background")
|
||||
@@ -198,9 +179,7 @@ class Jinja2Templates:
|
||||
request = args[0]
|
||||
name = args[1] if len(args) > 1 else kwargs["name"]
|
||||
context = args[2] if len(args) > 2 else kwargs.get("context", {})
|
||||
status_code = (
|
||||
args[3] if len(args) > 3 else kwargs.get("status_code", 200)
|
||||
)
|
||||
status_code = args[3] if len(args) > 3 else kwargs.get("status_code", 200)
|
||||
headers = args[4] if len(args) > 4 else kwargs.get("headers")
|
||||
media_type = args[5] if len(args) > 5 else kwargs.get("media_type")
|
||||
background = args[6] if len(args) > 6 else kwargs.get("background")
|
||||
@@ -208,7 +187,7 @@ class Jinja2Templates:
|
||||
if "request" not in kwargs:
|
||||
warnings.warn(
|
||||
"The `TemplateResponse` now requires the `request` argument.\n"
|
||||
'Replace `TemplateResponse(name, {"context": context})` by `TemplateResponse(request, name)`.', # noqa: E501
|
||||
'Replace `TemplateResponse(name, {"context": context})` by `TemplateResponse(request, name)`.',
|
||||
DeprecationWarning,
|
||||
)
|
||||
if "request" not in kwargs.get("context", {}):
|
||||
|
Reference in New Issue
Block a user