class CodeGenerator(NodeVisitor):
Known subclasses: jinja2.meta.TrackingCodeGenerator
, jinja2.nativetypes.NativeCodeGenerator
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 | __init__ |
Undocumented |
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. |
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 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 |
No summary |
Method | push_assign_tracking |
Pushes a new layer for assignment tracking. |
Method | push_context_reference |
Undocumented |
Method | push_parameter_definitions |
No summary |
Method | return_buffer_contents |
Return the buffer contents of the frame. |
Method | signature |
No summary |
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 | _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 |
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 |
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. |
jinja2.nativetypes.NativeCodeGenerator
Parameters | |
value:t.Any | Undocumented |
Returns | |
t.Any | Undocumented |
jinja2.meta.TrackingCodeGenerator
Undocumented
Parameters | |
environment:Environment | Undocumented |
name:t.Optional[ | Undocumented |
filename:t.Optional[ | Undocumented |
stream:t.Optional[ | Undocumented |
defer_init:bool | Undocumented |
optimized:bool | Undocumented |
Undocumented
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
is_filter:bool | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Undocumented
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
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:
Returns | |
_FinalizeInfo | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Parameters | |
node:nodes.Expr | Undocumented |
frame:Frame | Undocumented |
finalize:_FinalizeInfo | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Parameters | |
node:nodes.Expr | Undocumented |
frame:Frame | Undocumented |
finalize:_FinalizeInfo | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Try to optimize a child of an Output node by trying to convert it to constant, finalized data at compile time.
If 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.Expr | Undocumented |
frame:Frame | Undocumented |
finalize:_FinalizeInfo | Undocumented |
Returns | |
str | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Parameters | |
group:t.Iterable[ | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
nodes:t.Iterable[ | Undocumented |
frame:Frame | Undocumented |
Parameters | |
frame:Frame | Undocumented |
Undocumented
Parameters | |
async_value:str | Undocumented |
sync_value:str | Undocumented |
Returns | |
str | Undocumented |
Undocumented
Parameters | |
frame:Frame | Undocumented |
Returns | |
str | Undocumented |
Undocumented
Parameters | |
frame:Frame | Undocumented |
Returns | |
str | Undocumented |
start_write
.Parameters | |
frame:Frame | Undocumented |
jinja2.meta.TrackingCodeGenerator
Undocumented
Parameters | |
frame:Frame | Undocumented |
TemplateAssertionError
.Parameters | |
msg:str | Undocumented |
lineno:int | Undocumented |
Returns | |
te.NoReturn | Undocumented |
Undocumented
Parameters | |
frame:Frame | Undocumented |
with_python_scope:bool | Undocumented |
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
Returns | |
t.Tuple[ | Undocumented |
Parameters | |
target:str | Undocumented |
Parameters | |
node:t.Optional[ | Undocumented |
extra:int | Undocumented |
Parameters | |
target:str | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
frame:Frame | Undocumented |
Parameters | |
node:nodes.Node | Undocumented |
Returns | |
str | Undocumented |
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.
Parameters | |
nodes:t.Iterable[ | Undocumented |
visit_Name
to skip
undefined expressions for parameters in macros as macros can reference
otherwise unbound parameters.Parameters | |
frame:Frame | Undocumented |
Parameters | |
frame:Frame | Undocumented |
force_unescaped:bool | Undocumented |
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
extra_kwargs:t.Optional[ | Undocumented |
Parameters | |
s:str | Undocumented |
frame:Frame | Undocumented |
node:t.Optional[ | Undocumented |
Parameters | |
frame:Frame | Undocumented |
node:t.Optional[ | Undocumented |
Undocumented
Parameters | |
node:nodes.Assign | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.AssignBlock | Undocumented |
frame:Frame | Undocumented |
Parameters | |
node:nodes.Block | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Break | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Call | Undocumented |
frame:Frame | Undocumented |
forward_caller:bool | Undocumented |
Undocumented
Parameters | |
node:nodes.CallBlock | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Const | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.ContextReference | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Continue | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.DerivedContextReference | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Dict | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.EnvironmentAttribute | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.EvalContextModifier | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.ExprStmt | Undocumented |
frame:Frame | Undocumented |
Parameters | |
node:nodes.Extends | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.ExtensionAttribute | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.FilterBlock | Undocumented |
frame:Frame | Undocumented |
Parameters | |
node:nodes.FromImport | Undocumented |
frame:Frame | Undocumented |
Parameters | |
node:nodes.Import | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.ImportedName | Undocumented |
frame:Frame | Undocumented |
Parameters | |
node:nodes.Include | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.InternalName | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Keyword | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.List | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Macro | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.MarkSafe | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.MarkSafeIfAutoescape | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Name | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.NSRef | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Operand | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Output | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.OverlayScope | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Scope | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.ScopedEvalContextModifier | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Slice | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Template | Undocumented |
frame:t.Optional[ | Undocumented |
Undocumented
Parameters | |
node:nodes.TemplateData | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Tuple | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.With | Undocumented |
frame:Frame | Undocumented |
jinja2.meta.TrackingCodeGenerator
Parameters | |
x:str | Undocumented |
Parameters | |
x:str | Undocumented |
node:t.Optional[ | Undocumented |
extra:int | Undocumented |