CodeGenerator Class

Inheritance diagram of CodeGenerator

class CodeGenerator(environment, name, filename, stream=None, defer_init=False)

Methods

__init__(environment, name, filename[, ...])
blockvisit(nodes, frame) Visit a list of nodes as block in a frame.
buffer(frame) Enable buffering for the frame from that point onwards.
end_write(frame) End the writing process started by start_write.
fail(msg, lineno) Fail with a TemplateAssertionError.
function_scoping(node, frame[, children, ...]) In Jinja a few statements require the help of anonymous
generic_visit(node, *args, **kwargs) Called if no explicit visitor function exists for a node.
get_visitor(node) Return the visitor function for this node or None if no visitor
indent() Indent by one.
macro_body(node, frame[, children]) Dump the function def of a macro or call block.
macro_def(node, frame) Dump the macro definition for the def created by macro_body.
newline([node, extra]) Add one or more newlines before the next write.
outdent([step]) Outdent by step.
pop_scope(aliases, frame) Restore all aliases and delete unused variables.
position(node) Return a human readable position for the node.
pull_dependencies(nodes) Pull all the dependencies.
pull_locals(frame) Pull all the references identifiers into the local scope.
push_scope(frame[, extra_vars]) This function returns all the shadowed variables in a dict in the form name: alias and will write the required assignments into the current scope.
return_buffer_contents(frame) Return the buffer contents of the frame.
signature(node, frame[, extra_kwargs]) Writes a function call to the stream for the current node.
simple_write(s, frame[, node]) Simple shortcut for start_write + write + end_write.
start_write(frame[, node]) Yield or write into the frame buffer.
temporary_identifier() Get a new unique identifier.
unoptimize_scope(frame) Disable Python optimizations for the frame.
visit(node, *args, **kwargs) Visit a node.
visit_Add(node, frame)
visit_And(node, frame)
visit_Assign(node, frame)
visit_Block(node, frame) Call a block and register it for the template.
visit_Break(node, frame)
visit_Call(node, frame[, forward_caller])
visit_CallBlock(node, frame)
visit_Compare(node, frame)
visit_Concat(node, frame)
visit_CondExpr(node, frame)
visit_Const(node, frame)
visit_ContextReference(node, frame)
visit_Continue(node, frame)
visit_Dict(node, frame)
visit_Div(node, frame)
visit_EnvironmentAttribute(node, frame)
visit_EvalContextModifier(node, frame)
visit_ExprStmt(node, frame)
visit_Extends(node, frame) Calls the extender.
visit_ExtensionAttribute(node, frame)
visit_Filter(node, frame)
visit_FilterBlock(node, frame)
visit_FloorDiv(node, frame)
visit_For(node, frame)
visit_FromImport(node, frame) Visit named imports.
visit_Getattr(node, frame)
visit_Getitem(node, frame)
visit_If(node, frame)
visit_Import(node, frame) Visit regular imports.
visit_ImportedName(node, frame)
visit_Include(node, frame) Handles includes.
visit_InternalName(node, frame)
visit_Keyword(node, frame)
visit_List(node, frame)
visit_Macro(node, frame)
visit_MarkSafe(node, frame)
visit_MarkSafeIfAutoescape(node, frame)
visit_Mod(node, frame)
visit_Mul(node, frame)
visit_Name(node, frame)
visit_Neg(node, frame)
visit_Not(node, frame)
visit_Operand(node, frame)
visit_Or(node, frame)
visit_Output(node, frame)
visit_Pos(node, frame)
visit_Pow(node, frame)
visit_Scope(node, frame)
visit_ScopedEvalContextModifier(node, frame)
visit_Slice(node, frame)
visit_Sub(node, frame)
visit_Template(node[, frame])
visit_TemplateData(node, frame)
visit_Test(node, frame)
visit_Tuple(node, frame)
write(x) Write a string into the output stream.
writeline(x[, node, extra]) Combination of newline and write.

Descriptions

class CodeGenerator

Method details

__init__(environment, name, filename, stream=None, defer_init=False)
blockvisit(nodes, frame)

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 unless the force_generator parameter is set to False.

buffer(frame)

Enable buffering for the frame from that point onwards.

end_write(frame)

End the writing process started by start_write.

fail(msg, lineno)

Fail with a TemplateAssertionError.

function_scoping(node, frame, children=None, find_special=True)

In Jinja a few statements require the help of anonymous functions. Those are currently macros and call blocks and in the future also recursive loops. As there is currently technical limitation that doesn’t allow reading and writing a variable in a scope where the initial value is coming from an outer scope, this function tries to fall back with a common error message. Additionally the frame passed is modified so that the argumetns are collected and callers are looked up.

This will return the modified frame.

indent()

Indent by one.

macro_body(node, frame, children=None)

Dump the function def of a macro or call block.

macro_def(node, frame)

Dump the macro definition for the def created by macro_body.

newline(node=None, extra=0)

Add one or more newlines before the next write.

outdent(step=1)

Outdent by step.

pop_scope(aliases, frame)

Restore all aliases and delete unused variables.

position(node)

Return a human readable position for the node.

pull_dependencies(nodes)

Pull all the dependencies.

pull_locals(frame)

Pull all the references identifiers into the local scope.

push_scope(frame, extra_vars=())

This function returns all the shadowed variables in a dict in the form name: alias and will write the required assignments into the current scope. No indentation takes place.

This also predefines locally declared variables from the loop body because under some circumstances it may be the case that

extra_vars is passed to Frame.find_shadowed.

return_buffer_contents(frame)

Return the buffer contents of the frame.

signature(node, frame, extra_kwargs=None)

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 occour. The extra keyword arguments should be given as python dict.

simple_write(s, frame, node=None)

Simple shortcut for start_write + write + end_write.

start_write(frame, node=None)

Yield or write into the frame buffer.

temporary_identifier()

Get a new unique identifier.

unoptimize_scope(frame)

Disable Python optimizations for the frame.

visit_Add(node, frame)
visit_And(node, frame)
visit_Assign(node, frame)
visit_Block(node, frame)

Call a block and register it for the template.

visit_Break(node, frame)
visit_Call(node, frame, forward_caller=False)
visit_CallBlock(node, frame)
visit_Compare(node, frame)
visit_Concat(node, frame)
visit_CondExpr(node, frame)
visit_Const(node, frame)
visit_ContextReference(node, frame)
visit_Continue(node, frame)
visit_Dict(node, frame)
visit_Div(node, frame)
visit_EnvironmentAttribute(node, frame)
visit_EvalContextModifier(node, frame)
visit_ExprStmt(node, frame)
visit_Extends(node, frame)

Calls the extender.

visit_ExtensionAttribute(node, frame)
visit_Filter(node, frame)
visit_FilterBlock(node, frame)
visit_FloorDiv(node, frame)
visit_For(node, frame)
visit_FromImport(node, frame)

Visit named imports.

visit_Getattr(node, frame)
visit_Getitem(node, frame)
visit_If(node, frame)
visit_Import(node, frame)

Visit regular imports.

visit_ImportedName(node, frame)
visit_Include(node, frame)

Handles includes.

visit_InternalName(node, frame)
visit_Keyword(node, frame)
visit_List(node, frame)
visit_Macro(node, frame)
visit_MarkSafe(node, frame)
visit_MarkSafeIfAutoescape(node, frame)
visit_Mod(node, frame)
visit_Mul(node, frame)
visit_Name(node, frame)
visit_Neg(node, frame)
visit_Not(node, frame)
visit_Operand(node, frame)
visit_Or(node, frame)
visit_Output(node, frame)
visit_Pos(node, frame)
visit_Pow(node, frame)
visit_Scope(node, frame)
visit_ScopedEvalContextModifier(node, frame)
visit_Slice(node, frame)
visit_Sub(node, frame)
visit_Template(node, frame=None)
visit_TemplateData(node, frame)
visit_Test(node, frame)
visit_Tuple(node, frame)
write(x)

Write a string into the output stream.

writeline(x, node=None, extra=0)

Combination of newline and write.

Inherited member details

generic_visit(node, *args, **kwargs)

Called if no explicit visitor function exists for a node.

get_visitor(node)

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.

visit(node, *args, **kwargs)

Visit a node.

Table Of Contents

Previous topic

next

Next topic

DependencyFinderVisitor Class