diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-01-25 09:51:43 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-01-25 10:15:24 +0300 |
commit | 42db3295ba5bc7fffa4b289c9010d802e2d7911c (patch) | |
tree | c9a78a1b8b9f06c8de4788c1e19c83a35beea59d /contrib/python/Jinja2/py3 | |
parent | a47b1fb37eb32d1a5d55d8be2af832cc4406935a (diff) | |
download | ydb-42db3295ba5bc7fffa4b289c9010d802e2d7911c.tar.gz |
Update contrib/python/Jinja2/py3 to 3.1.3
Diffstat (limited to 'contrib/python/Jinja2/py3')
18 files changed, 133 insertions, 86 deletions
diff --git a/contrib/python/Jinja2/py3/.dist-info/METADATA b/contrib/python/Jinja2/py3/.dist-info/METADATA index f54bb5ca1a..56e942902a 100644 --- a/contrib/python/Jinja2/py3/.dist-info/METADATA +++ b/contrib/python/Jinja2/py3/.dist-info/METADATA @@ -1,10 +1,8 @@ Metadata-Version: 2.1 Name: Jinja2 -Version: 3.1.2 +Version: 3.1.3 Summary: A very fast and expressive template engine. Home-page: https://palletsprojects.com/p/jinja/ -Author: Armin Ronacher -Author-email: armin.ronacher@active-4.com Maintainer: Pallets Maintainer-email: contact@palletsprojects.com License: BSD-3-Clause @@ -13,9 +11,7 @@ Project-URL: Documentation, https://jinja.palletsprojects.com/ Project-URL: Changes, https://jinja.palletsprojects.com/changes/ Project-URL: Source Code, https://github.com/pallets/jinja/ Project-URL: Issue Tracker, https://github.com/pallets/jinja/issues/ -Project-URL: Twitter, https://twitter.com/PalletsTeam Project-URL: Chat, https://discord.gg/pallets -Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers @@ -27,9 +23,9 @@ Classifier: Topic :: Text Processing :: Markup :: HTML Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE.rst -Requires-Dist: MarkupSafe (>=2.0) +Requires-Dist: MarkupSafe >=2.0 Provides-Extra: i18n -Requires-Dist: Babel (>=2.7) ; extra == 'i18n' +Requires-Dist: Babel >=2.7 ; extra == 'i18n' Jinja ===== @@ -106,8 +102,4 @@ Links - PyPI Releases: https://pypi.org/project/Jinja2/ - Source Code: https://github.com/pallets/jinja/ - Issue Tracker: https://github.com/pallets/jinja/issues/ -- Website: https://palletsprojects.com/p/jinja/ -- Twitter: https://twitter.com/PalletsTeam - Chat: https://discord.gg/pallets - - diff --git a/contrib/python/Jinja2/py3/README.rst b/contrib/python/Jinja2/py3/README.rst index a197aea647..94b22ecabe 100644 --- a/contrib/python/Jinja2/py3/README.rst +++ b/contrib/python/Jinja2/py3/README.rst @@ -73,6 +73,4 @@ Links - PyPI Releases: https://pypi.org/project/Jinja2/ - Source Code: https://github.com/pallets/jinja/ - Issue Tracker: https://github.com/pallets/jinja/issues/ -- Website: https://palletsprojects.com/p/jinja/ -- Twitter: https://twitter.com/PalletsTeam - Chat: https://discord.gg/pallets diff --git a/contrib/python/Jinja2/py3/jinja2/__init__.py b/contrib/python/Jinja2/py3/jinja2/__init__.py index a684093795..8076e72cd1 100644 --- a/contrib/python/Jinja2/py3/jinja2/__init__.py +++ b/contrib/python/Jinja2/py3/jinja2/__init__.py @@ -35,4 +35,4 @@ from .utils import pass_environment as pass_environment from .utils import pass_eval_context as pass_eval_context from .utils import select_autoescape as select_autoescape -__version__ = "3.1.2" +__version__ = "3.1.3" diff --git a/contrib/python/Jinja2/py3/jinja2/async_utils.py b/contrib/python/Jinja2/py3/jinja2/async_utils.py index 1a4f3892ce..715d70119b 100644 --- a/contrib/python/Jinja2/py3/jinja2/async_utils.py +++ b/contrib/python/Jinja2/py3/jinja2/async_utils.py @@ -74,7 +74,7 @@ async def auto_aiter( async for item in t.cast("t.AsyncIterable[V]", iterable): yield item else: - for item in t.cast("t.Iterable[V]", iterable): + for item in iterable: yield item diff --git a/contrib/python/Jinja2/py3/jinja2/compiler.py b/contrib/python/Jinja2/py3/jinja2/compiler.py index 3458095f54..ff95c807b0 100644 --- a/contrib/python/Jinja2/py3/jinja2/compiler.py +++ b/contrib/python/Jinja2/py3/jinja2/compiler.py @@ -993,7 +993,6 @@ class CodeGenerator(NodeVisitor): # far, we don't have to add a check if something extended # the template before this one. if self.extends_so_far > 0: - # if we have a known extends we just add a template runtime # error into the generated code. We could catch that at compile # time too, but i welcome it not to confuse users by throwing the @@ -1407,7 +1406,7 @@ class CodeGenerator(NodeVisitor): if pass_arg is None: - def finalize(value: t.Any) -> t.Any: + def finalize(value: t.Any) -> t.Any: # noqa: F811 return default(env_finalize(value)) else: @@ -1415,7 +1414,7 @@ class CodeGenerator(NodeVisitor): if pass_arg == "environment": - def finalize(value: t.Any) -> t.Any: + def finalize(value: t.Any) -> t.Any: # noqa: F811 return default(env_finalize(self.environment, value)) self._finalize = self._FinalizeInfo(finalize, src) diff --git a/contrib/python/Jinja2/py3/jinja2/environment.py b/contrib/python/Jinja2/py3/jinja2/environment.py index ea04e8b443..185d33246e 100644 --- a/contrib/python/Jinja2/py3/jinja2/environment.py +++ b/contrib/python/Jinja2/py3/jinja2/environment.py @@ -701,7 +701,7 @@ class Environment: .. versionadded:: 2.5 """ - return compile(source, filename, "exec") # type: ignore + return compile(source, filename, "exec") @typing.overload def compile( # type: ignore @@ -920,7 +920,7 @@ class Environment: ) def filter_func(x: str) -> bool: - return "." in x and x.rsplit(".", 1)[1] in extensions # type: ignore + return "." in x and x.rsplit(".", 1)[1] in extensions if filter_func is not None: names = [name for name in names if filter_func(name)] @@ -1253,7 +1253,7 @@ class Template: t.blocks = namespace["blocks"] # render function and module - t.root_render_func = namespace["root"] # type: ignore + t.root_render_func = namespace["root"] t._module = None # debug and loader helpers @@ -1349,7 +1349,7 @@ class Template: ctx = self.new_context(dict(*args, **kwargs)) try: - yield from self.root_render_func(ctx) # type: ignore + yield from self.root_render_func(ctx) except Exception: yield self.environment.handle_exception() @@ -1532,7 +1532,7 @@ class TemplateModule: " API you are using." ) - body_stream = list(template.root_render_func(context)) # type: ignore + body_stream = list(template.root_render_func(context)) self._body_stream = body_stream self.__dict__.update(context.get_exported()) @@ -1564,7 +1564,7 @@ class TemplateExpression: def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Optional[t.Any]: context = self._template.new_context(dict(*args, **kwargs)) - consume(self._template.root_render_func(context)) # type: ignore + consume(self._template.root_render_func(context)) rv = context.vars["result"] if self._undefined_to_none and isinstance(rv, Undefined): rv = None diff --git a/contrib/python/Jinja2/py3/jinja2/ext.py b/contrib/python/Jinja2/py3/jinja2/ext.py index d5550540cd..fade1fa3bc 100644 --- a/contrib/python/Jinja2/py3/jinja2/ext.py +++ b/contrib/python/Jinja2/py3/jinja2/ext.py @@ -291,14 +291,14 @@ class InternationalizationExtension(Extension): if hasattr(translations, "pgettext"): # Python < 3.8 - pgettext = translations.pgettext # type: ignore + pgettext = translations.pgettext else: def pgettext(c: str, s: str) -> str: return s if hasattr(translations, "npgettext"): - npgettext = translations.npgettext # type: ignore + npgettext = translations.npgettext else: def npgettext(c: str, s: str, p: str, n: int) -> str: @@ -495,16 +495,26 @@ class InternationalizationExtension(Extension): parser.stream.expect("variable_end") elif parser.stream.current.type == "block_begin": next(parser.stream) - if parser.stream.current.test("name:endtrans"): + block_name = ( + parser.stream.current.value + if parser.stream.current.type == "name" + else None + ) + if block_name == "endtrans": break - elif parser.stream.current.test("name:pluralize"): + elif block_name == "pluralize": if allow_pluralize: break parser.fail( "a translatable section can have only one pluralize section" ) + elif block_name == "trans": + parser.fail( + "trans blocks can't be nested; did you mean `endtrans`?" + ) parser.fail( - "control structures in translatable sections are not allowed" + f"control structures in translatable sections are not allowed; " + f"saw `{block_name}`" ) elif parser.stream.eos: parser.fail("unclosed translation block") diff --git a/contrib/python/Jinja2/py3/jinja2/filters.py b/contrib/python/Jinja2/py3/jinja2/filters.py index ed07c4c0e2..c7ecc9bb68 100644 --- a/contrib/python/Jinja2/py3/jinja2/filters.py +++ b/contrib/python/Jinja2/py3/jinja2/filters.py @@ -248,13 +248,17 @@ def do_items(value: t.Union[t.Mapping[K, V], Undefined]) -> t.Iterator[t.Tuple[K yield from value.items() +_space_re = re.compile(r"\s", flags=re.ASCII) + + @pass_eval_context def do_xmlattr( eval_ctx: "EvalContext", d: t.Mapping[str, t.Any], autospace: bool = True ) -> str: """Create an SGML/XML attribute string based on the items in a dict. - All values that are neither `none` nor `undefined` are automatically - escaped: + + If any key contains a space, this fails with a ``ValueError``. Values that + are neither ``none`` nor ``undefined`` are automatically escaped. .. sourcecode:: html+jinja @@ -273,12 +277,22 @@ def do_xmlattr( As you can see it automatically prepends a space in front of the item if the filter returned something unless the second parameter is false. + + .. versionchanged:: 3.1.3 + Keys with spaces are not allowed. """ - rv = " ".join( - f'{escape(key)}="{escape(value)}"' - for key, value in d.items() - if value is not None and not isinstance(value, Undefined) - ) + items = [] + + for key, value in d.items(): + if value is None or isinstance(value, Undefined): + continue + + if _space_re.search(key) is not None: + raise ValueError(f"Spaces are not allowed in attributes: '{key}'") + + items.append(f'{escape(key)}="{escape(value)}"') + + rv = " ".join(items) if autospace and rv: rv = " " + rv diff --git a/contrib/python/Jinja2/py3/jinja2/loaders.py b/contrib/python/Jinja2/py3/jinja2/loaders.py index 261802176a..dfa2ad7ec5 100644 --- a/contrib/python/Jinja2/py3/jinja2/loaders.py +++ b/contrib/python/Jinja2/py3/jinja2/loaders.py @@ -16,7 +16,6 @@ from types import ModuleType from .exceptions import TemplateNotFound from .utils import internalcode -from .utils import open_if_exists if t.TYPE_CHECKING: from .environment import Environment @@ -196,29 +195,30 @@ class FileSystemLoader(BaseLoader): self, environment: "Environment", template: str ) -> t.Tuple[str, str, t.Callable[[], bool]]: pieces = split_template_path(template) + for searchpath in self.searchpath: # Use posixpath even on Windows to avoid "drive:" or UNC # segments breaking out of the search directory. filename = posixpath.join(searchpath, *pieces) - f = open_if_exists(filename) - if f is None: - continue - try: - contents = f.read().decode(self.encoding) - finally: - f.close() - mtime = os.path.getmtime(filename) + if os.path.isfile(filename): + break + else: + raise TemplateNotFound(template) - def uptodate() -> bool: - try: - return os.path.getmtime(filename) == mtime - except OSError: - return False + with open(filename, encoding=self.encoding) as f: + contents = f.read() - # Use normpath to convert Windows altsep to sep. - return contents, os.path.normpath(filename), uptodate - raise TemplateNotFound(template) + mtime = os.path.getmtime(filename) + + def uptodate() -> bool: + try: + return os.path.getmtime(filename) == mtime + except OSError: + return False + + # Use normpath to convert Windows altsep to sep. + return contents, os.path.normpath(filename), uptodate def list_templates(self) -> t.List[str]: found = set() @@ -412,7 +412,7 @@ class PackageLoader(BaseLoader): ) offset = len(prefix) - for name in self._loader._files.keys(): # type: ignore + for name in self._loader._files.keys(): # Find names under the templates directory that aren't directories. if name.startswith(prefix) and name[-1] != os.path.sep: results.append(name[offset:].replace(os.path.sep, "/")) diff --git a/contrib/python/Jinja2/py3/jinja2/nativetypes.py b/contrib/python/Jinja2/py3/jinja2/nativetypes.py index ac08610348..71db8cc31f 100644 --- a/contrib/python/Jinja2/py3/jinja2/nativetypes.py +++ b/contrib/python/Jinja2/py3/jinja2/nativetypes.py @@ -106,7 +106,7 @@ class NativeTemplate(Template): try: return self.environment_class.concat( # type: ignore - self.root_render_func(ctx) # type: ignore + self.root_render_func(ctx) ) except Exception: return self.environment.handle_exception() diff --git a/contrib/python/Jinja2/py3/jinja2/parser.py b/contrib/python/Jinja2/py3/jinja2/parser.py index cefce2dfa1..3354bc9339 100644 --- a/contrib/python/Jinja2/py3/jinja2/parser.py +++ b/contrib/python/Jinja2/py3/jinja2/parser.py @@ -311,12 +311,14 @@ class Parser: # enforce that required blocks only contain whitespace or comments # by asserting that the body, if not empty, is just TemplateData nodes # with whitespace data - if node.required and not all( - isinstance(child, nodes.TemplateData) and child.data.isspace() - for body in node.body - for child in body.nodes # type: ignore - ): - self.fail("Required blocks can only contain comments or whitespace") + if node.required: + for body_node in node.body: + if not isinstance(body_node, nodes.Output) or any( + not isinstance(output_node, nodes.TemplateData) + or not output_node.data.isspace() + for output_node in body_node.nodes + ): + self.fail("Required blocks can only contain comments or whitespace") self.stream.skip_if("name:" + node.name) return node @@ -857,7 +859,7 @@ class Parser: else: args.append(None) - return nodes.Slice(lineno=lineno, *args) + return nodes.Slice(lineno=lineno, *args) # noqa: B026 def parse_call_args(self) -> t.Tuple: token = self.stream.expect("lparen") diff --git a/contrib/python/Jinja2/py3/jinja2/runtime.py b/contrib/python/Jinja2/py3/jinja2/runtime.py index 985842b284..58a540ba3f 100644 --- a/contrib/python/Jinja2/py3/jinja2/runtime.py +++ b/contrib/python/Jinja2/py3/jinja2/runtime.py @@ -272,9 +272,9 @@ class Context: # Allow callable classes to take a context if ( hasattr(__obj, "__call__") # noqa: B004 - and _PassArg.from_obj(__obj.__call__) is not None # type: ignore + and _PassArg.from_obj(__obj.__call__) is not None ): - __obj = __obj.__call__ # type: ignore + __obj = __obj.__call__ pass_arg = _PassArg.from_obj(__obj) @@ -927,9 +927,7 @@ def make_logging_undefined( logger.addHandler(logging.StreamHandler(sys.stderr)) def _log_message(undef: Undefined) -> None: - logger.warning( # type: ignore - "Template variable warning: %s", undef._undefined_message - ) + logger.warning("Template variable warning: %s", undef._undefined_message) class LoggingUndefined(base): # type: ignore __slots__ = () diff --git a/contrib/python/Jinja2/py3/jinja2/utils.py b/contrib/python/Jinja2/py3/jinja2/utils.py index 9b5f5a50eb..18914a58fd 100644 --- a/contrib/python/Jinja2/py3/jinja2/utils.py +++ b/contrib/python/Jinja2/py3/jinja2/utils.py @@ -182,7 +182,7 @@ def object_type_repr(obj: t.Any) -> str: def pformat(obj: t.Any) -> str: """Format an object using :func:`pprint.pformat`.""" - from pprint import pformat # type: ignore + from pprint import pformat return pformat(obj) @@ -259,7 +259,7 @@ def urlize( if trim_url_limit is not None: def trim_url(x: str) -> str: - if len(x) > trim_url_limit: # type: ignore + if len(x) > trim_url_limit: return f"{x[:trim_url_limit]}..." return x diff --git a/contrib/python/Jinja2/py3/tests/test_ext.py b/contrib/python/Jinja2/py3/tests/test_ext.py index 2e842e0ab5..0b48ca2586 100644 --- a/contrib/python/Jinja2/py3/tests/test_ext.py +++ b/contrib/python/Jinja2/py3/tests/test_ext.py @@ -7,6 +7,7 @@ from jinja2 import DictLoader from jinja2 import Environment from jinja2 import nodes from jinja2 import pass_context +from jinja2 import TemplateSyntaxError from jinja2.exceptions import TemplateAssertionError from jinja2.ext import Extension from jinja2.lexer import count_newlines @@ -468,6 +469,18 @@ class TestInternationalization: (3, "npgettext", ("babel", "%(users)s user", "%(users)s users", None), []), ] + def test_nested_trans_error(self): + s = "{% trans %}foo{% trans %}{% endtrans %}" + with pytest.raises(TemplateSyntaxError) as excinfo: + i18n_env.from_string(s) + assert "trans blocks can't be nested" in str(excinfo.value) + + def test_trans_block_error(self): + s = "{% trans %}foo{% wibble bar %}{% endwibble %}{% endtrans %}" + with pytest.raises(TemplateSyntaxError) as excinfo: + i18n_env.from_string(s) + assert "saw `wibble`" in str(excinfo.value) + class TestScope: def test_basic_scope_behavior(self): diff --git a/contrib/python/Jinja2/py3/tests/test_filters.py b/contrib/python/Jinja2/py3/tests/test_filters.py index 73f0f0be3c..f50ed13ab5 100644 --- a/contrib/python/Jinja2/py3/tests/test_filters.py +++ b/contrib/python/Jinja2/py3/tests/test_filters.py @@ -474,6 +474,12 @@ class TestFilter: assert 'bar="23"' in out assert 'blub:blub="<?>"' in out + def test_xmlattr_key_with_spaces(self, env): + with pytest.raises(ValueError, match="Spaces are not allowed"): + env.from_string( + "{{ {'src=1 onerror=alert(1)': 'my_class'}|xmlattr }}" + ).render() + def test_sort1(self, env): tmpl = env.from_string("{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}") assert tmpl.render() == "[1, 2, 3]|[3, 2, 1]" @@ -870,4 +876,6 @@ class TestFilter: with pytest.raises(TemplateRuntimeError, match="No filter named 'f'"): t1.render(x=42) + + with pytest.raises(TemplateRuntimeError, match="No filter named 'f'"): t2.render(x=42) diff --git a/contrib/python/Jinja2/py3/tests/test_inheritance.py b/contrib/python/Jinja2/py3/tests/test_inheritance.py index 0c20d4da7d..0a525e7ac9 100644 --- a/contrib/python/Jinja2/py3/tests/test_inheritance.py +++ b/contrib/python/Jinja2/py3/tests/test_inheritance.py @@ -287,26 +287,34 @@ class TestInheritance: env = Environment( loader=DictLoader( { - "default": "{% block x required %}data {# #}{% endblock %}", - "default1": "{% block x required %}{% block y %}" - "{% endblock %} {% endblock %}", - "default2": "{% block x required %}{% if true %}" - "{% endif %} {% endblock %}", - "level1": "{% if default %}{% extends default %}" - "{% else %}{% extends 'default' %}{% endif %}" - "{%- block x %}CHILD{% endblock %}", + "empty": "{% block x required %}{% endblock %}", + "blank": "{% block x required %} {# c #}{% endblock %}", + "text": "{% block x required %}data {# c #}{% endblock %}", + "block": "{% block x required %}{% block y %}" + "{% endblock %}{% endblock %}", + "if": "{% block x required %}{% if true %}" + "{% endif %}{% endblock %}", + "top": "{% extends t %}{% block x %}CHILD{% endblock %}", } ) ) - t = env.get_template("level1") + t = env.get_template("top") + assert t.render(t="empty") == "CHILD" + assert t.render(t="blank") == "CHILD" - with pytest.raises( + required_block_check = pytest.raises( TemplateSyntaxError, match="Required blocks can only contain comments or whitespace", - ): - assert t.render(default="default") - assert t.render(default="default2") - assert t.render(default="default3") + ) + + with required_block_check: + t.render(t="text") + + with required_block_check: + t.render(t="block") + + with required_block_check: + t.render(t="if") def test_required_with_scope(self, env): env = Environment( @@ -347,8 +355,11 @@ class TestInheritance: ) ) tmpl = env.get_template("child") + with pytest.raises(TemplateSyntaxError): tmpl.render(default="default1", seq=list(range(3))) + + with pytest.raises(TemplateSyntaxError): tmpl.render(default="default2", seq=list(range(3))) diff --git a/contrib/python/Jinja2/py3/tests/test_loader.py b/contrib/python/Jinja2/py3/tests/test_loader.py index a396e18fec..d3b4ddf1ba 100644 --- a/contrib/python/Jinja2/py3/tests/test_loader.py +++ b/contrib/python/Jinja2/py3/tests/test_loader.py @@ -186,6 +186,7 @@ class TestFileSystemLoader: class TestModuleLoader: archive = None + mod_env = None def compile_down(self, prefix_loader, zip="deflated"): log = [] @@ -199,13 +200,14 @@ class TestModuleLoader: self.mod_env = Environment(loader=loaders.ModuleLoader(self.archive)) return "".join(log) - def teardown(self): - if hasattr(self, "mod_env"): + def teardown_method(self): + if self.archive is not None: if os.path.isfile(self.archive): os.remove(self.archive) else: shutil.rmtree(self.archive) self.archive = None + self.mod_env = None def test_log(self, prefix_loader): log = self.compile_down(prefix_loader) diff --git a/contrib/python/Jinja2/py3/ya.make b/contrib/python/Jinja2/py3/ya.make index 67ba20df0c..2c15cb57d4 100644 --- a/contrib/python/Jinja2/py3/ya.make +++ b/contrib/python/Jinja2/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(3.1.2) +VERSION(3.1.3) LICENSE(BSD-3-Clause) |