diff options
author | shadchin <shadchin@yandex-team.com> | 2024-07-22 10:46:36 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2024-07-22 10:57:10 +0300 |
commit | b28ebe1bef50f23bcb3bffac9964e77f13a0058d (patch) | |
tree | b3ae6dcf6b966809df80dc5d9743fc87ed855314 /contrib/python/Jinja2/py3/jinja2/loaders.py | |
parent | 7a8bf49265109474e1529e1f9fb790e684a0771d (diff) | |
download | ydb-b28ebe1bef50f23bcb3bffac9964e77f13a0058d.tar.gz |
Fix templates (version 2)
47274c98d3db8b857bdc3dc05fbd2beacde038ba
Diffstat (limited to 'contrib/python/Jinja2/py3/jinja2/loaders.py')
-rw-r--r-- | contrib/python/Jinja2/py3/jinja2/loaders.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/contrib/python/Jinja2/py3/jinja2/loaders.py b/contrib/python/Jinja2/py3/jinja2/loaders.py index b69ef29859..c36ae77e15 100644 --- a/contrib/python/Jinja2/py3/jinja2/loaders.py +++ b/contrib/python/Jinja2/py3/jinja2/loaders.py @@ -279,6 +279,7 @@ class PackageLoader(BaseLoader): package_name: str, package_path: "str" = "templates", encoding: str = "utf-8", + skip_unknown_package: bool = False, ) -> None: package_path = os.path.normpath(package_path).rstrip(os.path.sep) @@ -291,6 +292,7 @@ class PackageLoader(BaseLoader): self.package_path = package_path self.package_name = package_name self.encoding = encoding + self.skip_unknown_package = skip_unknown_package # Make sure the package exists. This also makes namespace # packages work, otherwise get_loader returns None. @@ -328,7 +330,7 @@ class PackageLoader(BaseLoader): template_root = root break - if template_root is None: + if template_root is None and not skip_unknown_package: raise ValueError( f"The {package_name!r} package was not installed in a" " way that PackageLoader understands." @@ -339,6 +341,9 @@ class PackageLoader(BaseLoader): def get_source( self, environment: "Environment", template: str ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]: + if self._template_root is None and self.skip_unknown_package: + raise TemplateNotFound(template) + # Use posixpath even on Windows to avoid "drive:" or UNC # segments breaking out of the search directory. Use normpath to # convert Windows altsep to sep. @@ -386,6 +391,9 @@ class PackageLoader(BaseLoader): def list_templates(self) -> t.List[str]: results: t.List[str] = [] + if self._template_root is None and self.skip_unknown_package: + return results + if self._archive is None and hasattr(self, "_package"): prefix = os.path.join(self._template_root, self.package_path).encode() + b"/" for name in arcadia_res.resfs_files(prefix): |