Package genshi :: Package template :: Module base :: Class Template

Class Template



object --+
         |
        Template
Known Subclasses:
markup.MarkupTemplate, text.TextTemplate

Abstract template base class.

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



Nested Classes
  __metaclass__
Meta class for templates.
Instance Methods
 
__init__(self, source, basedir=None, filename=None, loader=None, encoding=None, lookup='lenient')
Initialize a template from either a string, a file-like object, or an already parsed markup stream.
 
__repr__(self)
repr(x)
 
generate(self, *args, **kwargs)
Apply the template to the given context data.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables
  EXPR = 'EXPR'
Stream event kind representing a Python expression.
  SUB = 'SUB'
Stream event kind representing a nested stream to which one or more directives should be applied.
Properties

Inherited from object: __class__

Method Details

__init__(self, source, basedir=None, filename=None, loader=None, encoding=None, lookup='lenient')
(Constructor)

 
Initialize a template from either a string, a file-like object, or an already parsed markup stream.
Parameters:
  • source - a string, file-like object, or markup stream to read the template from
  • basedir - the base directory containing the template file; when loaded from a TemplateLoader, this will be the directory on the template search path in which the template was found
  • filename - the name of the template file, relative to the given base directory
  • loader - the TemplateLoader to use for load included templates
  • encoding - the encoding of the source
  • lookup - the variable lookup mechanism; either "lenient" (the default), "strict", or a custom lookup class
Overrides: object.__init__

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)

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.

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