TemplateStream Class

Inheritance diagram of TemplateStream

class TemplateStream(gen)

A template stream works pretty much like an ordinary python generator but it can buffer multiple items to reduce the number of total iterations. Per default the output is unbuffered which means that for every unbuffered instruction in the template one unicode string is yielded.

If buffering is enabled with a buffer size of 5, five items are combined into a new unicode string. This is mainly useful if you are streaming big templates to a client via WSGI which flushes after each iteration.

Methods

__init__(gen)
disable_buffering() Disable the output buffering.
dump(fp[, encoding, errors]) Dump the complete stream into a file or file-like object.
enable_buffering([size]) Enable buffering.
next()

Descriptions

class TemplateStream

Method details

__init__(gen)
disable_buffering()

Disable the output buffering.

dump(fp, encoding=None, errors='strict')

Dump the complete stream into a file or file-like object. Per default unicode strings are written, if you want to encode before writing specifiy an encoding.

Example usage:

Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')
enable_buffering(size=5)

Enable buffering. Buffer size items before yielding them.

next()

Table Of Contents

Previous topic

TemplateModule Class

Next topic

TemplateNotFound