BaseTemplate
Base class for compiled Templates.
The BaseTemplate class is accessible via the kid module.
All kid template modules expose a class named Template that extends from this class making the methods defined here available on all Template subclasses.
This class should not be instantiated directly.
Attributes
Methods
f __init__(self) ...
Initialize a template with instance attributes specified by keyword arguments.
Keyword arguments are available to the template using self.var notation.
f generate(self, encoding=None, fragment=0, output=None) ...
Execute template and generate serialized output incrementally.
This method returns an iterator that yields an encoded string for each iteration. The iteration ends when the template is done executing.
- encoding
- The output encoding. Default: utf-8.
- fragment
- Controls whether prologue information (such as <?xml?> declaration and DOCTYPE should be written). Set to 1 when generating fragments meant to be inserted into existing XML documents.
- output
- A string specifying an output method ('xml', 'html', 'xhtml') or a Serializer object.
f serialize(self, encoding=None, fragment=0, output=None) ...
Execute a template and return a single string.
- encoding
- The output encoding. Default: utf-8.
- fragment
- Controls whether prologue information (such as <?xml?> declaration and DOCTYPE should be written). Set to 1 when generating fragments meant to be inserted into existing XML documents.
- output
- A string specifying an output method ('xml', 'html', 'xhtml') or a Serializer object.
This is a convienence method, roughly equivalent to:
''.join([x for x in obj.generate(encoding, fragment, output)]
f transform(self, stream=None, filters=[]) ...
Execute the template and apply any match transformations.
If stream is specified, it must be one of the following:
- Element
- An ElementTree Element.
- ElementStream
- An pull.ElementStream instance or other iterator that yields stream events.
- string
- A file or URL unless the string starts with '<' in which case it is considered an XML document and processed as if it had been an Element.
By default, the pull method is called to obtain the stream.
f write(self, file, encoding=None, fragment=0, output=None) ...
Execute template and write output to file.
- file:file
- A filename or a file like object (must support write()).
- encoding:string
- The output encoding. Default: utf-8.
- fragment:bool
- Controls whether prologue information (such as <?xml?> declaration and DOCTYPE should be written). Set to 1 when generating fragments meant to be inserted into existing XML documents.
- output:string,`Serializer`
- A string specifying an output method ('xml', 'html', 'xhtml') or a Serializer object.
See the source for more information.