Module documentation
ll.ul4c provides templating for XML/HTML as well as any other text-based
format. A template defines placeholders for data output and basic logic (like
loops and conditional blocks), that define how the final rendered output will
look.
ll.ul4c compiles a template to an internal format, which makes it
possible to implement template renderers in multiple programming languages.
- ll.ul4c.withcontext(f)[source]
Normally when a function is exposed to UL4 this function will be called directly.
However when the function needs access to the rendering context (i.e. the local variables or information about the call stack), the function must have an additional first parameter, and UL4 must be told that this parmeter is required.
This can be done with this decorator.
- exception ll.ul4c.LocationError[source]
Bases:
ExceptionException class that provides a location inside an UL4 template.
If an exception happens inside an UL4 template, this exception will propagate outwards and will be decorated with
LocationErrorinstances which will be chained via the__cause__attribute. Only the original exception will be reraised again and again, so theseLocationErrorwill never have a traceback attached to them.The first
__cause__attribute marks the location in the UL4 source where the exception happened and the last__cause__attribute at the end of the exception chain marks the outermost call.
- exception ll.ul4c.BlockError[source]
Bases:
ExceptionException that is raised by the compiler when an illegal block structure is detected (e.g. an
<?end if?>without a previous<?if?>).
- class ll.ul4c.Context[source]
Bases:
objectA
Contextobject stores the context of a call to a template. This consists of local, global and builtin variables and the indent stack.
- class ll.ul4c.AST[source]
Bases:
objectBase class for all UL4 syntax tree nodes.
- eval(context)[source]
This evaluates the node.
For most nodes this is a normal function that returns the result of evaluating the node. (For these nodes the class attribute
outputis false.). For nodes that produce output (like literal text,PrintAST,PrintXASTorRenderAST) it is a generator which yields the text output of the node. For blocks (which might contain nodes which produce output) this is also a generator. (For these nodes the class attributeoutputis true.)
- class ll.ul4c.TextAST[source]
Bases:
ll.ul4c.ASTAST node for literal text (i.e. the stuff between tags).
Attributes are:
textstrThe text
- class ll.ul4c.IndentAST[source]
Bases:
ll.ul4c.TextASTAST node for literal text that is an indentation at the start of the line.
Attributes are:
textstrThe indentation text (i.e. a string that consists solely of whitespace).
- class ll.ul4c.LineEndAST[source]
Bases:
ll.ul4c.TextASTAST node for literal text that is the end of a line.
Attributes are:
textstrThe text of the linefeed (i.e.
"\n"or"\r\n").
- class ll.ul4c.Tag[source]
Bases:
ll.ul4c.ASTA
Tagobject is the location of a template tag in a template.
- class ll.ul4c.CodeAST[source]
Bases:
ll.ul4c.ASTThe base class of all AST nodes that are not literal text.
These nodes appear inside a
Tag.
- class ll.ul4c.ConstAST[source]
Bases:
ll.ul4c.CodeASTAST node for load a constant value.
Attributes are:
valueThe constant to be loaded.
- class ll.ul4c.SeqItemAST[source]
Bases:
ll.ul4c.CodeASTAST node for an item in a list/set “literal” (e.g.
{x, y}or[x, y])Attributes are:
valueASTThe list/set item (
xandyin the above examples).
- class ll.ul4c.UnpackSeqItemAST[source]
Bases:
ll.ul4c.CodeASTAST node for an
*unpacking expression in a list/set “literal” (e.g. theyin{x, *y}or[x, *y])Attributes are:
valueASTThe item to be unpacked into list/set items (
yin the above examples).
- class ll.ul4c.DictItemAST[source]
Bases:
ll.ul4c.CodeASTAST node for a dictionary entry in a dict expression (
DictAST).Attributes are:
- class ll.ul4c.UnpackDictItemAST[source]
Bases:
ll.ul4c.CodeASTAST node for
**unpacking expressions in dict “literal” (e.g. the**uin{k: v, **u}).Attributes are:
itemASTThe argument that must evaluate to a dictionary or an iterable of (key, value) pairs.
- class ll.ul4c.PositionalArgumentAST[source]
Bases:
ll.ul4c.CodeASTAST node for a positional argument. (e.g. the
xinf(x)).Attributes are:
valueASTThe value of the argument (
xin the above example).
- class ll.ul4c.KeywordArgumentAST[source]
Bases:
ll.ul4c.CodeASTAST node for a keyword argument in a
CallAST(e.g. thex=yin the function call``f(x=y)``).Attributes are:
- class ll.ul4c.UnpackListArgumentAST[source]
Bases:
ll.ul4c.CodeASTAST node for an
*unpacking expressions in aCallAST(e.g. the*xinf(*x)).Attributes are:
itemASTThe argument that must evaluate an iterable.
- class ll.ul4c.UnpackDictArgumentAST[source]
Bases:
ll.ul4c.CodeASTAST node for an
**unpacking expressions in aCallAST(e.g. the**xinf(**x)).Attributes are:
itemASTThe argument that must evaluate to a dictionary or an iterable of (key, value) pairs.
- class ll.ul4c.ListAST[source]
Bases:
ll.ul4c.CodeASTAST node for creating a list object (e.g.
[x, y, *z]).Attributes are:
itemslistThe items that will be put into the newly created list as a list of
SeqItemAST(xandyin the above example) andUnpackSeqItemASTobjects (zin the above example).
- class ll.ul4c.ListComprehensionAST[source]
Bases:
ll.ul4c.CodeASTAST node for a list comprehension (e.g.
[v for (a, b) in w if c].Attributes are:
itemASTThe expression for the item in the newly created list (
vin the above example).varnamenestedtupleofVarASTobjectsThe loop variable (or variables) (
aandbin the above example).containerASTThe container or iterable object over which to loop (
win the above example).conditionASTorNoneThe condition (as an
ASTobject if there is one, orNoneif there is not) (cin the above example).
- class ll.ul4c.SetAST[source]
Bases:
ll.ul4c.CodeASTAST node for creating a set object (e.g.
{x, y, *z}.Attributes are:
itemslistThe items that will be put into the newly created set as a list of
SeqItemAST(xandyin the above example) andUnpackSeqItemASTobjects (zin the above example).
- class ll.ul4c.SetComprehensionAST[source]
Bases:
ll.ul4c.CodeASTAST node for a set comprehension (e.g.
{v for (a, b) in w if c}.Attributes are:
itemASTThe expression for the item in the newly created set (
vin the above example).varnamenestedtupleofVarASTobjectsThe loop variable (or variables) (
aandbin the above example).containerASTThe container or iterable object over which to loop (
win the above example).conditionASTorNoneThe condition (as an
ASTobject if there is one, orNoneif there is not) (cin the above example).
- class ll.ul4c.DictAST[source]
Bases:
ll.ul4c.CodeASTAST node for creating a dict object (e.g. {k: v, **u}.
Attributes are:
itemslistThe items that will be put into the newly created dictionary as a list of
DictItemAST(forkandvin the above example) andUnpackDictItemASTobjects (foruin the above example).
- class ll.ul4c.DictComprehensionAST[source]
Bases:
ll.ul4c.CodeASTAST node for a dictionary comprehension (e.g.
{k: v for (a, b) in w if c}.Attributes are:
keyASTThe expression for the keys in the newly created dictionary (
kin the above example).valueASTThe expression for the values in the newly created dictionary (
vin the above example).varnamenestedtupleofVarASTobjectsThe loop variable (or variables) (
aandbin the above example).containerASTThe container or iterable object over which to loop (
win the above example).conditionASTorNoneThe condition (as an
ASTobject if there is one, orNoneif there is not) (cin the above example).
- class ll.ul4c.GeneratorExpressionAST[source]
Bases:
ll.ul4c.CodeASTAST node for a generator expression (e.g.
(x for (a, b) in w if c)).Attributes are:
itemASTAn expression for the item that looping over the generator expression will produce (
xin the above example).varnamenestedtupleofVarASTobjectsThe loop variable (or variables) (
aandbin the above example).containerASTThe container or iterable object over which to loop (
win the above example).conditionASTorNoneThe condition (as an
ASTobject if there is one, orNoneif there is not) (cin the above example).
- class ll.ul4c.VarAST[source]
Bases:
ll.ul4c.CodeASTAST node for getting a variable.
Attributes are:
namestrThe name of the variable.
- class ll.ul4c.BlockAST[source]
Bases:
ll.ul4c.CodeASTBase class for all AST nodes that are blocks.
A block contains a sequence of AST nodes that are executed sequencially. A block may execute its content zero (e.g. an
<?if?>block) or more times (e.g. a<?for?>block).Attributes are:
- class ll.ul4c.ConditionalBlocksAST[source]
Bases:
ll.ul4c.BlockASTAST node for a conditional
<?if?>/<?elif?>/<?else?>block.Attributes are:
contentlistThe content of the
ConditionalBlocksASTblock is oneIfBlockASTfollowed by zero or moreElIfBlockASTs followed by zero or oneElseBlockAST.
- class ll.ul4c.IfBlockAST[source]
Bases:
ll.ul4c.BlockASTAST node for an
<?if?>block in an<?if?>/<?elif?>/<?else?>block.Attributes are:
conditionclass:ASTThe condition in the
<?if?>block.contentlistof :class:`AST objectsThe content of the
<?if?>block.
- class ll.ul4c.ElIfBlockAST[source]
Bases:
ll.ul4c.BlockASTAST node for an
<?elif?>block.Attributes are:
conditionclass:ASTThe condition in the
<?elif?>block.contentlistof :class:`AST objectsThe content of the
<?elif?>block.
- class ll.ul4c.ElseBlockAST[source]
Bases:
ll.ul4c.BlockASTAST node for an
<?else?>block.Attributes are:
contentlistof :class:`AST objectsThe content of the
<?else?>block.
- class ll.ul4c.ForBlockAST[source]
Bases:
ll.ul4c.BlockASTAST node for a
<?for?>loop.For example
<?for (a, b) in w?> body <?end for?>
Attributes are:
- class ll.ul4c.WhileBlockAST[source]
Bases:
ll.ul4c.BlockASTAST node for a
<?while?>loop.For example
<?while c?> body <?end for?>
Attributes are:
- class ll.ul4c.BreakAST[source]
Bases:
ll.ul4c.CodeASTAST node for a
<?break?>tag inside a<?for?>loop.
- class ll.ul4c.ContinueAST[source]
Bases:
ll.ul4c.CodeASTAST node for a
<?continue?>tag inside a<?for?>block.
- class ll.ul4c.AttrAST[source]
Bases:
ll.ul4c.CodeASTAST node for an expression that gets or sets an attribute of an object. (e.g.
x.y).Attributes are:
- class ll.ul4c.SliceAST[source]
Bases:
ll.ul4c.CodeASTAST node for creating a slice object (used in
obj[index1:index2]).Attributes are:
index1ASTorNoneThe start index (
index1in the above example).index2ASTorNoneThe stop hand side (
yin the above example).
index1andindex2may also beNone(for missing slice indices, which default to the 0 for the start index and the length of the sequence for the end index).
- class ll.ul4c.UnaryAST[source]
Bases:
ll.ul4c.CodeASTBase class for all AST nodes implementing unary expressions (i.e. operators with one operand).
Atttributes are:
objASTThe operand of the unary operator.
- class ll.ul4c.NotAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a unary “not” expression (e.g.
not x).Attributes are:
objASTThe operand (
xin the above example).
- class ll.ul4c.NegAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a unary negation expression (e.g.
-x).Attributes are:
objASTThe operand (
xin the above example).
- class ll.ul4c.BitNotAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a bitwise unary “not” expression that returns its operand with its bits inverted (e.g.
~x).Attributes are:
objASTThe operand (
xin the above example).
- class ll.ul4c.PrintAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a
<?print?>tag (e.g.<?print x?>).Attributes are:
objASTThe object to be printed (
xin the above example).
- class ll.ul4c.PrintXAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a
<?printx?>tag (e.g.<?printx x?>).Attributes are:
objASTThe object to be printed (
xin the above example).
- class ll.ul4c.ReturnAST[source]
Bases:
ll.ul4c.UnaryASTAST node for a
<?return?>tag (e.g.<?return x?>).Attributes are:
objASTThe operand (
xin the above example).
- class ll.ul4c.BinaryAST[source]
Bases:
ll.ul4c.CodeASTBase class for all UL4 AST nodes implementing binary expressions (i.e. operators with two operands).
- class ll.ul4c.ItemAST[source]
Bases:
ll.ul4c.BinaryASTAST node for subscripting expression (e.g.
x[y]).Attributes are:
- class ll.ul4c.IsAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary
iscomparison expression (e.g.x is y).Attributes are:
- class ll.ul4c.IsNotAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary
is notcomparison expression (e.g.x is not y).Attributes are:
- class ll.ul4c.EQAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary equality comparison (e.g.
x == y.Attributes are:
- class ll.ul4c.NEAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary inequalitiy comparison (e.g.
x != y).Attributes are:
- class ll.ul4c.LTAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary “less than” comparison (e.g.
x < y).Attributes are:
- class ll.ul4c.LEAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary “less than or equal” comparison (e.g.
x <= y).Attributes are:
- class ll.ul4c.GTAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary “greater than” comparison (e.g.
x > y).Attributes are:
- class ll.ul4c.GEAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary “greater than or equal” comparison (e.g.
x >= y).Attributes are:
- class ll.ul4c.ContainsAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary containment testing operator (e.g.
x in y).Attributes are:
- class ll.ul4c.NotContainsAST[source]
Bases:
ll.ul4c.BinaryASTAST node for an inverted containment testing expression (e.g.
x not in y).Attributes are:
- class ll.ul4c.AddAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary addition expression that adds its two operands and returns the result (e.g.
x + y).Attributes are:
- class ll.ul4c.SubAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary subtraction operator.
- class ll.ul4c.MulAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary multiplication expression (e.g.
x * y).Attributes are:
- class ll.ul4c.FloorDivAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary truncating division expression (e.g.
x // y).Attributes are:
- class ll.ul4c.TrueDivAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary true division expression (e.g.
x / y).Attributes are:
- class ll.ul4c.ModAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary modulo expression (e.g.
x % y).Attributes are:
- class ll.ul4c.ShiftLeftAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a bitwise left shift expression (e.g.
x << y).Attributes are:
- class ll.ul4c.ShiftRightAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a bitwise right shift expression (e.g.
x >> y).Attributes are:
- class ll.ul4c.BitAndAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary bitwise “and” expression (e.g
x & y).Attributes are:
- class ll.ul4c.BitXOrAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary bitwise “exclusive or” expression (e.g.
x ^ y).Attributes are:
- class ll.ul4c.BitOrAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary bitwise “or” expression (e.g.
x | y).Attributes are:
- class ll.ul4c.AndAST[source]
Bases:
ll.ul4c.BinaryASTAST node for the binary “and” expression (i.e.
x and y).Attributes are:
- class ll.ul4c.OrAST[source]
Bases:
ll.ul4c.BinaryASTAST node for a binary “or” expression (e.g.
x or y).Attributes are:
- class ll.ul4c.IfAST[source]
Bases:
ll.ul4c.CodeASTAST node for the ternary inline
if/elseoperator (e.g.x if y else z).Attributes are:
- class ll.ul4c.ChangeVarAST[source]
Bases:
ll.ul4c.CodeASTBase class for all AST nodes that are assignment operators, i.e. that set or modify a variable/attribute or item.
Attributes are:
- class ll.ul4c.SetVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for setting a variable, attribute or item to a value (e.g.
x = y).
- class ll.ul4c.AddVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that adds a value to a variable (e.g.
x += y).Attributes are:
- class ll.ul4c.SubVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that subtracts a value from a variable/attribute/item. (e.g.
x -= y).Attributes are:
- class ll.ul4c.MulVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a multiplication to its left operand. (e.g.
x *= y).Attributes are:
- class ll.ul4c.FloorDivVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for augmented assignment expression that divides a variable by a value, truncating to an integer value (e.g.
x //= y).Attributes are:
- class ll.ul4c.TrueDivVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a truncation division to its left operand. (e.g.
x //= y).Attributes are:
- class ll.ul4c.ModVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a modulo expression to its left operand. (e.g.
x %= y).Attributes are:
- class ll.ul4c.ShiftLeftVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a “shift left” expression to its left operand. (e.g.
x <<= y).Attributes are:
- class ll.ul4c.ShiftRightVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a “shift right” expression to its left operand. (e.g.
x >>= y).Attributes are:
- class ll.ul4c.BitAndVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a binary bitwise “and” expression to its left operand. (e.g.
x &= y).Attributes are:
- class ll.ul4c.BitXOrVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a binary bitwise “exclusive or” expression to its left operand. (e.g.
x ^= y).Attributes are:
- class ll.ul4c.BitOrVarAST[source]
Bases:
ll.ul4c.ChangeVarASTAST node for an augmented assignment expression that assigns the result of a binary bitwise “or” expression to its left operand. (e.g.
x |= y).Attributes are:
- class ll.ul4c.CallAST[source]
Bases:
ll.ul4c.CodeASTAST node for calling an object (e.g.
f(x, y)).Attributes are:
objASTThe object to be called (
fin the above example);argslistThe arguments to the call as a
listofPositionalArgumentAST,KeywordArgumentAST,UnpackListArgumentASTorUnpackDictArgumentASTobjects (xandyin the above example).
- class ll.ul4c.RenderAST[source]
Bases:
ll.ul4c.CallASTAST node for rendering a template (e.g.
<?render t(x)?>.Attributes are:
objASTThe object to be rendered (
tin the above example);argslistThe arguments to the call as a
listofPositionalArgumentAST,KeywordArgumentAST,UnpackListArgumentASTorUnpackDictArgumentASTobjects.
- class ll.ul4c.RenderXAST[source]
Bases:
ll.ul4c.RenderASTAST node for rendering a template and XML-escaping the output (e.g.
<?renderx t(x)?>.Attributes are:
objASTThe object to be rendered (
tin the above example);argslistThe arguments to the call as a
listofPositionalArgumentAST,KeywordArgumentAST,UnpackListArgumentASTorUnpackDictArgumentASTobjects.
- class ll.ul4c.RenderBlockAST[source]
Bases:
ll.ul4c.RenderASTAST node for rendering a template via a
<?renderblock?>block and passing the content of the block as one additional keyword argument namedcontent.For example
<?renderblock t(a, b)?> content <?end renderblock?>
Attributes are:
objASTThe object to be rendered (
tin the above example);argslistThe arguments to the call as a
listofPositionalArgumentAST,KeywordArgumentAST,UnpackListArgumentASTorUnpackDictArgumentASTobjects (aandbin the above example).contentlistofASTobjectsThe content of the
<?renderblock?>tag (contentin the above example) that will be passed as a signatureless template as the keyword argumentcontentto the object.
- class ll.ul4c.RenderBlocksAST[source]
Bases:
ll.ul4c.RenderASTAST node for rendering a template and passing additional arguments via nested variable definitions, e.g.:
<?renderblocks t(a, b)?> <?code x = 42?> <?def n?> ... <?end def?> <?end renderblocks?>Attributes are:
objASTThe object to be rendered (
tin the above example);argslistThe arguments to the call as a
listofPositionalArgumentAST,KeywordArgumentAST,UnpackListArgumentASTorUnpackDictArgumentASTobjects (aandbin the above example).contentlistofASTobjectsThe content of the
<?renderblocks?>tag. These must beASTnodes that define variables (e.g.SetVarAST(the<?code x = 42?>in the above example), orTemplate(the<?def n?>...<?end def?>in the above example)).
- class ll.ul4c.Template[source]
Bases:
ll.ul4c.BlockASTA UL4 template.
A template object is normally created by passing the template source to the constructor. It can also be loaded from the compiled format via the class methods
load()(from a stream) orloads()(from a string).The compiled format can be generated with the methods
dump()(which dumps the format to a stream) ordumps()(which returns a string with the compiled format).Rendering the template can be done with the methods
render()(which is a generator) orrenders()(which returns a string).A
Templatecan also be called as a function (returning the result of the first<?return?>tag encountered). In this case all output of the template will be ignored.For rendering and calling a template with global variables the following methods are available:
render_with_globals(),renders_with_globals()andcall_with_globals().A
Templateobject is itself an AST node. Evaluating it will store aTemplateClosureobject for this template under the template’s name in the local variables.- __init__(source=None, name=None, *, whitespace='keep', signature=None)[source]
Create a
Templateobject.If
sourceisNone, theTemplateremains uninitialized, otherwisesourcewill be compiled.nameis the name of the template. It will be used in exception messages and should be a valid Python identifier.whitespacespecifies how whitespace is handled in the literal text in templates (i.e. the text between the tags):"keep"Whitespace is kept as it is.
"strip"Strip linefeeds and the following indentation from the text. However trailing whitespace at the end of the line will still be honored.
"smart"If a line contains only indentation and one tag that isn’t a
printorprintxtag, the indentation and the linefeed after the tag will be stripped from the text. Furthermore the additional indentation that might be introduced by afor,if,elif,elseordefblock will be ignored. So for example the output of:<?code langs = ["Python", "Java", "Javascript"]?> <?if langs?> <?for lang in langs?> <?print lang?> <?end for?> <?end if?>will simply be:
Python Java Javascript
without any additional empty lines or indentation.
(Output will always be ignored when calling a template as a function.)
signatureis the signature of the template. For a top level template it can be:NoneThe template will accept all keyword arguments.
- An
inspect.Signatureobject This signature will be used as the signature of the template.
- A callable
The signature of the callable will be used.
- A string
The signature as a string, i.e. something like
"x, y=42, *args, **kwargs". This string will be parsed and evaluated to create the signature for the template.
If the template is a locally defined subtemplate (i.e. a template defined by another template via
<?def t?>...<?end def?>),signaturecan be:NoneThe template will accept all arguments.
- A
SignatureASTobject This AST node will be evaluated at the point of definition of the subtemplate to create the final signature of the subtemplate.
- classmethod loads(data)[source]
Loads a template as an UL4ON dump from the string
data.
- classmethod load(stream)[source]
Loads the template as an UL4ON dump from the stream
stream. format.
- dump(stream)[source]
Dump the template in compiled UL4ON format to the stream
stream.
- dumps()[source]
Return the template in compiled UL4ON format (as a string).
- render(*args, **kwargs)[source]
Render the template iteratively (i.e. this is a generator).
argsandkwargscontain the top level positional and keyword arguments available to the template code. Positional arguments will only be supported if the template has a signature.
- render_with_globals(args, kwargs, globals)[source]
Render the template iteratively (i.e. this is a generator).
argsandkwargscontain the top level positional and keyword arguments available to the template code.globalscontains global variables. Positional arguments will only be supported if the template has a signature.
- renders(*args, **kwargs)[source]
Render the template as a string.
argsandkwargscontain the top level positional and keyword arguments available to the template code. Positional arguments will only be supported if the template has a signature.
- renders_with_globals(args, kwargs, globals)[source]
Render the template as a string.
argsandkwargscontain the top level positional and keyword arguments available to the template code.globalscontains global variables. Positional arguments will only be supported if the template has a signature.
- ul4_call(context, /, *args, **kwargs)[source]
Call the template as a function and return the resulting value.
argsandkwargscontain the top level positional and keyword arguments available to the template code. Positional arguments will only be supported if the template has a signature.
- __call__(*args, **kwargs)[source]
Call the template as a function and return the resulting value.
argsandkwargscontain the top level positional and keyword arguments available to the template code. Positional arguments will only be supported if the template has a signature.
- call_with_globals(args, kwargs, globals)[source]
Call the template as a function and return the resulting value.
argsandkwargscontain the top level positional and keyword arguments available to the template code.globalscontains global variables. Positional arguments will only be supported if the template has a signature.
- jssource()[source]
Return the template as the source code of a Javascript function.
- javasource()[source]
Return the template as Java source code.
- class ll.ul4c.SignatureAST[source]
Bases:
ll.ul4c.CodeASTAST node for the signature of a locally defined subtemplate.
Attributes are:
paramslistThe parameter. Each list item is a
tuplewith three items:namestrThe name of the argument.
typestrThe type of the argument. One of:
pk(positional or keyword argument without default)pk=(positional or keyword argument with default)p(positional-only argument without default)p=(positional-only argument with default)k(keyword-only argument without default)k=(keyword-only argument with default)*(argument that collects addition positional arguments)**(argument that collects addition keyword arguments)
defaultASTorNoneThe default value for the argument (or
Noneif the argument has no default value).
- class ll.ul4c.TemplateClosure[source]
Bases:
ll.ul4c.BlockASTA locally defined subtemplate.
A
TemplateClosureis a closure, i.e. it can use the local variables of the template it is defined in.