(
self, environment: "Environment", template: str
)
| 328 | self._template_root = template_root |
| 329 | |
| 330 | def get_source( |
| 331 | self, environment: "Environment", template: str |
| 332 | ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]: |
| 333 | # Use posixpath even on Windows to avoid "drive:" or UNC |
| 334 | # segments breaking out of the search directory. Use normpath to |
| 335 | # convert Windows altsep to sep. |
| 336 | p = os.path.normpath( |
| 337 | posixpath.join(self._template_root, *split_template_path(template)) |
| 338 | ) |
| 339 | up_to_date: t.Optional[t.Callable[[], bool]] |
| 340 | |
| 341 | if self._archive is None: |
| 342 | # Package is a directory. |
| 343 | if not os.path.isfile(p): |
| 344 | raise TemplateNotFound(template) |
| 345 | |
| 346 | with open(p, "rb") as f: |
| 347 | source = f.read() |
| 348 | |
| 349 | mtime = os.path.getmtime(p) |
| 350 | |
| 351 | def up_to_date() -> bool: |
| 352 | return os.path.isfile(p) and os.path.getmtime(p) == mtime |
| 353 | |
| 354 | else: |
| 355 | # Package is a zip file. |
| 356 | try: |
| 357 | source = self._loader.get_data(p) # type: ignore |
| 358 | except OSError as e: |
| 359 | raise TemplateNotFound(template) from e |
| 360 | |
| 361 | # Could use the zip's mtime for all template mtimes, but |
| 362 | # would need to safely reload the module if it's out of |
| 363 | # date, so just report it as always current. |
| 364 | up_to_date = None |
| 365 | |
| 366 | return source.decode(self.encoding), p, up_to_date |
| 367 | |
| 368 | def list_templates(self) -> t.List[str]: |
| 369 | results: t.List[str] = [] |
nothing calls this directly
no test coverage detected