1.21. templates
¶
This module provides base classes for the Jinja2 environments used throughout the application.
1.21.1. Classes¶
-
class
FindFileSystemLoader
[source]¶ Bases:
jinja2.loaders.BaseLoader
A
BaseLoader
which loads templates by name from the file system. Templates are searched for using thedata_file()
function.-
get_source
(environment, template)[source]¶ 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 unicode string or a ASCII bytestring. 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.
-
-
class
TemplateEnvironmentBase
(loader=None, global_vars=None)[source]¶ Bases:
jinja2.environment.Environment
A configured Jinja2
Environment
with additional filters and default settings.-
__init__
(loader=None, global_vars=None)[source]¶ Parameters: - loader (
jinja2.BaseLoader
) – The loader to supply to the environment. - global_vars (dict) – Additional global variables for the environment.
- loader (
-
from_file
(path, **kwargs)[source]¶ A convenience method to load template data from a specified file, passing it to
from_string()
.Warning
Because this method ultimately passes the template data to the
from_string()
method, the data will not be automatically escaped based on the file extension as it would be when usingget_template()
.Parameters: - path (str) – The path from which to load the template data.
- kwargs – Additional keyword arguments to pass to
from_string()
.
-
-
class
MessageTemplateEnvironment
(*args, **kwargs)[source]¶ Bases:
king_phisher.templates.TemplateEnvironmentBase
A configured Jinja2 environment for formatting messages.