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 | |
parent | 7a8bf49265109474e1529e1f9fb790e684a0771d (diff) | |
download | ydb-b28ebe1bef50f23bcb3bffac9964e77f13a0058d.tar.gz |
Fix templates (version 2)
47274c98d3db8b857bdc3dc05fbd2beacde038ba
-rw-r--r-- | contrib/python/Flask/py3/flask/scaffold.py | 3 | ||||
-rw-r--r-- | contrib/python/Jinja2/py3/jinja2/loaders.py | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/contrib/python/Flask/py3/flask/scaffold.py b/contrib/python/Flask/py3/flask/scaffold.py index a58941c01d..8f301d9001 100644 --- a/contrib/python/Flask/py3/flask/scaffold.py +++ b/contrib/python/Flask/py3/flask/scaffold.py @@ -10,7 +10,7 @@ from functools import update_wrapper from json import JSONDecoder from json import JSONEncoder -from jinja2 import ChoiceLoader, FileSystemLoader, ResourceLoader +from jinja2 import ChoiceLoader, FileSystemLoader, ResourceLoader, PackageLoader from werkzeug.exceptions import default_exceptions from werkzeug.exceptions import HTTPException @@ -359,6 +359,7 @@ class Scaffold: if self.template_folder is not None: return ChoiceLoader([ FileSystemLoader(os.path.join(self.root_path, self.template_folder)), + PackageLoader(self.import_name, self.template_folder, skip_unknown_package=True), ResourceLoader(os.path.join(self._builtin_resource_prefix, self.template_folder), self.module_loader), ]) else: 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): |