class CodeGenerator(NodeVisitor): (source)
Known subclasses: jinja2.meta.TrackingCodeGenerator
, jinja2.nativetypes.NativeCodeGenerator
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 |
Undocumented |
Method | derive |
Undocumented |
Method | dump |
Undocumented |
Method | end |
End the writing process started by `start_write`. |
Method | enter |
Undocumented |
Method | fail |
Fail with a :exc:`TemplateAssertionError`. |
Method | func |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | indent |
Indent by one. |
Method | leave |
Undocumented |
Method | macro |
Dump the function def of a macro or call block. |
Method | macro |
Dump the macro definition for the def created by macro_body. |
Method | mark |
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 |
Checks if a given target is an undeclared parameter. |
Method | pop |
Pops the topmost level for assignment tracking and updates the context variables if necessary. |
Method | pop |
Undocumented |
Method | pop |
Pops the current parameter definitions set. |
Method | position |
Return a human readable position for the node. |
Method | pull |
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 |
Pushes a new layer for assignment tracking. |
Method | push |
Undocumented |
Method | push |
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 |
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 |
Simple shortcut for start_write + write + end_write. |
Method | start |
Yield or write into the frame buffer. |
Method | temporary |
Get a new unique identifier. |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Call a block and register it for the template. |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Calls the extender. |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Visit named imports. |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Visit regular imports. |
Method | visit_ |
Undocumented |
Method | visit_ |
Handles includes. |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | visit_ |
Undocumented |
Method | write |
Write a string into the output stream. |
Method | write |
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_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Class Variable | visit_ |
Undocumented |
Instance Variable | blocks |
Undocumented |
Instance Variable | code |
Undocumented |
Instance Variable | created |
Undocumented |
Instance Variable | debug |
Undocumented |
Instance Variable | defer |
Undocumented |
Instance Variable | environment |
Undocumented |
Instance Variable | extends |
Undocumented |
Instance Variable | filename |
Undocumented |
Instance Variable | filters |
Undocumented |
Instance Variable | has |
Undocumented |
Instance Variable | import |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | optimizer |
Undocumented |
Instance Variable | stream |
Undocumented |
Instance Variable | tests |
Undocumented |
Property | optimized |
Undocumented |
Class | _ |
Undocumented |
Static Method | _default |
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 |
Undocumented |
Method | _import |
Undocumented |
Method | _make |
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 |
Output extra source code after visiting a child of an ``Output`` node. |
Method | _output |
Output extra source code before visiting a child of an ``Output`` node. |
Method | _output |
Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. |
Method | _output |
Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source. |
Instance Variable | _assign |
Undocumented |
Instance Variable | _context |
Undocumented |
Instance Variable | _finalize |
Undocumented |
Instance Variable | _first |
Undocumented |
Instance Variable | _indentation |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _new |
Undocumented |
Instance Variable | _param |
Undocumented |
Instance Variable | _write |
Undocumented |
Inherited from NodeVisitor
:
Method | generic |
Called if no explicit visitor function exists for a node. |
Method | get |
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.meta.TrackingCodeGenerator
Undocumented
Parameters | |
environment:Environment | Undocumented |
name:t.Optional[ | Undocumented |
filename:t.Optional[ | Undocumented |
stream:t.Optional[ | Undocumented |
deferbool | Undocumented |
optimized:bool | Undocumented |
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[ | Undocumented |
frame:Frame | Undocumented |
Dump the function def of a macro or call block.
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
Returns | |
t.Tuple[ | Undocumented |
Marks a parameter in the current parameter definitions as stored. This will skip the enforced undefined checks.
Parameters | |
target:str | Undocumented |
Add one or more newlines before the next write.
Parameters | |
node:t.Optional[ | Undocumented |
extra:int | Undocumented |
Pops the topmost level for assignment tracking and updates the context variables if necessary.
Parameters | |
frame:Frame | Undocumented |
Return a human readable position for the node.
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. .. versionchanged:: 3.0 Filters and tests in If and CondExpr nodes are checked at runtime instead of compile time.
Parameters | |
nodes:t.Iterable[ | Undocumented |
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:Frame | Undocumented |
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[ | Undocumented |
frame:Frame | Undocumented |
extrat.Optional[ | Undocumented |
Simple shortcut for start_write + write + end_write.
Parameters | |
s:str | Undocumented |
frame:Frame | Undocumented |
node:t.Optional[ | Undocumented |
Yield or write into the frame buffer.
Parameters | |
frame:Frame | Undocumented |
node:t.Optional[ | Undocumented |
Call a block and register it for the template.
Parameters | |
node:nodes.Block | Undocumented |
frame:Frame | Undocumented |
Undocumented
Parameters | |
node:nodes.Call | Undocumented |
frame:Frame | Undocumented |
forwardbool | Undocumented |
jinja2.meta.TrackingCodeGenerator
Write a string into the output stream.
Parameters | |
x:str | Undocumented |
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.
Combination of newline and write.
Parameters | |
x:str | Undocumented |
node:t.Optional[ | Undocumented |
extra:int | Undocumented |
Undocumented
Parameters | |
node:t.Union[ | Undocumented |
frame:Frame | Undocumented |
isbool | 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: ``const`` A function to finalize constant data at compile time. ``src`` Source code to output around nodes to be evaluated at runtime.
Returns | |
_FinalizeInfo | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Output extra source code after visiting a child of an ``Output`` node.
Parameters | |
node:nodes.Expr | Undocumented |
frame:Frame | Undocumented |
finalize:_FinalizeInfo | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
Output extra source code before visiting a child of an ``Output`` node.
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 :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.Expr | Undocumented |
frame:Frame | Undocumented |
finalize:_FinalizeInfo | Undocumented |
Returns | |
str | Undocumented |
jinja2.nativetypes.NativeCodeGenerator
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[ | Undocumented |
Returns | |
str | Undocumented |