A template loader that loads from a dictionary.
| 479 | |
| 480 | |
| 481 | class DictLoader(BaseLoader): |
| 482 | """A template loader that loads from a dictionary.""" |
| 483 | |
| 484 | def __init__(self, dict: Dict[str, str], **kwargs: Any) -> None: |
| 485 | super().__init__(**kwargs) |
| 486 | self.dict = dict |
| 487 | |
| 488 | def resolve_path(self, name: str, parent_path: Optional[str] = None) -> str: |
| 489 | if ( |
| 490 | parent_path |
| 491 | and not parent_path.startswith("<") |
| 492 | and not parent_path.startswith("/") |
| 493 | and not name.startswith("/") |
| 494 | ): |
| 495 | file_dir = posixpath.dirname(parent_path) |
| 496 | name = posixpath.normpath(posixpath.join(file_dir, name)) |
| 497 | return name |
| 498 | |
| 499 | def _create_template(self, name: str) -> Template: |
| 500 | return Template(self.dict[name], name=name, loader=self) |
| 501 | |
| 502 | |
| 503 | class _Node(object): |
no outgoing calls