genshi.template.base.Template

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

# Class Template

          object --+
                   |
    DirectiveFactory --+
                       |
                      Template

Known Subclasses:
  - text.NewTextTemplate
  - , text.OldTextTemplate
  - , markup.MarkupTemplate

Abstract template base class.

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

Nested Classes
Inherited from `DirectiveFactory`: `__metaclass__`

Instance Methods
__init__(self, source, filepath=None, filename=None, loader=None, encoding=None, lookup=`'``strict``'`, allow_exec=True) Initialize a template from either a string, a file-like object, or an already parsed markup stream. |
__getstate__(self) |
__setstate__(self, state) |
__repr__(self) repr(x) |
generate(self, *args, **kwargs) Apply the template to the given context data. |
Inherited from `DirectiveFactory`: `get_directive`, `get_directive_index` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables
| EXEC = `'EXEC'` Stream event kind representing a Python code suite to execute.
| EXPR = `'EXPR'` Stream event kind representing a Python expression.
| INCLUDE = `'INCLUDE'` Stream event kind representing the inclusion of another template.
| SUB = `'SUB'` Stream event kind representing a nested stream to which one or more directives should be applied.
| serializer = `None` hash(x)
Inherited from `DirectiveFactory`: `directives`

Properties
| stream
Inherited from `object`: `__class__`

Method Details

### __init__(self, source, filepath=None, filename=None, loader=None, encoding=None, lookup=`'``strict``'`, allow_exec=True) (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 `filepath` - the absolute path to the template file `filename` - the path to the template file relative to the search path `loader` - the TemplateLoader to use for loading included templates `encoding` - the encoding of the `source` `lookup` - the variable lookup mechanism; either "strict" (the default), "lenient", or a custom lookup class `allow_exec` - whether Python code blocks in templates should be allowed Overrides: object.__init__ Note: Changed in 0.5: Added the `allow_exec` argument

### __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.

Property Details

### stream Get Method: unreachable.stream(self)