Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
jinja2.loaders.BaseLoader Class Reference
Inheritance diagram for jinja2.loaders.BaseLoader:
Inheritance graph
[legend]

Public Member Functions

t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]] get_source (self, "Environment" environment, str template)
 
t.List[str] list_templates (self)
 
"Template" load (self, "Environment" environment, str name, t.Optional[t.MutableMapping[str, t.Any]] globals=None)
 

Static Public Attributes

bool has_source_access = True
 

Detailed Description

Baseclass for all loaders.  Subclass this and override `get_source` to
implement a custom loading mechanism.  The environment provides a
`get_template` method that calls the loader's `load` method to get the
:class:`Template` object.

A very basic example for a loader that looks up templates on the file
system could look like this::

    from jinja2 import BaseLoader, TemplateNotFound
    from os.path import join, exists, getmtime

    class MyLoader(BaseLoader):

        def __init__(self, path):
            self.path = path

        def get_source(self, environment, template):
            path = join(self.path, template)
            if not exists(path):
                raise TemplateNotFound(template)
            mtime = getmtime(path)
            with open(path) as f:
                source = f.read()
            return source, path, lambda: mtime == getmtime(path)

Member Function Documentation

◆ get_source()

t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]] jinja2.loaders.BaseLoader.get_source (   self,
"Environment"  environment,
str   template 
)
Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template.

The source part of the returned tuple must be the source of the
template as a string. The filename should be the name of the
file on the filesystem if it was loaded from there, otherwise
``None``. The filename is used by Python for the tracebacks
if no loader extension is used.

The last item in the tuple is the `uptodate` function.  If auto
reloading is enabled it's always called to check if the template
changed.  No arguments are passed so the function must store the
old state somewhere (for example in a closure).  If it returns `False`
the template will be reloaded.

Reimplemented in jinja2.loaders.FileSystemLoader, jinja2.loaders.PackageLoader, jinja2.loaders.DictLoader, jinja2.loaders.FunctionLoader, jinja2.loaders.PrefixLoader, jinja2.loaders.ChoiceLoader, sphinx.jinja2glue.SphinxFileSystemLoader, sphinx.jinja2glue.BuiltinTemplateLoader, and sphinx.util.template.SphinxTemplateLoader.

◆ list_templates()

t.List[str] jinja2.loaders.BaseLoader.list_templates (   self)
Iterates over all templates.  If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.

Reimplemented in jinja2.loaders.FileSystemLoader, jinja2.loaders.PackageLoader, jinja2.loaders.DictLoader, jinja2.loaders.PrefixLoader, and jinja2.loaders.ChoiceLoader.

◆ load()

"Template" jinja2.loaders.BaseLoader.load (   self,
"Environment"  environment,
str  name,
t.Optional[t.MutableMapping[str, t.Any]]   globals = None 
)
Loads a template.  This method looks up the template in the cache
or loads one by calling :meth:`get_source`.  Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
will not call this method but `get_source` directly.

Reimplemented in jinja2.loaders.PrefixLoader, jinja2.loaders.ChoiceLoader, and jinja2.loaders.ModuleLoader.


The documentation for this class was generated from the following file: