class documentation

Undocumented

Method __init__ Undocumented
Method blockvisit Visit a list of nodes as block in a frame. If the current frame is no buffer a dummy ``if 0: yield None`` is written automatically.
Method buffer Enable buffering for the frame from that point onwards.
Method choose_async Undocumented
Method derive_context Undocumented
Method dump_local_context Undocumented
Method end_write End the writing process started by `start_write`.
Method enter_frame Undocumented
Method fail Fail with a :exc:`TemplateAssertionError`.
Method func Undocumented
Method get_context_ref Undocumented
Method get_resolve_func Undocumented
Method indent Indent by one.
Method leave_frame Undocumented
Method macro_body Dump the function def of a macro or call block.
Method macro_def Dump the macro definition for the def created by macro_body.
Method mark_parameter_stored Marks a parameter in the current parameter definitions as stored. This will skip the enforced undefined checks.
Method newline Add one or more newlines before the next write.
Method outdent Outdent by step.
Method parameter_is_undeclared Checks if a given target is an undeclared parameter.
Method pop_assign_tracking Pops the topmost level for assignment tracking and updates the context variables if necessary.
Method pop_context_reference Undocumented
Method pop_parameter_definitions Pops the current parameter definitions set.
Method position Return a human readable position for the node.
Method pull_dependencies Find all filter and test names used in the template and assign them to variables in the compiled namespace. Checking that the names are registered with the environment is done when compiling the Filter and Test nodes...
Method push_assign_tracking Pushes a new layer for assignment tracking.
Method push_context_reference Undocumented
Method push_parameter_definitions Pushes all parameter targets from the given frame into a local stack that permits tracking of yet to be assigned parameters. In particular this enables the optimization from `visit_Name` to skip undefined expressions for parameters in macros as macros can reference otherwise unbound parameters.
Method return_buffer_contents Return the buffer contents of the frame.
Method signature Writes a function call to the stream for the current node. A leading comma is added automatically. The extra keyword arguments may not include python keywords otherwise a syntax error could occur. The extra keyword arguments should be given as python dict.
Method simple_write Simple shortcut for start_write + write + end_write.
Method start_write Yield or write into the frame buffer.
Method temporary_identifier Get a new unique identifier.
Method visit_Assign Undocumented
Method visit_AssignBlock Undocumented
Method visit_Block Call a block and register it for the template.
Method visit_Break Undocumented
Method visit_Call Undocumented
Method visit_CallBlock Undocumented
Method visit_Compare Undocumented
Method visit_Concat Undocumented
Method visit_CondExpr Undocumented
Method visit_Const Undocumented
Method visit_ContextReference Undocumented
Method visit_Continue Undocumented
Method visit_DerivedContextReference Undocumented
Method visit_Dict Undocumented
Method visit_EnvironmentAttribute Undocumented
Method visit_EvalContextModifier Undocumented
Method visit_ExprStmt Undocumented
Method visit_Extends Calls the extender.
Method visit_ExtensionAttribute Undocumented
Method visit_Filter Undocumented
Method visit_FilterBlock Undocumented
Method visit_For Undocumented
Method visit_FromImport Visit named imports.
Method visit_Getattr Undocumented
Method visit_Getitem Undocumented
Method visit_If Undocumented
Method visit_Import Visit regular imports.
Method visit_ImportedName Undocumented
Method visit_Include Handles includes.
Method visit_InternalName Undocumented
Method visit_Keyword Undocumented
Method visit_List Undocumented
Method visit_Macro Undocumented
Method visit_MarkSafe Undocumented
Method visit_MarkSafeIfAutoescape Undocumented
Method visit_Name Undocumented
Method visit_NSRef Undocumented
Method visit_Operand Undocumented
Method visit_Output Undocumented
Method visit_OverlayScope Undocumented
Method visit_Scope Undocumented
Method visit_ScopedEvalContextModifier Undocumented
Method visit_Slice Undocumented
Method visit_Template Undocumented
Method visit_TemplateData Undocumented
Method visit_Test Undocumented
Method visit_Tuple Undocumented
Method visit_With Undocumented
Method write Write a string into the output stream.
Method write_commons Writes a common preamble that is used by root and block functions. Primarily this sets up common local helpers and enforces a generator through a dead branch.
Method writeline Combination of newline and write.
Class Variable visit_Add Undocumented
Class Variable visit_And Undocumented
Class Variable visit_Div Undocumented
Class Variable visit_FloorDiv Undocumented
Class Variable visit_Mod Undocumented
Class Variable visit_Mul Undocumented
Class Variable visit_Neg Undocumented
Class Variable visit_Not Undocumented
Class Variable visit_Or Undocumented
Class Variable visit_Pos Undocumented
Class Variable visit_Pow Undocumented
Class Variable visit_Sub Undocumented
Instance Variable blocks Undocumented
Instance Variable code_lineno Undocumented
Instance Variable created_block_context Undocumented
Instance Variable debug_info Undocumented
Instance Variable defer_init Undocumented
Instance Variable environment Undocumented
Instance Variable extends_so_far Undocumented
Instance Variable filename Undocumented
Instance Variable filters Undocumented
Instance Variable has_known_extends Undocumented
Instance Variable import_aliases Undocumented
Instance Variable name Undocumented
Instance Variable optimizer Undocumented
Instance Variable stream Undocumented
Instance Variable tests Undocumented
Property optimized Undocumented
Class _FinalizeInfo Undocumented
Static Method _default_finalize The default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants.
Method _filter_test_common Undocumented
Method _import_common Undocumented
Method _make_finalize Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes.
Method _output_child_post Output extra source code after visiting a child of an ``Output`` node.
Method _output_child_pre Output extra source code before visiting a child of an ``Output`` node.
Method _output_child_to_const Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time.
Method _output_const_repr Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source.
Instance Variable _assign_stack Undocumented
Instance Variable _context_reference_stack Undocumented
Instance Variable _finalize Undocumented
Instance Variable _first_write Undocumented
Instance Variable _indentation Undocumented
Instance Variable _last_identifier Undocumented
Instance Variable _last_line Undocumented
Instance Variable _new_lines Undocumented
Instance Variable _param_def_block Undocumented
Instance Variable _write_debug_info Undocumented

Inherited from NodeVisitor:

Method generic_visit Called if no explicit visitor function exists for a node.
Method get_visitor Return the visitor function for this node or `None` if no visitor exists for this node. In that case the generic visit function is used instead.
Method visit Visit a node.
def __init__(self, environment, name, filename, stream=None, defer_init=False, optimized=True): (source)

Undocumented

Parameters
environment:EnvironmentUndocumented
name:t.Optional[str]Undocumented
filename:t.Optional[str]Undocumented
stream:t.Optional[t.TextIO]Undocumented
defer_init:boolUndocumented
optimized:boolUndocumented
def blockvisit(self, nodes, frame): (source)

Visit a list of nodes as block in a frame. If the current frame is no buffer a dummy ``if 0: yield None`` is written automatically.

Parameters
nodes:t.Iterable[nodes.Node]Undocumented
frame:FrameUndocumented
def buffer(self, frame): (source)

Enable buffering for the frame from that point onwards.

Parameters
frame:FrameUndocumented
def choose_async(self, async_value='async ', sync_value=''): (source)

Undocumented

Parameters
async_value:strUndocumented
sync_value:strUndocumented
Returns
strUndocumented
def derive_context(self, frame): (source)

Undocumented

Parameters
frame:FrameUndocumented
Returns
strUndocumented
def dump_local_context(self, frame): (source)

Undocumented

Parameters
frame:FrameUndocumented
Returns
strUndocumented
def end_write(self, frame): (source)

End the writing process started by `start_write`.

Parameters
frame:FrameUndocumented
def enter_frame(self, frame): (source)

Undocumented

Parameters
frame:FrameUndocumented
def fail(self, msg, lineno): (source)

Fail with a :exc:`TemplateAssertionError`.

Parameters
msg:strUndocumented
lineno:intUndocumented
Returns
te.NoReturnUndocumented
def func(self, name): (source)

Undocumented

Parameters
name:strUndocumented
Returns
strUndocumented
def get_context_ref(self): (source)

Undocumented

Returns
strUndocumented
def get_resolve_func(self): (source)

Undocumented

Returns
strUndocumented
def indent(self): (source)

Indent by one.

def leave_frame(self, frame, with_python_scope=False): (source)

Undocumented

Parameters
frame:FrameUndocumented
with_python_scope:boolUndocumented
def macro_body(self, node, frame): (source)

Dump the function def of a macro or call block.

Parameters
node:t.Union[nodes.Macro, nodes.CallBlock]Undocumented
frame:FrameUndocumented
Returns
t.Tuple[Frame, MacroRef]Undocumented
def macro_def(self, macro_ref, frame): (source)

Dump the macro definition for the def created by macro_body.

Parameters
macro_ref:MacroRefUndocumented
frame:FrameUndocumented
def mark_parameter_stored(self, target): (source)

Marks a parameter in the current parameter definitions as stored. This will skip the enforced undefined checks.

Parameters
target:strUndocumented
def newline(self, node=None, extra=0): (source)

Add one or more newlines before the next write.

Parameters
node:t.Optional[nodes.Node]Undocumented
extra:intUndocumented
def outdent(self, step=1): (source)

Outdent by step.

Parameters
step:intUndocumented
def parameter_is_undeclared(self, target): (source)

Checks if a given target is an undeclared parameter.

Parameters
target:strUndocumented
Returns
boolUndocumented
def pop_assign_tracking(self, frame): (source)

Pops the topmost level for assignment tracking and updates the context variables if necessary.

Parameters
frame:FrameUndocumented
def pop_context_reference(self): (source)

Undocumented

def pop_parameter_definitions(self): (source)

Pops the current parameter definitions set.

def position(self, node): (source)

Return a human readable position for the node.

Parameters
node:nodes.NodeUndocumented
Returns
strUndocumented
def pull_dependencies(self, nodes): (source)

Find all filter and test names used in the template and assign them to variables in the compiled namespace. Checking that the names are registered with the environment is done when compiling the Filter and Test nodes. If the node is in an If or CondExpr node, the check is done at runtime instead. .. versionchanged:: 3.0 Filters and tests in If and CondExpr nodes are checked at runtime instead of compile time.

Parameters
nodes:t.Iterable[nodes.Node]Undocumented
def push_assign_tracking(self): (source)

Pushes a new layer for assignment tracking.

def push_context_reference(self, target): (source)

Undocumented

Parameters
target:strUndocumented
def push_parameter_definitions(self, frame): (source)

Pushes all parameter targets from the given frame into a local stack that permits tracking of yet to be assigned parameters. In particular this enables the optimization from `visit_Name` to skip undefined expressions for parameters in macros as macros can reference otherwise unbound parameters.

Parameters
frame:FrameUndocumented
def return_buffer_contents(self, frame, force_unescaped=False): (source)

Return the buffer contents of the frame.

Parameters
frame:FrameUndocumented
force_unescaped:boolUndocumented
def signature(self, node, frame, extra_kwargs=None): (source)

Writes a function call to the stream for the current node. A leading comma is added automatically. The extra keyword arguments may not include python keywords otherwise a syntax error could occur. The extra keyword arguments should be given as python dict.

Parameters
node:t.Union[nodes.Call, nodes.Filter, nodes.Test]Undocumented
frame:FrameUndocumented
extra_kwargs:t.Optional[t.Mapping[str, t.Any]]Undocumented
def simple_write(self, s, frame, node=None): (source)

Simple shortcut for start_write + write + end_write.

Parameters
s:strUndocumented
frame:FrameUndocumented
node:t.Optional[nodes.Node]Undocumented
def start_write(self, frame, node=None): (source)

Yield or write into the frame buffer.

Parameters
frame:FrameUndocumented
node:t.Optional[nodes.Node]Undocumented
def temporary_identifier(self): (source)

Get a new unique identifier.

Returns
strUndocumented
def visit_Assign(self, node, frame): (source)

Undocumented

Parameters
node:nodes.AssignUndocumented
frame:FrameUndocumented
def visit_AssignBlock(self, node, frame): (source)

Undocumented

Parameters
node:nodes.AssignBlockUndocumented
frame:FrameUndocumented
def visit_Block(self, node, frame): (source)

Call a block and register it for the template.

Parameters
node:nodes.BlockUndocumented
frame:FrameUndocumented
def visit_Break(self, node, frame): (source)

Undocumented

Parameters
node:nodes.BreakUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Call(self, node, frame, forward_caller=False): (source)

Undocumented

Parameters
node:nodes.CallUndocumented
frame:FrameUndocumented
forward_caller:boolUndocumented
def visit_CallBlock(self, node, frame): (source)

Undocumented

Parameters
node:nodes.CallBlockUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Compare(self, node, frame): (source)

Undocumented

Parameters
node:nodes.CompareUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Concat(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ConcatUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_CondExpr(self, node, frame): (source)

Undocumented

Parameters
node:nodes.CondExprUndocumented
frame:FrameUndocumented
def visit_Const(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ConstUndocumented
frame:FrameUndocumented
def visit_ContextReference(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ContextReferenceUndocumented
frame:FrameUndocumented
def visit_Continue(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ContinueUndocumented
frame:FrameUndocumented
def visit_DerivedContextReference(self, node, frame): (source)

Undocumented

Parameters
node:nodes.DerivedContextReferenceUndocumented
frame:FrameUndocumented
def visit_Dict(self, node, frame): (source)

Undocumented

Parameters
node:nodes.DictUndocumented
frame:FrameUndocumented
def visit_EnvironmentAttribute(self, node, frame): (source)

Undocumented

Parameters
node:nodes.EnvironmentAttributeUndocumented
frame:FrameUndocumented
def visit_EvalContextModifier(self, node, frame): (source)

Undocumented

Parameters
node:nodes.EvalContextModifierUndocumented
frame:FrameUndocumented
def visit_ExprStmt(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ExprStmtUndocumented
frame:FrameUndocumented
def visit_Extends(self, node, frame): (source)

Calls the extender.

Parameters
node:nodes.ExtendsUndocumented
frame:FrameUndocumented
def visit_ExtensionAttribute(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ExtensionAttributeUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Filter(self, node, frame): (source)

Undocumented

Parameters
node:nodes.FilterUndocumented
frame:FrameUndocumented
def visit_FilterBlock(self, node, frame): (source)

Undocumented

Parameters
node:nodes.FilterBlockUndocumented
frame:FrameUndocumented
def visit_For(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ForUndocumented
frame:FrameUndocumented
def visit_FromImport(self, node, frame): (source)

Visit named imports.

Parameters
node:nodes.FromImportUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Getattr(self, node, frame): (source)

Undocumented

Parameters
node:nodes.GetattrUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Getitem(self, node, frame): (source)

Undocumented

Parameters
node:nodes.GetitemUndocumented
frame:FrameUndocumented
def visit_If(self, node, frame): (source)

Undocumented

Parameters
node:nodes.IfUndocumented
frame:FrameUndocumented
def visit_Import(self, node, frame): (source)

Visit regular imports.

Parameters
node:nodes.ImportUndocumented
frame:FrameUndocumented
def visit_ImportedName(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ImportedNameUndocumented
frame:FrameUndocumented
def visit_Include(self, node, frame): (source)

Handles includes.

Parameters
node:nodes.IncludeUndocumented
frame:FrameUndocumented
def visit_InternalName(self, node, frame): (source)

Undocumented

Parameters
node:nodes.InternalNameUndocumented
frame:FrameUndocumented
def visit_Keyword(self, node, frame): (source)

Undocumented

Parameters
node:nodes.KeywordUndocumented
frame:FrameUndocumented
def visit_List(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ListUndocumented
frame:FrameUndocumented
def visit_Macro(self, node, frame): (source)

Undocumented

Parameters
node:nodes.MacroUndocumented
frame:FrameUndocumented
def visit_MarkSafe(self, node, frame): (source)

Undocumented

Parameters
node:nodes.MarkSafeUndocumented
frame:FrameUndocumented
def visit_MarkSafeIfAutoescape(self, node, frame): (source)

Undocumented

Parameters
node:nodes.MarkSafeIfAutoescapeUndocumented
frame:FrameUndocumented
def visit_Name(self, node, frame): (source)

Undocumented

Parameters
node:nodes.NameUndocumented
frame:FrameUndocumented
def visit_NSRef(self, node, frame): (source)

Undocumented

Parameters
node:nodes.NSRefUndocumented
frame:FrameUndocumented
def visit_Operand(self, node, frame): (source)

Undocumented

Parameters
node:nodes.OperandUndocumented
frame:FrameUndocumented
def visit_Output(self, node, frame): (source)

Undocumented

Parameters
node:nodes.OutputUndocumented
frame:FrameUndocumented
def visit_OverlayScope(self, node, frame): (source)

Undocumented

Parameters
node:nodes.OverlayScopeUndocumented
frame:FrameUndocumented
def visit_Scope(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ScopeUndocumented
frame:FrameUndocumented
def visit_ScopedEvalContextModifier(self, node, frame): (source)

Undocumented

Parameters
node:nodes.ScopedEvalContextModifierUndocumented
frame:FrameUndocumented
def visit_Slice(self, node, frame): (source)

Undocumented

Parameters
node:nodes.SliceUndocumented
frame:FrameUndocumented
def visit_Template(self, node, frame=None): (source)

Undocumented

Parameters
node:nodes.TemplateUndocumented
frame:t.Optional[Frame]Undocumented
def visit_TemplateData(self, node, frame): (source)

Undocumented

Parameters
node:nodes.TemplateDataUndocumented
frame:FrameUndocumented
@optimizeconst
def visit_Test(self, node, frame): (source)

Undocumented

Parameters
node:nodes.TestUndocumented
frame:FrameUndocumented
def visit_Tuple(self, node, frame): (source)

Undocumented

Parameters
node:nodes.TupleUndocumented
frame:FrameUndocumented
def visit_With(self, node, frame): (source)

Undocumented

Parameters
node:nodes.WithUndocumented
frame:FrameUndocumented
def write(self, x): (source)

Write a string into the output stream.

Parameters
x:strUndocumented
def write_commons(self): (source)

Writes a common preamble that is used by root and block functions. Primarily this sets up common local helpers and enforces a generator through a dead branch.

def writeline(self, x, node=None, extra=0): (source)

Combination of newline and write.

Parameters
x:strUndocumented
node:t.Optional[nodes.Node]Undocumented
extra:intUndocumented
visit_Add = (source)

Undocumented

visit_And = (source)

Undocumented

visit_Div = (source)

Undocumented

visit_FloorDiv = (source)

Undocumented

visit_Mod = (source)

Undocumented

visit_Mul = (source)

Undocumented

visit_Neg = (source)

Undocumented

visit_Not = (source)

Undocumented

visit_Or = (source)

Undocumented

visit_Pos = (source)

Undocumented

visit_Pow = (source)

Undocumented

visit_Sub = (source)

Undocumented

Undocumented

code_lineno: int = (source)

Undocumented

created_block_context: bool = (source)

Undocumented

debug_info: t.List[t.Tuple[int, int]] = (source)

Undocumented

defer_init = (source)

Undocumented

environment = (source)

Undocumented

extends_so_far: int = (source)

Undocumented

filename = (source)

Undocumented

filters: t.Dict[str, str] = (source)

Undocumented

has_known_extends: bool = (source)

Undocumented

import_aliases: t.Dict[str, str] = (source)

Undocumented

name = (source)

Undocumented

optimizer = (source)

Undocumented

stream = (source)

Undocumented

Undocumented

@property
optimized: bool = (source)

Undocumented

@staticmethod
def _default_finalize(value): (source)

The default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants.

Parameters
value:t.AnyUndocumented
Returns
t.AnyUndocumented
@contextmanager
def _filter_test_common(self, node, frame, is_filter): (source)

Undocumented

Parameters
node:t.Union[nodes.Filter, nodes.Test]Undocumented
frame:FrameUndocumented
is_filter:boolUndocumented
Returns
t.Iterator[None]Undocumented
def _import_common(self, node, frame): (source)

Undocumented

Parameters
node:t.Union[nodes.Import, nodes.FromImport]Undocumented
frame:FrameUndocumented
def _make_finalize(self): (source)

Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes. Returns a ``namedtuple`` with the following attributes: ``const`` A function to finalize constant data at compile time. ``src`` Source code to output around nodes to be evaluated at runtime.

Returns
_FinalizeInfoUndocumented
def _output_child_post(self, node, frame, finalize): (source)

Output extra source code after visiting a child of an ``Output`` node.

Parameters
node:nodes.ExprUndocumented
frame:FrameUndocumented
finalize:_FinalizeInfoUndocumented
def _output_child_pre(self, node, frame, finalize): (source)

Output extra source code before visiting a child of an ``Output`` node.

Parameters
node:nodes.ExprUndocumented
frame:FrameUndocumented
finalize:_FinalizeInfoUndocumented
def _output_child_to_const(self, node, frame, finalize): (source)

Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. If :exc:`Impossible` is raised, the node is not constant and will be evaluated at runtime. Any other exception will also be evaluated at runtime for easier debugging.

Parameters
node:nodes.ExprUndocumented
frame:FrameUndocumented
finalize:_FinalizeInfoUndocumented
Returns
strUndocumented
def _output_const_repr(self, group): (source)

Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source.

Parameters
group:t.Iterable[t.Any]Undocumented
Returns
strUndocumented
_assign_stack: t.List[t.Set[str]] = (source)

Undocumented

_context_reference_stack: list[str] = (source)

Undocumented

_finalize = (source)

Undocumented

_first_write: bool = (source)

Undocumented

_indentation: int = (source)

Undocumented

_last_identifier: int = (source)

Undocumented

_last_line = (source)

Undocumented

_new_lines = (source)

Undocumented

_param_def_block: t.List[t.Set[str]] = (source)

Undocumented

_write_debug_info = (source)

Undocumented