genshi.template.base
Basic templating functionality.
TemplateError
Base exception class for errors related to template processing.
TemplateSyntaxError
Exception raised when an expression in a template causes a Python syntax error, or the template is not well-formed.
BadDirectiveError
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.
TemplateRuntimeError
Exception raised when an the evaluation of a Python expression in a template causes an error.
Context
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') 'foo' >>> ctxt.get('other') 1 >>> ctxt.push(dict(one='frost')) >>> ctxt.get('one') 'frost' >>> ctxt.get('other') 1 >>> ctxt.pop() {'one': 'frost'} >>> ctxt.get('one') 'foo'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 keys(self)Return the name of all variables in the context.
return: a list of variable names items(self)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(self)Pop the top-most scope from the stack.
DirectiveFactoryMeta
Meta class for directive factories.
DirectiveFactory
Base for classes that provide a set of template directives.
since: version 0.6 compare_directives(self)Return a function that takes two directive classes and compares them to determine their relative ordering.
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 see: Directive
Template
Abstract template base class.
This class implements most of the template processing model, but does not specify the syntax of templates.
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
