class documentation

class TemplateStream:

View In Hierarchy

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 string is yielded.

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

Method disable​_buffering Disable the output buffering.
Method dump Dump the complete stream into a file or file-like object. Per default strings are written, if you want to encode before writing specify an encoding.
Method enable​_buffering Enable buffering. Buffer size items before yielding them.
Method __init__ Undocumented
Method __iter__ Undocumented
Method __next__ Undocumented
Method ​_buffered​_generator Undocumented
Instance Variable ​_gen Undocumented
Instance Variable ​_next Undocumented
Instance Variable buffered Undocumented
def disable_buffering(self):
Disable the output buffering.
def dump(self, fp, encoding=None, errors='strict'):

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

Example usage:

Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')
Parameters
fp:t.Union[str, t.IO]Undocumented
encoding:t.Optional[str]Undocumented
errors:t.Optional[str]Undocumented
def enable_buffering(self, size=5):
Enable buffering. Buffer size items before yielding them.
Parameters
size:intUndocumented
def __init__(self, gen):

Undocumented

Parameters
gen:t.Iterator[str]Undocumented
def __iter__(self):

Undocumented

Returns
TemplateStreamUndocumented
def __next__(self):

Undocumented

Returns
strUndocumented
def _buffered_generator(self, size):

Undocumented

Parameters
size:intUndocumented
Returns
t.Iterator[str]Undocumented
_gen =

Undocumented

_next =

Undocumented

buffered: bool =

Undocumented