|
@@ -16,7 +16,6 @@ from types import ModuleType
|
|
|
|
|
|
from .exceptions import TemplateNotFound
|
|
from .exceptions import TemplateNotFound
|
|
from .utils import internalcode
|
|
from .utils import internalcode
|
|
-from .utils import open_if_exists
|
|
|
|
|
|
|
|
if t.TYPE_CHECKING:
|
|
if t.TYPE_CHECKING:
|
|
from .environment import Environment
|
|
from .environment import Environment
|
|
@@ -196,29 +195,30 @@ class FileSystemLoader(BaseLoader):
|
|
self, environment: "Environment", template: str
|
|
self, environment: "Environment", template: str
|
|
) -> t.Tuple[str, str, t.Callable[[], bool]]:
|
|
) -> t.Tuple[str, str, t.Callable[[], bool]]:
|
|
pieces = split_template_path(template)
|
|
pieces = split_template_path(template)
|
|
|
|
+
|
|
for searchpath in self.searchpath:
|
|
for searchpath in self.searchpath:
|
|
# Use posixpath even on Windows to avoid "drive:" or UNC
|
|
# Use posixpath even on Windows to avoid "drive:" or UNC
|
|
# segments breaking out of the search directory.
|
|
# segments breaking out of the search directory.
|
|
filename = posixpath.join(searchpath, *pieces)
|
|
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]:
|
|
def list_templates(self) -> t.List[str]:
|
|
found = set()
|
|
found = set()
|
|
@@ -412,7 +412,7 @@ class PackageLoader(BaseLoader):
|
|
)
|
|
)
|
|
offset = len(prefix)
|
|
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.
|
|
# Find names under the templates directory that aren't directories.
|
|
if name.startswith(prefix) and name[-1] != os.path.sep:
|
|
if name.startswith(prefix) and name[-1] != os.path.sep:
|
|
results.append(name[offset:].replace(os.path.sep, "/"))
|
|
results.append(name[offset:].replace(os.path.sep, "/"))
|