MCPcopy
hub / github.com/pallets/jinja / DictLoader

Class DictLoader

src/jinja2/loaders.py:436–457  ·  view source on GitHub ↗

Loads a template from a Python dict mapping template names to template source. This loader is useful for unittesting: >>> loader = DictLoader({'index.html': 'source here'}) Because auto reloading is rarely useful this is disabled by default.

Source from the content-addressed store, hash-verified

434
435
436class DictLoader(BaseLoader):
437 """Loads a template from a Python dict mapping template names to
438 template source. This loader is useful for unittesting:
439
440 >>> loader = DictLoader({'index.html': 'source here'})
441
442 Because auto reloading is rarely useful this is disabled by default.
443 """
444
445 def __init__(self, mapping: t.Mapping[str, str]) -> None:
446 self.mapping = mapping
447
448 def get_source(
449 self, environment: "Environment", template: str
450 ) -> t.Tuple[str, None, t.Callable[[], bool]]:
451 if template in self.mapping:
452 source = self.mapping[template]
453 return source, None, lambda: source == self.mapping.get(template)
454 raise TemplateNotFound(template)
455
456 def list_templates(self) -> t.List[str]:
457 return sorted(self.mapping)
458
459
460class FunctionLoader(BaseLoader):

Callers 15

envFunction · 0.90
test_superMethod · 0.90
test_preserve_blocksMethod · 0.90
test_scoped_blockMethod · 0.90
test_level1_requiredMethod · 0.90
test_level2_requiredMethod · 0.90
test_level3_requiredMethod · 0.90
test_invalid_requiredMethod · 0.90

Calls

no outgoing calls

Tested by 15

envFunction · 0.72
test_superMethod · 0.72
test_preserve_blocksMethod · 0.72
test_scoped_blockMethod · 0.72
test_level1_requiredMethod · 0.72
test_level2_requiredMethod · 0.72
test_level3_requiredMethod · 0.72
test_invalid_requiredMethod · 0.72