Edgewall Software


Basic templating functionality.


Base exception class for errors related to template processing.


Exception raised when an expression in a template causes a Python syntax error, or the template is not well-formed.


Exception raised when an unknown directive is encountered when parsing a template.

An unknown directive is any attribute using the namespace for directives, with a local name that doesn't match any registered directive.


Exception raised when an the evaluation of a Python expression in a template causes an error.


Container for template input data.

A context provides a stack of scopes (represented by dictionaries).

Template directives such as loops can push a new scope on the stack with data that should only be available inside the loop. When the loop terminates, that scope can get popped off the stack again.

>>> ctxt = Context(one='foo', other=1)
>>> ctxt.get('one')
>>> ctxt.get('other')
>>> ctxt.push(dict(one='frost'))
>>> ctxt.get('one')
>>> ctxt.get('other')
>>> ctxt.pop()
{'one': 'frost'}
>>> ctxt.get('one')

get(self, key, default=None)

Get a variable's value, starting at the current scope and going upward.

param key:the name of the variable
param default:the default value to return when the variable is not found


Return the name of all variables in the context.

return:a list of variable names


Return a list of (name, value) tuples for all variables in the context.

return:a list of variables

update(self, mapping)

Update the context from the mapping provided.

push(self, data)

Push a new scope on the stack.

param data:the data dictionary to push on the context stack.


Pop the top-most scope from the stack.


Create a copy of this Context object.


Meta class for directive factories.


Base for classes that provide a set of template directives.

since:version 0.6

get_directive(self, name)

Return the directive class for the given name.

param name:the directive name as used in the template
return:the directive class

get_directive_index(self, dir_cls)

Return a key for the given directive class that should be used to sort it among other directives on the same SUB event.

The default implementation simply returns the index of the directive in the directives list.

param dir_cls:the directive class
return:the sort key


Abstract template base class.

This class implements most of the template processing model, but does not specify the syntax of templates.


(Not documented)

generate(self, **args, *kwargs)

Apply the template to the given context data.

Any keyword arguments are made available to the template as context data.

Only one positional argument is accepted: if it is provided, it must be an instance of the Context class, and keyword arguments are ignored. This calling style is used for internal processing.

return:a markup event stream representing the result of applying the template to the context data.

See Genshi XML Template Language, Genshi Text Template Language, ApiDocs, Documentation

Last modified 9 years ago Last modified on Dec 10, 2015, 6:15:05 AM