``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. ============================ def ``register``​(``name``): ============================ ============================ def ``withcontext``​(``f``): ============================ 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 call be done with this decorator. ================================ class ``Error``​(``Exception``): ================================ Exception class that wraps another exception and provides a location. def ``__init__``​(``self``, ``node``, ``template``=``None``): ------------------------------------------------------------- def ``__repr__``​(``self``): ---------------------------- def ``__str__``​(``self``): --------------------------- ===================================== class ``BlockError``​(``Exception``): ===================================== Exception that is raised by the compiler when an illegal block structure is detected (e.g. an ```` without a previous ````). def ``__init__``​(``self``, ``message``): ----------------------------------------- def ``__str__``​(``self``): --------------------------- ========================================= class ``BreakException``​(``Exception``): ========================================= ============================================ class ``ContinueException``​(``Exception``): ============================================ ========================================== class ``ReturnException``​(``Exception``): ========================================== def ``__init__``​(``self``, ``value``): --------------------------------------- ================================= class ``Undefined``​(``object``): ================================= def ``__bool__``​(``self``): ---------------------------- def ``__iter__``​(``self``): ---------------------------- def ``__len__``​(``self``): --------------------------- def ``__call__``​(``self``, *``args``, **``kwargs``): ----------------------------------------------------- def ``__getattr__``​(``self``, ``key``): ---------------------------------------- def ``__getitem__``​(``self``, ``key``): ---------------------------------------- ======================================= class ``UndefinedKey``​(``Undefined``): ======================================= def ``__init__``​(``self``, ``key``): ------------------------------------- def ``__repr__``​(``self``): ---------------------------- ============================================ class ``UndefinedVariable``​(``Undefined``): ============================================ def ``__init__``​(``self``, ``name``): -------------------------------------- def ``__repr__``​(``self``): ---------------------------- ========================================= class ``UndefinedIndex``​(``Undefined``): ========================================= def ``__init__``​(``self``, ``index``): --------------------------------------- def ``__repr__``​(``self``): ---------------------------- =============================== class ``Context``​(``object``): =============================== A ``Context`` object stores the context of a call to a template. This consists of the local variables and the indent stack. def ``__init__``​(``self``): ---------------------------- def ``replacevars``​(*``args``, **``kwds``): -------------------------------------------- def ``chainvars``​(*``args``, **``kwds``): ------------------------------------------ ====================================== def ``_handleexpressioneval``​(``f``): ====================================== Decorator for an implementation of the ``eval`` method that does not do output (so it is a normal method). This decorator is responsible for exception handling. An exception that bubbles up the Python call stack will generate an exception chain that follows the UL4 call stack. ================================== def ``_handleoutputeval``​(``f``): ================================== Decorator for an implementation of the ``eval`` method that does output (so it is a generator). This decorator is responsible for exception handling. An exception that bubbles up the Python call stack will generate an exception chain that follows the UL4 call stack. =========================================== def ``_unpackvar``​(``lvalue``, ``value``): =========================================== A generator used for recursively unpacking values for assignment. ``lvalue`` may be an ``AST`` object (in which case the recursion ends) or a (possible nested) sequence of ``AST`` objects. The values produced are (AST node, value) tuples. ======================================================== def ``_makevars``​(``signature``, ``args``, ``kwargs``): ======================================================== Bind ``args`` and ``kwargs`` to the ``inspect.Signature`` object ``signature`` and return the resulting argument dictionary. (This differs from ``inspect.Signature.bind`` in that it handles default values too.) ``signature`` may also be ``None`` in which case ``args`` must be empty and :obj:kwargs is returned, i.e. the signature is treated als accepting no positional argument and any keyword argument. ======================================== def ``_ul4getattr``​(``obj``, ``name``): ======================================== Return the attribute ``name`` of the object :obj`obj` and honor ``ul4getattr`` and ``ul4attrs``. =================================================== def ``_ul4setattr``​(``obj``, ``name``, ``value``): =================================================== Set the attribute ``name`` of the object :obj`obj` to ``value`` and honor ``ul4setattr`` and ``ul4attrs``. ============================== def ``_str``​(``obj``=``''``): ============================== ========================================= def ``_repr_helper``​(``obj``, ``seen``): ========================================= ======================== def ``_repr``​(``obj``): ======================== ========================== def ``_asjson``​(``obj``): ========================== ============================= def ``_xmlescape``​(``obj``): ============================= =========================== class ``AST``​(``object``): =========================== Base class for all syntax tree nodes. def ``__init__``​(``self``, ``startpos``=``None``, ``endpos``=``None``): ------------------------------------------------------------------------ def ``_linecol``​(``source``, ``startpos``, ``endpos``): -------------------------------------------------------- def ``__repr__``​(``self``): ---------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty_``​(``self``, ``p``, ``cycle``): --------------------------------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``__str__``​(``self``): --------------------------- def ``eval``​(``self``, ``context``): ------------------------------------- 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`` is false.). For nodes that produce output (like literal text, ``Print``, ``PrintX`` or ``Render``) 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 attribute ``output`` is true.) def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ========================= class ``Text``​(``AST``): ========================= AST node for literal text. def ``__init__``​(``self``, ``source``=``None``, ``startpos``=``None``, ``endpos``=``None``): --------------------------------------------------------------------------------------------- def ``_linecol``​(``self``): ---------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- property text: -------------- def ``__get__``​(``self``): """"""""""""""""""""""""""" def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``eval``​(``self``, ``context``): ------------------------------------- ============================ class ``Indent``​(``Text``): ============================ AST node for literal text that is an indentation at the start of the line. def ``__init__``​(``self``, ``source``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``text``=``None``): ---------------------------------------------------------------------------------------------------------------- property text: -------------- def ``__get__``​(``self``): """"""""""""""""""""""""""" def ``_settext``​(``self``, ``text``): -------------------------------------- def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``eval``​(``self``, ``context``): ------------------------------------- ============================= class ``LineEnd``​(``Text``): ============================= AST node for literal text that is the end of a line. def ``_str``​(``self``): ------------------------ ======================== class ``Tag``​(``AST``): ======================== A ``Tag`` object is the location of a template tag in a template. def ``__init__``​(``self``, ``source``=``None``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``startposcode``=``None``, ``endposcode``=``None``): ------------------------------------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_linecol``​(``self``): ---------------------------- def ``__str__``​(``self``): --------------------------- property text: -------------- def ``__get__``​(``self``): """"""""""""""""""""""""""" property code: -------------- def ``__get__``​(``self``): """"""""""""""""""""""""""" def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ========================= class ``Code``​(``AST``): ========================= The base class of all AST nodes that appear inside a ``Tag``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``): ------------------------------------------------------------------------------------------ def ``_linecol``​(``self``): ---------------------------- property text: -------------- def ``__get__``​(``self``): """"""""""""""""""""""""""" def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ =========================== class ``Const``​(``Code``): =========================== Load a constant def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``value``=``None``): -------------------------------------------------------------------------------------------------------------- def ``eval``​(``self``, ``context``): ------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- ========================== class ``List``​(``Code``): ========================== AST nodes for loading a list object. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, *``items``): ------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ============================== class ``ListComp``​(``Code``): ============================== AST node for list comprehension. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``item``=``None``, ``varname``=``None``, ``container``=``None``, ``condition``=``None``): ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ========================= class ``Set``​(``Code``): ========================= AST nodes for loading a set object. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, *``items``): ------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ============================= class ``SetComp``​(``Code``): ============================= AST node for set comprehension. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``item``=``None``, ``varname``=``None``, ``container``=``None``, ``condition``=``None``): ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ========================== class ``Dict``​(``Code``): ========================== AST node for loading a dict object. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, *``items``): ------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ============================== class ``DictComp``​(``Code``): ============================== AST node for dictionary comprehension. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``key``=``None``, ``value``=``None``, ``varname``=``None``, ``container``=``None``, ``condition``=``None``): ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ def ``__repr__``​(``self``): ---------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ============================= class ``GenExpr``​(``Code``): ============================= AST node for a generator expression. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``item``=``None``, ``varname``=``None``, ``container``=``None``, ``condition``=``None``): ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, ``context``): ------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ========================= class ``Var``​(``Code``): ========================= AST nodes for loading a variable. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``name``=``None``): ------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``evalset``​(``self``, *``args``, **``kwargs``): ---------------------------------------------------- def ``evalmodify``​(``self``, *``args``, **``kwargs``): ------------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ =========================== class ``Block``​(``Code``): =========================== 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 ```` block) or more times (e.g. a ```` block). def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``): ------------------------------------------------------------------------------------------ def ``append``​(``self``, ``item``): ------------------------------------ def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ================================ class ``CondBlock``​(``Block``): ================================ AST node for an conditional block. The content of the ``CondBlock`` block is one ``IfBlock`` block followed by zero or more ``ElIfBlock`` blocks followed by zero or one ``ElseBlock`` block. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``condition``=``None``): ------------------------------------------------------------------------------------------------------------------ def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``append``​(``self``, ``item``): ------------------------------------ def ``newblock``​(``self``, ``block``): --------------------------------------- def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================== class ``IfBlock``​(``Block``): ============================== AST node for an ```` block. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``condition``=``None``): ------------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ================================ class ``ElIfBlock``​(``Block``): ================================ AST node for an ```` block. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``condition``=``None``): ------------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ================================ class ``ElseBlock``​(``Block``): ================================ AST node for an ```` block. def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_str``​(``self``): ------------------------ =============================== class ``ForBlock``​(``Block``): =============================== AST node for a ```` loop. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``varname``=``None``, ``container``=``None``): ---------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ================================= class ``WhileBlock``​(``Block``): ================================= AST node for a ```` loop. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``condition``=``None``): ------------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- =========================== class ``Break``​(``Code``): =========================== AST node for a ```` inside a ```` block. def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================== class ``Continue``​(``Code``): ============================== AST node for a ```` inside a ```` block. def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ========================== class ``Attr``​(``Code``): ========================== AST node for getting and setting an attribute of an object. The object is loaded from the AST node ``obj`` and the attribute name is stored in the string ``attrname``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``obj``=``None``, ``attrname``=``None``): ----------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``method_str``​(``self``, ``obj``, ``methname``): ----------------------------------------------------- def ``method_list``​(``self``, ``obj``, ``methname``): ------------------------------------------------------ def ``method_set``​(``self``, ``obj``, ``methname``): ----------------------------------------------------- def ``method_ul4attrs``​(``self``, ``obj``, ``methname``): ---------------------------------------------------------- def ``method_dict``​(``self``, ``obj``, ``methname``): ------------------------------------------------------ def ``method_date``​(``self``, ``obj``, ``methname``): ------------------------------------------------------ def ``method_timedelta``​(``self``, ``obj``, ``methname``): ----------------------------------------------------------- def ``evalset``​(``self``, *``args``, **``kwargs``): ---------------------------------------------------- def ``evalmodify``​(``self``, *``args``, **``kwargs``): ------------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ =========================== class ``Slice``​(``Code``): =========================== AST node for creating a slice object (used in ``obj[index1:index2]``). The start and stop indices are loaded from the AST nodes ``index1`` and ``index2``. ``index1`` and ``index2`` may also be ``None`` (for missing slice indices, which default to the 0 for the start index and the length of the sequence for the end index). def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``index1``=``None``, ``index2``=``None``): ------------------------------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ =========================== class ``Unary``​(``Code``): =========================== Base class for all AST nodes implementing unary operators. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``obj``=``None``): ------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ========================== class ``Not``​(``Unary``): ========================== AST node for the unary ``not`` operator. ========================== class ``Neg``​(``Unary``): ========================== AST node for the unary negation (i.e. "-") operator. ============================= class ``BitNot``​(``Unary``): ============================= AST node for the bitwise not operator. ============================ class ``Print``​(``Unary``): ============================ AST node for a ```` tag. def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================= class ``PrintX``​(``Unary``): ============================= AST node for a ```` tag. def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================= class ``Return``​(``Unary``): ============================= AST node for a ```` tag. def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================ class ``Binary``​(``Code``): ============================ Base class for all AST nodes implementing binary operators. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``obj1``=``None``, ``obj2``=``None``): -------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ============================ class ``Item``​(``Binary``): ============================ AST node for subscripting operator. The object (which must be a list, string or dict) is loaded from the AST node ``obj1`` and the index/key is loaded from the AST node ``obj2``. def ``evalset``​(``self``, *``args``, **``kwargs``): ---------------------------------------------------- def ``evalmodify``​(``self``, *``args``, **``kwargs``): ------------------------------------------------------- ========================== class ``Is``​(``Binary``): ========================== AST node for the binary ``is`` comparison operator. ============================= class ``IsNot``​(``Binary``): ============================= AST node for the binary ``is not`` comparison operator. ========================== class ``EQ``​(``Binary``): ========================== AST node for the binary ``==`` comparison operator. ========================== class ``NE``​(``Binary``): ========================== AST node for the binary ``!=`` comparison operator. ========================== class ``LT``​(``Binary``): ========================== AST node for the binary ``<`` comparison operator. ========================== class ``LE``​(``Binary``): ========================== AST node for the binary ``<=`` comparison operator. ========================== class ``GT``​(``Binary``): ========================== AST node for the binary ``>`` comparison operator. ========================== class ``GE``​(``Binary``): ========================== AST node for the binary ``>=`` comparison operator. ================================ class ``Contains``​(``Binary``): ================================ AST node for the binary containment testing operator. The item/key object is loaded from the AST node ``obj1`` and the container object (which must be a list, string, dict or an object with a ``ul4attrs`` attribute) is loaded from the AST node ``obj2``. =================================== class ``NotContains``​(``Binary``): =================================== AST node for the inverted containment testing operator. The item/key object is loaded from the AST node ``obj1`` and the container object (which must be a list, string, dict or an object with a ``ul4attrs`` attribute) is loaded from the AST node ``obj2``. =========================== class ``Add``​(``Binary``): =========================== AST node for the binary addition operator. =========================== class ``Sub``​(``Binary``): =========================== AST node for the binary substraction operator. =========================== class ``Mul``​(``Binary``): =========================== AST node for the binary multiplication operator. ================================ class ``FloorDiv``​(``Binary``): ================================ AST node for the binary truncating division operator. =============================== class ``TrueDiv``​(``Binary``): =============================== AST node for the binary true division operator. =========================== class ``Mod``​(``Binary``): =========================== AST node for the binary modulo operator. ================================= class ``ShiftLeft``​(``Binary``): ================================= AST node for the bitwise left shift operator. ================================== class ``ShiftRight``​(``Binary``): ================================== AST node for the bitwise right shift operator. ============================== class ``BitAnd``​(``Binary``): ============================== AST node for the binary bitwise and operator (``&``). ============================== class ``BitXOr``​(``Binary``): ============================== AST node for the binary bitwise exclusive or operator (``^``). ============================= class ``BitOr``​(``Binary``): ============================= AST node for the binary bitwise or operator (``|``). =========================== class ``And``​(``Binary``): =========================== AST node for the binary ``and`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ========================== class ``Or``​(``Binary``): ========================== AST node for the binary ``or`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ======================== class ``If``​(``Code``): ======================== AST node for the ternary inline ``if/else`` operator. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``objif``=``None``, ``objcond``=``None``, ``objelse``=``None``): ---------------------------------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- =============================== class ``ChangeVar``​(``Code``): =============================== Baseclass for all AST nodes that store or modify a variable. The left hand side is loaded from the AST node ``label`` and the value that will be stored or be used to modify the stored value is loaded from the AST node ``value``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``lvalue``=``None``, ``value``=``None``): ----------------------------------------------------------------------------------------------------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ================================= class ``SetVar``​(``ChangeVar``): ================================= AST node that stores a value into a variable. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ================================= class ``AddVar``​(``ChangeVar``): ================================= AST node that adds a value to a variable (i.e. the ``+=`` operator). def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ================================= class ``SubVar``​(``ChangeVar``): ================================= AST node that substracts a value from a variable (i.e. the ``-=`` operator). def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ================================= class ``MulVar``​(``ChangeVar``): ================================= AST node that multiplies a variable by a value (i.e. the ``*=`` operator). def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ====================================== class ``FloorDivVar``​(``ChangeVar``): ====================================== AST node that divides a variable by a value (truncating to an integer value; i.e. the ``//=`` operator). def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ===================================== class ``TrueDivVar``​(``ChangeVar``): ===================================== AST node that divides a variable by a value (i.e. the ``/=`` operator). def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ================================= class ``ModVar``​(``ChangeVar``): ================================= AST node for the ``%=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ======================================= class ``ShiftLeftVar``​(``ChangeVar``): ======================================= AST node for the ``<<=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ======================================== class ``ShiftRightVar``​(``ChangeVar``): ======================================== AST node for the ``>>=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ==================================== class ``BitAndVar``​(``ChangeVar``): ==================================== AST node for the ``&=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ==================================== class ``BitXOrVar``​(``ChangeVar``): ==================================== AST node for the ``^=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- =================================== class ``BitOrVar``​(``ChangeVar``): =================================== AST node for the ``|=`` operator. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- ========================== class ``Call``​(``Code``): ========================== AST node for calling an object. The object to be called is stored in the attribute ``obj``. The list of arguments is found in ``args``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``obj``=``None``): ------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, ``context``): ------------------------------------- def ``evalset``​(``self``, *``args``, **``kwargs``): ---------------------------------------------------- def ``evalmodify``​(``self``, *``args``, **``kwargs``): ------------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ============================ class ``Render``​(``Call``): ============================ AST node for rendering a template. The template to be rendered is stored in the attribute ``obj``. The list of arguments is found in ``args``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``, ``obj``=``None``): ------------------------------------------------------------------------------------------------------------ def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``eval``​(``self``, ``context``): ------------------------------------- def ``_str``​(``self``): ------------------------ def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ =============================== class ``Template``​(``Block``): =============================== 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) or ``loads`` (from a string). The compiled format can be generated with the methods ``dump`` (which dumps the format to a stream) or ``dumps`` (which returns a string with the compiled format). Rendering the template can be done with the methods ``render`` (which is a generator) or ``renders`` (which returns a string). A ``Template`` can also be called as a function (returning the result of the first ```` tag encountered). In this case all output of the template will be ignored. A ``Template`` object is itself an AST node. Evaluating it will store the template object under its name in the local variables. def ``__init__``​(``self``, ``source``=``None``, ``name``=``None``, ``whitespace``=``'keep'``, ``startdelim``=``''``, ``signature``=``None``): ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- Create a ``Template`` object. If ``source`` is ``None``, the ``Template`` remains uninitialized, otherwise ``source`` will be compiled (using ``startdelim`` and ``enddelim`` as the tag delimiters). ``name`` is the name of the template. It will be used in exception messages and should be a valid Python identifier. ``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`` or ``printx`` tag, the indentation and the linefeed after the tag will be stripped from the text. Furthermore the additional indentation that might be introduced by a ``for``, ``if``, ``elif``, ``else`` or ``def`` block will be ignored. So for example the output of: 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 subtemplate (i.e. a template defined by another template via ``...``), ``signature`` can be: ``None`` The template will accept all arguments. A ``Signature`` object This AST node will be evaluated at the point of definition of the subtemplate to create the final signature of the subtemplate. def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_str``​(``self``): ------------------------ def ``ul4getattr``​(``self``, ``name``): ---------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ def ``dump``​(``self``, ``stream``): ------------------------------------ ``dump`` dumps the template/function in compiled UL4ON format to the stream ``stream``. def ``dumps``​(``self``): ------------------------- ``dumps`` returns the template/function in compiled UL4ON format (as a string). def ``_renderbound``​(``self``, ``context``): --------------------------------------------- def ``ul4render``​(*``args``, **``kwargs``): -------------------------------------------- def ``render``​(*``args``, **``kwargs``): ----------------------------------------- Render the template iteratively (i.e. this is a generator). ``args[1:]`` and ``kwargs`` contain the top level variables available to the template code. (``args[0]`` is the ``self`` parameter, but ``render`` is defined in this way, to allow a keyword argument named ``self``). def ``_rendersbound``​(``self``, ``context``): ---------------------------------------------- def ``ul4renders``​(*``args``, **``kwargs``): --------------------------------------------- def ``renders``​(*``args``, **``kwargs``): ------------------------------------------ Render the template as a string. ``vars`` contains the top level variables available to the template code. def ``_callbound``​(``self``, ``context``): ------------------------------------------- def ``ul4call``​(*``args``, **``kwargs``): ------------------------------------------ Call the template as a function and return the resulting value. ``vars`` contains the top level variables available to the template code. def ``__call__``​(*``args``, **``kwargs``): ------------------------------------------- Call the template as a function and return the resulting value. ``vars`` contains the top level variables available to the template code. def ``jssource``​(``self``): ---------------------------- Return the template as the source code of a Javascript function. def ``javasource``​(``self``): ------------------------------ Return the template as Java source code. def ``_tokenize``​(``self``, ``source``, ``startdelim``, ``enddelim``): ----------------------------------------------------------------------- Tokenize the template/function source code ``source`` into tags and non-tag text. ``startdelim`` and ``enddelim`` are used as the tag delimiters. This is a generator which produces ``Text``/``Tag`` objects for each tag or non-tag text. It will be called by ``_compile`` internally. def ``_tags2lines``​(``self``, ``tags``): ----------------------------------------- Transforms an iterable of tags into an iterable of lines by splitting the literal text between the tags into lines. A line is a list of nodes and will start with an ``Indent`` node (containing the indenting whitespace if the line is indented, or an empty indentation if it isn't) and might end with a ``LineEnd`` node (containing the line feed if the line is terminated (which most lines (except maybe the last one) are)). def ``_whitespace_keep``​(``self``, ``lines``): ----------------------------------------------- def ``_whitespace_strip``​(``self``, ``lines``): ------------------------------------------------ def ``_whitespace_smart``​(``self``, ``lines``): ------------------------------------------------ def ``_parser``​(``self``, ``tag``, ``error``): ----------------------------------------------- def ``_parsesignature``​(``self``, ``tag``): -------------------------------------------- def ``_compile``​(``self``, ``source``, ``name``, ``startdelim``, ``enddelim``): -------------------------------------------------------------------------------- Compile the template source code ``source`` into an AST. ``startdelim`` and ``enddelim`` are used as the tag delimiters. def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- =============================== class ``Signature``​(``Code``): =============================== AST node for the signature of a template. The list of arguments is found in ``params``. def ``__init__``​(``self``, ``tag``=``None``, ``startpos``=``None``, ``endpos``=``None``): ------------------------------------------------------------------------------------------ def ``__repr__``​(``self``): ---------------------------- def ``_repr_pretty``​(``self``, ``p``): --------------------------------------- def ``_str``​(``self``): ------------------------ def ``eval``​(``self``, *``args``, **``kwargs``): ------------------------------------------------- def ``ul4ondump``​(``self``, ``encoder``): ------------------------------------------ def ``ul4onload``​(``self``, ``decoder``): ------------------------------------------ ====================================== def ``function_str``​(``obj``=``''``): ====================================== ================================ def ``function_repr``​(``obj``): ================================ ======================== def ``function_now``​(): ======================== ================================================================================================================================ def ``function_date``​(``year``, ``month``, ``day``, ``hour``=``0``, ``minute``=``0``, ``second``=``0``, ``microsecond``=``0``): ================================================================================================================================ ======================================================================================= def ``function_timedelta``​(``days``=``0``, ``seconds``=``0``, ``microseconds``=``0``): ======================================================================================= =============================================== def ``function_monthdelta``​(``months``=``0``): =============================================== ===================================== def ``function_xmlescape``​(``obj``): ===================================== =============================== def ``function_csv``​(``obj``): =============================== ================================== def ``function_asjson``​(``obj``): ================================== ======================================= def ``function_fromjson``​(``string``): ======================================= =================================== def ``function_asul4on``​(``obj``): =================================== ======================================== def ``function_fromul4on``​(``string``): ======================================== ======================================================== def ``function_int``​(``obj``=``0``, ``base``=``None``): ======================================================== ========================================= def ``function_float``​(``obj``=``0.0``): ========================================= ========================================== def ``function_bool``​(``obj``=``False``): ========================================== ============================================ def ``function_list``​(``iterable``=``()``): ============================================ =========================================== def ``function_set``​(``iterable``=``()``): =========================================== ==================================== def ``function_len``​(``sequence``): ==================================== ================================== def ``function_abs``​(``number``): ================================== ==================================== def ``function_any``​(``iterable``): ==================================== ==================================== def ``function_all``​(``iterable``): ==================================== ======================================================== def ``function_enumfl``​(``iterable``, ``start``=``0``): ======================================================== ============================================ def ``function_isfirstlast``​(``iterable``): ============================================ ======================================== def ``function_isfirst``​(``iterable``): ======================================== ======================================= def ``function_islast``​(``iterable``): ======================================= ======================================= def ``function_isundefined``​(``obj``): ======================================= ===================================== def ``function_isdefined``​(``obj``): ===================================== ================================== def ``function_isnone``​(``obj``): ================================== ================================= def ``function_isstr``​(``obj``): ================================= ================================= def ``function_isint``​(``obj``): ================================= =================================== def ``function_isfloat``​(``obj``): =================================== ================================== def ``function_isbool``​(``obj``): ================================== ================================== def ``function_isdate``​(``obj``): ================================== ======================================= def ``function_istimedelta``​(``obj``): ======================================= ======================================== def ``function_ismonthdelta``​(``obj``): ======================================== ================================== def ``function_islist``​(``obj``): ================================== ================================= def ``function_isset``​(``obj``): ================================= ================================== def ``function_isdict``​(``obj``): ================================== =================================== def ``function_iscolor``​(``obj``): =================================== ====================================== def ``function_istemplate``​(``obj``): ====================================== ====================================== def ``function_isfunction``​(``obj``): ====================================== ============================= def ``function_chr``​(``i``): ============================= ============================= def ``function_ord``​(``c``): ============================= ================================== def ``function_hex``​(``number``): ================================== ================================== def ``function_oct``​(``number``): ================================== ================================== def ``function_bin``​(``number``): ================================== ================================= def ``function_min``​(*``args``): ================================= ================================= def ``function_max``​(*``args``): ================================= ============================================================ def ``function_first``​(``iterable``, ``default``=``None``): ============================================================ =========================================================== def ``function_last``​(``iterable``, ``default``=``None``): =========================================================== ===================================================== def ``function_sum``​(``iterable``, ``start``=``0``): ===================================================== ======================================= def ``function_sorted``​(``iterable``): ======================================= =================================== def ``function_range``​(*``args``): =================================== =================================== def ``function_slice``​(*``args``): =================================== ================================ def ``function_type``​(``obj``): ================================ ========================================= def ``function_reversed``​(``sequence``): ========================================= ======================================= def ``function_randrange``​(*``args``): ======================================= =========================================== def ``function_randchoice``​(``sequence``): =========================================== ============================================================== def ``function_format``​(``obj``, ``fmt``, ``lang``=``None``): ============================================================== ====================================== def ``function_zip``​(*``iterables``): ====================================== ======================================= def ``function_urlquote``​(``string``): ======================================= ========================================= def ``function_urlunquote``​(``string``): ========================================= ========================================================== def ``function_rgb``​(``r``, ``g``, ``b``, ``a``=``1.0``): ========================================================== ========================================================== def ``function_hls``​(``h``, ``l``, ``s``, ``a``=``1.0``): ========================================================== ========================================================== def ``function_hsv``​(``h``, ``s``, ``v``, ``a``=``1.0``): ========================================================== ================================================= def ``function_round``​(``x``, ``digits``=``0``): ================================================= ================================================= def ``function_floor``​(``x``, ``digits``=``0``): ================================================= ================================================ def ``function_ceil``​(``x``, ``digits``=``0``): ================================================ ============================== def ``function_sqrt``​(``x``): ============================== ============================= def ``function_cos``​(``x``): ============================= ============================= def ``function_sin``​(``x``): ============================= ============================= def ``function_tan``​(``x``): ============================= ============================= def ``function_exp``​(``x``): ============================= ================================================ def ``function_log``​(``x``, ``base``=``None``): ================================================ ==================================== def ``function_pow``​(``x``, ``y``): ==================================== ====================================== class ``TemplateClosure``​(``Block``): ====================================== def ``__init__``​(``self``, ``template``, ``context``, ``signature``): ---------------------------------------------------------------------- def ``ul4render``​(*``args``, **``kwargs``): -------------------------------------------- def ``renders``​(*``args``, **``kwargs``): ------------------------------------------ def ``ul4call``​(*``args``, **``kwargs``): ------------------------------------------ def ``__getattr__``​(``self``, ``name``): ----------------------------------------- def ``_repr``​(``self``): ------------------------- def ``_repr_pretty``​(``self``, ``p``): ---------------------------------------