class cherrypy.lib.encoding.ResponseEncoder(**kwargs)

Encode a streaming response body.

Use a generator wrapper, and just pray it works as the stream is being written out.


Encode a buffered response body.


cherrypy.lib.encoding.decode(encoding=None, default_encoding='utf-8')

Replace or extend the list of charsets used to decode a request entity.

Either argument may be a single string or a list of strings.

If not None, restricts the set of charsets attempted while decoding a request entity to the given set (even if a different charset is given in the Content-Type request header).
Only in effect if the ‘encoding’ argument is not given. If given, the set of charsets attempted while decoding a request entity is extended with the given value(s).
cherrypy.lib.encoding.compress(body, compress_level)

Compress ‘body’ at the given compress_level.

cherrypy.lib.encoding.gzip(compress_level=5, mime_types=['text/html', 'text/plain'], debug=False)

Try to gzip the response body if Content-Type in mime_types.

cherrypy.response.headers[‘Content-Type’] must be set to one of the values in the mime_types arg before calling this function.

The provided list of mime-types must be of one of the following form:
  • type/subtype
  • type/*
  • type/*+subtype
No compression is performed if any of the following hold:
  • The client sends no Accept-Encoding request header
  • No ‘gzip’ or ‘x-gzip’ is present in the Accept-Encoding header
  • No ‘gzip’ or ‘x-gzip’ with a qvalue > 0 is present
  • The ‘identity’ value is given with a qvalue > 0.