aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Jinja2/py3/jinja2/environment.py
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2024-05-20 09:01:58 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2024-05-20 09:13:14 +0300
commit113478c6a7e201ab2d7ad78d9edbc28800283a75 (patch)
tree98b88d8dc4bfe5c664f813ead96eefb0f456e2a9 /contrib/python/Jinja2/py3/jinja2/environment.py
parent685fde8e2a4228200a88a5987a061329f7c59323 (diff)
downloadydb-113478c6a7e201ab2d7ad78d9edbc28800283a75.tar.gz
Update contrib/python/Jinja2/py3 to 3.1.4
264ae85f13f4a11226be8b846079da1aece08b50
Diffstat (limited to 'contrib/python/Jinja2/py3/jinja2/environment.py')
-rw-r--r--contrib/python/Jinja2/py3/jinja2/environment.py48
1 files changed, 28 insertions, 20 deletions
diff --git a/contrib/python/Jinja2/py3/jinja2/environment.py b/contrib/python/Jinja2/py3/jinja2/environment.py
index 185d33246e3..1d3be0bed08 100644
--- a/contrib/python/Jinja2/py3/jinja2/environment.py
+++ b/contrib/python/Jinja2/py3/jinja2/environment.py
@@ -1,6 +1,7 @@
"""Classes for managing templates and their runtime and compile time
options.
"""
+
import os
import typing
import typing as t
@@ -20,10 +21,10 @@ from .defaults import BLOCK_END_STRING
from .defaults import BLOCK_START_STRING
from .defaults import COMMENT_END_STRING
from .defaults import COMMENT_START_STRING
-from .defaults import DEFAULT_FILTERS
+from .defaults import DEFAULT_FILTERS # type: ignore[attr-defined]
from .defaults import DEFAULT_NAMESPACE
from .defaults import DEFAULT_POLICIES
-from .defaults import DEFAULT_TESTS
+from .defaults import DEFAULT_TESTS # type: ignore[attr-defined]
from .defaults import KEEP_TRAILING_NEWLINE
from .defaults import LINE_COMMENT_PREFIX
from .defaults import LINE_STATEMENT_PREFIX
@@ -55,6 +56,7 @@ from .utils import missing
if t.TYPE_CHECKING:
import typing_extensions as te
+
from .bccache import BytecodeCache
from .ext import Extension
from .loaders import BaseLoader
@@ -79,7 +81,7 @@ def get_spontaneous_environment(cls: t.Type[_env_bound], *args: t.Any) -> _env_b
def create_cache(
size: int,
-) -> t.Optional[t.MutableMapping[t.Tuple[weakref.ref, str], "Template"]]:
+) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[t.Any]", str], "Template"]]:
"""Return the cache class for the given size."""
if size == 0:
return None
@@ -91,13 +93,13 @@ def create_cache(
def copy_cache(
- cache: t.Optional[t.MutableMapping],
-) -> t.Optional[t.MutableMapping[t.Tuple[weakref.ref, str], "Template"]]:
+ cache: t.Optional[t.MutableMapping[t.Any, t.Any]],
+) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[t.Any]", str], "Template"]]:
"""Create an empty copy of the given cache."""
if cache is None:
return None
- if type(cache) is dict:
+ if type(cache) is dict: # noqa E721
return {}
return LRUCache(cache.capacity) # type: ignore
@@ -670,7 +672,7 @@ class Environment:
stream = ext.filter_stream(stream) # type: ignore
if not isinstance(stream, TokenStream):
- stream = TokenStream(stream, name, filename) # type: ignore
+ stream = TokenStream(stream, name, filename)
return stream
@@ -711,8 +713,7 @@ class Environment:
filename: t.Optional[str] = None,
raw: "te.Literal[False]" = False,
defer_init: bool = False,
- ) -> CodeType:
- ...
+ ) -> CodeType: ...
@typing.overload
def compile(
@@ -722,8 +723,7 @@ class Environment:
filename: t.Optional[str] = None,
raw: "te.Literal[True]" = ...,
defer_init: bool = False,
- ) -> str:
- ...
+ ) -> str: ...
@internalcode
def compile(
@@ -814,7 +814,7 @@ class Environment:
def compile_templates(
self,
- target: t.Union[str, os.PathLike],
+ target: t.Union[str, "os.PathLike[str]"],
extensions: t.Optional[t.Collection[str]] = None,
filter_func: t.Optional[t.Callable[[str], bool]] = None,
zip: t.Optional[str] = "deflated",
@@ -858,7 +858,10 @@ class Environment:
f.write(data.encode("utf8"))
if zip is not None:
- from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED, ZIP_STORED
+ from zipfile import ZIP_DEFLATED
+ from zipfile import ZIP_STORED
+ from zipfile import ZipFile
+ from zipfile import ZipInfo
zip_file = ZipFile(
target, "w", dict(deflated=ZIP_DEFLATED, stored=ZIP_STORED)[zip]
@@ -1417,7 +1420,9 @@ class Template:
"""
ctx = self.new_context(vars, shared, locals)
return TemplateModule(
- self, ctx, [x async for x in self.root_render_func(ctx)] # type: ignore
+ self,
+ ctx,
+ [x async for x in self.root_render_func(ctx)], # type: ignore
)
@internalcode
@@ -1588,7 +1593,7 @@ class TemplateStream:
def dump(
self,
- fp: t.Union[str, t.IO],
+ fp: t.Union[str, t.IO[bytes]],
encoding: t.Optional[str] = None,
errors: t.Optional[str] = "strict",
) -> None:
@@ -1606,22 +1611,25 @@ class TemplateStream:
if encoding is None:
encoding = "utf-8"
- fp = open(fp, "wb")
+ real_fp: t.IO[bytes] = open(fp, "wb")
close = True
+ else:
+ real_fp = fp
+
try:
if encoding is not None:
iterable = (x.encode(encoding, errors) for x in self) # type: ignore
else:
iterable = self # type: ignore
- if hasattr(fp, "writelines"):
- fp.writelines(iterable)
+ if hasattr(real_fp, "writelines"):
+ real_fp.writelines(iterable)
else:
for item in iterable:
- fp.write(item)
+ real_fp.write(item)
finally:
if close:
- fp.close()
+ real_fp.close()
def disable_buffering(self) -> None:
"""Disable the output buffering."""