OpenQuizz
Une application de gestion des contenus pédagogiques
TemplateStream Class Reference
Inheritance diagram for TemplateStream:
Collaboration diagram for TemplateStream:

Public Member Functions

def __init__ (self, gen)
 
def dump (self, fp, encoding=None, errors="strict")
 
def disable_buffering (self)
 
def enable_buffering (self, size=5)
 
def __iter__ (self)
 
def __next__ (self)
 

Data Fields

 buffered
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  gen 
)

Member Function Documentation

◆ __iter__()

def __iter__ (   self)

◆ __next__()

def __next__ (   self)

◆ disable_buffering()

def disable_buffering (   self)
Disable the output buffering.

◆ dump()

def dump (   self,
  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 specify an `encoding`.

Example usage::

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

◆ enable_buffering()

def enable_buffering (   self,
  size = 5 
)
Enable buffering.  Buffer `size` items before yielding them.

Field Documentation

◆ buffered

buffered

The documentation for this class was generated from the following file: