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.
- class ll.ul4c.XMLEscapeStream[source]
Bases:
object
Output stream that delegates all writes to an underlying stream, but XML escapes everything that gets written.
- exception ll.ul4c.LocationError[source]
Bases:
Exception
Exception 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
LocationError
instances which will be chained via the__cause__
attribute. Only the original exception will be reraised again and again, so theseLocationError
will 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:
Exception
Exception 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:
object
A
Context
object 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:
object
Base 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
output
isFalse
.). For nodes that produce output (like literal text,PrintAST
,PrintXAST
orRenderAST
etc.) 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 attributeoutput
isTrue
.)
- class ll.ul4c.TextAST[source]
Bases:
AST
AST node for literal text (i.e. the stuff between tags).
Attributes are:
text
str
The text
- class ll.ul4c.IndentAST[source]
Bases:
TextAST
AST node for literal text that is an indentation at the start of the line.
Attributes are:
text
str
The indentation text (i.e. a string that consists solely of whitespace).
- class ll.ul4c.LineEndAST[source]
Bases:
TextAST
AST node for literal text that is the end of a line.
Attributes are:
text
str
The text of the linefeed (i.e.
"\n"
or"\r\n"
).
- class ll.ul4c.CodeAST[source]
Bases:
AST
The base class of all AST nodes that are not literal text.
These nodes appear inside a
Tag
.
- class ll.ul4c.ConstAST[source]
Bases:
CodeAST
AST node for a constant value.
Attributes are:
value
The constant to be loaded.
- class ll.ul4c.SeqItemAST[source]
Bases:
CodeAST
AST node for an item in a list/set “literal” (e.g.
{x, y}
or[x, y]
)Attributes are:
value
AST
The list/set item (
x
andy
in the above examples).
- class ll.ul4c.UnpackSeqItemAST[source]
Bases:
CodeAST
AST node for an
*
unpacking expression in a list/set “literal” (e.g. they
in{x, *y}
or[x, *y]
)Attributes are:
value
AST
The item to be unpacked into list/set items (
y
in the above examples).
- class ll.ul4c.DictItemAST[source]
Bases:
CodeAST
AST node for a dictionary entry in a dict expression (
DictAST
).Attributes are:
- class ll.ul4c.UnpackDictItemAST[source]
Bases:
CodeAST
AST node for
**
unpacking expressions in dict “literal” (e.g. the**u
in{k: v, **u}
).Attributes are:
item
AST
The argument that must evaluate to a dictionary or an iterable of (key, value) pairs.
- class ll.ul4c.PositionalArgumentAST[source]
Bases:
CodeAST
AST node for a positional argument. (e.g. the
x
inf(x)
).Attributes are:
value
AST
The value of the argument (
x
in the above example).
- class ll.ul4c.KeywordArgumentAST[source]
Bases:
CodeAST
AST node for a keyword argument in a
CallAST
(e.g. thex=y
in the function callf(x=y)
).Attributes are:
- class ll.ul4c.UnpackListArgumentAST[source]
Bases:
CodeAST
AST node for an
*
unpacking expressions in aCallAST
(e.g. the*x
inf(*x)
).Attributes are:
item
AST
The argument that must evaluate an iterable.
- class ll.ul4c.UnpackDictArgumentAST[source]
Bases:
CodeAST
AST node for an
**
unpacking expressions in aCallAST
(e.g. the**x
inf(**x)
).Attributes are:
item
AST
The argument that must evaluate to a dictionary or an iterable of (key, value) pairs.
- class ll.ul4c.ListAST[source]
Bases:
CodeAST
AST node for creating a list object (e.g.
[x, y, *z]
).Attributes are:
items
list
The items that will be put into the newly created list as a list of
SeqItemAST
(x
andy
in the above example) andUnpackSeqItemAST
objects (z
in the above example).
- class ll.ul4c.ListComprehensionAST[source]
Bases:
CodeAST
AST node for a list comprehension (e.g.
[v for (a, b) in w if c]
.Attributes are:
item
AST
The expression for the item in the newly created list (
v
in the above example).varname
nestedtuple
ofVarAST
objectsThe loop variable (or variables) (
a
andb
in the above example).container
AST
The container or iterable object over which to loop (
w
in the above example).condition
AST
orNone
The condition (as an
AST
object if there is one, orNone
if there is not) (c
in the above example).
- class ll.ul4c.SetAST[source]
Bases:
CodeAST
AST node for creating a set object (e.g.
{x, y, *z}
.Attributes are:
items
list
The items that will be put into the newly created set as a list of
SeqItemAST
(x
andy
in the above example) andUnpackSeqItemAST
objects (z
in the above example).
- class ll.ul4c.SetComprehensionAST[source]
Bases:
CodeAST
AST node for a set comprehension (e.g.
{v for (a, b) in w if c}
.Attributes are:
item
AST
The expression for the item in the newly created set (
v
in the above example).varname
nestedtuple
ofVarAST
objectsThe loop variable (or variables) (
a
andb
in the above example).container
AST
The container or iterable object over which to loop (
w
in the above example).condition
AST
orNone
The condition (as an
AST
object if there is one, orNone
if there is not) (c
in the above example).
- class ll.ul4c.DictAST[source]
Bases:
CodeAST
AST node for creating a dict object (e.g. {k: v, **u}.
Attributes are:
items
list
The items that will be put into the newly created dictionary as a list of
DictItemAST
(fork
andv
in the above example) andUnpackDictItemAST
objects (foru
in the above example).
- class ll.ul4c.DictComprehensionAST[source]
Bases:
CodeAST
AST node for a dictionary comprehension (e.g.
{k: v for (a, b) in w if c}
.Attributes are:
key
AST
The expression for the keys in the newly created dictionary (
k
in the above example).value
AST
The expression for the values in the newly created dictionary (
v
in the above example).varname
nestedtuple
ofVarAST
objectsThe loop variable (or variables) (
a
andb
in the above example).container
AST
The container or iterable object over which to loop (
w
in the above example).condition
AST
orNone
The condition (as an
AST
object if there is one, orNone
if there is not) (c
in the above example).
- class ll.ul4c.GeneratorExpressionAST[source]
Bases:
CodeAST
AST node for a generator expression (e.g.
(x for (a, b) in w if c)
).Attributes are:
item
AST
An expression for the item that looping over the generator expression will produce (
x
in the above example).varname
nestedtuple
ofVarAST
objectsThe loop variable (or variables) (
a
andb
in the above example).container
AST
The container or iterable object over which to loop (
w
in the above example).condition
AST
orNone
The condition (as an
AST
object if there is one, orNone
if there is not) (c
in the above example).
- class ll.ul4c.VarAST[source]
Bases:
CodeAST
AST node for getting a variable.
Attributes are:
name
str
The name of the variable.
- class ll.ul4c.BlockAST[source]
Bases:
CodeAST
Base 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:
BlockAST
AST node for a conditional
<?if?>/<?elif?>/<?else?>
block.Attributes are:
content
list
The content of the
ConditionalBlocksAST
block is oneIfBlockAST
followed by zero or moreElIfBlockAST
s followed by zero or oneElseBlockAST
.
- class ll.ul4c.IfBlockAST[source]
Bases:
BlockAST
AST node for an
<?if?>
block in an<?if?>/<?elif?>/<?else?>
block.Attributes are:
- class ll.ul4c.ForBlockAST[source]
Bases:
BlockAST
AST node for a
<?for?>
loop.For example
<?for (a, b) in w?> body <?end for?>
Attributes are:
- class ll.ul4c.WhileBlockAST[source]
Bases:
BlockAST
AST node for a
<?while?>
loop.For example
<?while c?> body <?end for?>
Attributes are:
- class ll.ul4c.ContinueAST[source]
Bases:
CodeAST
AST node for a
<?continue?>
tag inside a<?for?>
block.
- class ll.ul4c.AttrAST[source]
Bases:
CodeAST
AST 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:
CodeAST
AST node for creating a slice object (used in
obj[index1:index2]
).Attributes are:
index1
AST
orNone
The start index (
index1
in the above example).index2
AST
orNone
The stop index (
index2
in the above example).
index1
andindex2
may also beNone
(for missing slice indices, which default to 0 for the start index and the length of the sequence for the stop index).
- class ll.ul4c.UnaryAST[source]
Bases:
CodeAST
Base class for all AST nodes implementing unary expressions (i.e. operators with one operand).
Atttributes are:
obj
AST
The operand of the unary operator.
- class ll.ul4c.NotAST[source]
Bases:
UnaryAST
AST node for a unary “not” expression (e.g.
not x
).Attributes are:
obj
AST
The operand (
x
in the above example).
- class ll.ul4c.NegAST[source]
Bases:
UnaryAST
AST node for a unary negation expression (e.g.
-x
).Attributes are:
obj
AST
The operand (
x
in the above example).
- class ll.ul4c.BitNotAST[source]
Bases:
UnaryAST
AST node for a bitwise unary “not” expression that returns its operand with its bits inverted (e.g.
~x
).Attributes are:
obj
AST
The operand (
x
in the above example).
- class ll.ul4c.PrintAST[source]
Bases:
UnaryAST
AST node for a
<?print?>
tag (e.g.<?print x?>
).Attributes are:
obj
AST
The object to be printed (
x
in the above example).
- class ll.ul4c.PrintXAST[source]
Bases:
UnaryAST
AST node for a
<?printx?>
tag (e.g.<?printx x?>
).Attributes are:
obj
AST
The object to be printed (
x
in the above example).
- class ll.ul4c.ReturnAST[source]
Bases:
UnaryAST
AST node for a
<?return?>
tag (e.g.<?return x?>
).Attributes are:
obj
AST
The operand (
x
in the above example).
- class ll.ul4c.BinaryAST[source]
Bases:
CodeAST
Base class for all UL4 AST nodes implementing binary expressions (i.e. operators with two operands).
- class ll.ul4c.ItemAST[source]
Bases:
BinaryAST
AST node for subscripting expression (e.g.
x[y]
).Attributes are:
- class ll.ul4c.IsAST[source]
Bases:
BinaryAST
AST node for a binary
is
comparison expression (e.g.x is y
).Attributes are:
- class ll.ul4c.IsNotAST[source]
Bases:
BinaryAST
AST node for a binary
is not
comparison expression (e.g.x is not y
).Attributes are:
- class ll.ul4c.EQAST[source]
Bases:
BinaryAST
AST node for the binary equality comparison (e.g.
x == y
.Attributes are:
- class ll.ul4c.NEAST[source]
Bases:
BinaryAST
AST node for a binary inequality comparison (e.g.
x != y
).Attributes are:
- class ll.ul4c.LTAST[source]
Bases:
BinaryAST
AST node for the binary “less than” comparison (e.g.
x < y
).Attributes are:
- class ll.ul4c.LEAST[source]
Bases:
BinaryAST
AST node for the binary “less than or equal” comparison (e.g.
x <= y
).Attributes are:
- class ll.ul4c.GTAST[source]
Bases:
BinaryAST
AST node for the binary “greater than” comparison (e.g.
x > y
).Attributes are:
- class ll.ul4c.GEAST[source]
Bases:
BinaryAST
AST node for the binary “greater than or equal” comparison (e.g.
x >= y
).Attributes are:
- class ll.ul4c.ContainsAST[source]
Bases:
BinaryAST
AST node for the binary containment testing operator (e.g.
x in y
).Attributes are:
- class ll.ul4c.NotContainsAST[source]
Bases:
BinaryAST
AST node for an inverted containment testing expression (e.g.
x not in y
).Attributes are:
- class ll.ul4c.AddAST[source]
Bases:
BinaryAST
AST node for a binary addition expression (e.g.
x + y
).Attributes are:
- class ll.ul4c.SubAST[source]
Bases:
BinaryAST
AST node for the binary subtraction expression (e.g.
x - y
).
- class ll.ul4c.MulAST[source]
Bases:
BinaryAST
AST node for the binary multiplication expression (e.g.
x * y
).Attributes are:
- class ll.ul4c.FloorDivAST[source]
Bases:
BinaryAST
AST node for a binary truncating division expression (e.g.
x // y
).Attributes are:
- class ll.ul4c.TrueDivAST[source]
Bases:
BinaryAST
AST node for a binary true division expression (e.g.
x / y
).Attributes are:
- class ll.ul4c.ModAST[source]
Bases:
BinaryAST
AST node for a binary modulo expression (e.g.
x % y
).Attributes are:
- class ll.ul4c.ShiftLeftAST[source]
Bases:
BinaryAST
AST node for a bitwise left shift expression (e.g.
x << y
).Attributes are:
- class ll.ul4c.ShiftRightAST[source]
Bases:
BinaryAST
AST node for a bitwise right shift expression (e.g.
x >> y
).Attributes are:
- class ll.ul4c.BitAndAST[source]
Bases:
BinaryAST
AST node for a binary bitwise “and” expression (e.g
x & y
).Attributes are:
- class ll.ul4c.BitXOrAST[source]
Bases:
BinaryAST
AST node for the binary bitwise “exclusive or” expression (e.g.
x ^ y
).Attributes are:
- class ll.ul4c.BitOrAST[source]
Bases:
BinaryAST
AST node for a binary bitwise “or” expression (e.g.
x | y
).Attributes are:
- class ll.ul4c.AndAST[source]
Bases:
BinaryAST
AST node for the binary “and” expression (i.e.
x and y
).Attributes are:
- class ll.ul4c.OrAST[source]
Bases:
BinaryAST
AST node for a binary “or” expression (e.g.
x or y
).Attributes are:
- class ll.ul4c.IfAST[source]
Bases:
CodeAST
AST node for the ternary inline
if/else
operator (e.g.x if y else z
).Attributes are:
- class ll.ul4c.ChangeVarAST[source]
Bases:
CodeAST
Base 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:
ChangeVarAST
AST node for setting a variable, attribute or item to a value (e.g.
x = y
).
- class ll.ul4c.AddVarAST[source]
Bases:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
ChangeVarAST
AST 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:
CodeAST
AST node for calling an object (e.g.
f(x, y)
).Attributes are:
obj
AST
The object to be called (
f
in the above example) (or rendered/printed in the subclassRenderAST
and its subclasses);args
list
The arguments to the call as a
list
ofPositionalArgumentAST
,KeywordArgumentAST
,UnpackListArgumentAST
orUnpackDictArgumentAST
objects (x
andy
in the above example).
- class ll.ul4c.RenderAST[source]
Bases:
CallAST
AST node for rendering a template (e.g.
<?render t(x)?>
.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderXAST[source]
Bases:
RenderAST
AST node for rendering a template and XML-escaping the output (e.g.
<?renderx t(x)?>
.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderOrPrintAST[source]
Bases:
RenderAST
AST node for rendering a template or printing an object.
<?render_or_print t(x)?>
is equivalent to
<?if istemplate(t)?> <?render t(x)?> <?else?> <?print t?> <?end if?>
except that even if
t
is not renderable, all argument in the call will be evaluated.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderOrPrintXAST[source]
Bases:
RenderAST
AST node for rendering a template or printing an object (e.g.
<?render_or_printx t(x)?>
.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderXOrPrintAST[source]
Bases:
RenderAST
AST node for rendering a template or printing an object (e.g.
<?renderx_or_print t(x)?>
.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderXOrPrintXAST[source]
Bases:
RenderAST
AST node for rendering a template or printing an object (e.g.
<?renderx_or_printx t(x)?>
.For a list of attribute see
CallAST
.
- class ll.ul4c.RenderBlockAST[source]
Bases:
RenderAST
AST 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:
obj
AST
The object to be rendered (
t
in the above example);args
list
The arguments to the call as a
list
ofPositionalArgumentAST
,KeywordArgumentAST
,UnpackListArgumentAST
orUnpackDictArgumentAST
objects (a
andb
in the above example).content
list
ofAST
objectsThe content of the
<?renderblock?>
tag (content
in the above example) that will be passed as a signatureless template as the keyword argumentcontent
to the object.
- class ll.ul4c.RenderBlocksAST[source]
Bases:
RenderAST
AST 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:
obj
AST
The object to be rendered (
t
in the above example);args
list
The arguments to the call as a
list
ofPositionalArgumentAST
,KeywordArgumentAST
,UnpackListArgumentAST
orUnpackDictArgumentAST
objects (a
andb
in the above example).content
list
ofAST
objectsThe content of the
<?renderblocks?>
tag. These must beAST
nodes 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:
BlockAST
A 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
Template
can 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
Template
object is itself an AST node. Evaluating it will store aTemplateClosure
object for this template under the template’s name in the local variables.- __init__(source=None, name=None, *, namespace=None, whitespace='keep', signature=None)[source]
Create a
Template
object.If
source
isNone
, theTemplate
remains uninitialized, otherwisesource
will be compiled.name
is the name of the template. It will be used in exception messages and should be a valid Python identifier.namespace
is the namespace name. It defaults to None.whitespace
specifies 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
print
orprintx
tag, 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
,else
ordef
block 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.)
signature
is the signature of the template. For a top level template it can be:None
The template will accept all keyword arguments.
- An
inspect.Signature
object 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?>
),signature
can be:None
The template will accept all arguments.
- A
SignatureAST
object 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(stream, /, *args, **kwargs)[source]
Render the template into the output stream stream.
args
andkwargs
contain 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(stream, args, kwargs, globals)[source]
Render the template into the output stream stream.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains global variables. Positional arguments will only be supported if the template has a signature.
- renders(*args, **kwargs)[source]
Render the template as a string.
args
andkwargs
contain 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.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains 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.
args
andkwargs
contain 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.
args
andkwargs
contain 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.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains 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:
CodeAST
AST node for the signature of a locally defined subtemplate.
Attributes are:
params
list
The parameter. Each list item is a
tuple
with three items:name
str
The name of the argument.
type
str
The 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)
default
AST
orNone
The default value for the argument (or
None
if the argument has no default value).
- class ll.ul4c.TemplateClosure[source]
Bases:
BlockAST
A locally defined subtemplate.
A
TemplateClosure
is a closure, i.e. it can use the local variables of the template it is defined in.
- class ll.ul4c.BoundTemplate[source]
Bases:
object
A template bound to an object.
Calling or rendering a
BoundTemplate
instance passes the object to which the template is bound as the first positional argument.- render(stream, /, *args, **kwargs)[source]
Render the template into the output stream stream.
args
andkwargs
contain 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(stream, args, kwargs, globals)[source]
Render the template into the output stream stream.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains global variables. Positional arguments will only be supported if the template has a signature.
- renders(*args, **kwargs)[source]
Render the template as a string.
args
andkwargs
contain 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.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains global variables. 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.
args
andkwargs
contain 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.
args
andkwargs
contain the top level positional and keyword arguments available to the template code.globals
contains global variables. Positional arguments will only be supported if the template has a signature.