cherrypy.lib.编码模块

class cherrypy.lib.encoding.ResponseEncoder(**kwargs)[源代码]

基类:object

add_charset = True
debug = False
default_encoding = 'utf-8'
encode_stream(encoding)[源代码]

对流响应正文进行编码。

使用一个生成器包装器,并祈祷它在流被写出时工作。

encode_string(encoding)[源代码]

对缓冲响应体进行编码。

encoding = None
errors = 'strict'
failmsg = 'Response body could not be encoded with %r.'
find_acceptable_charset()[源代码]
text_only = True
class cherrypy.lib.encoding.UTF8StreamEncoder(iterator)[源代码]

基类:object

close()[源代码]
next()[源代码]
cherrypy.lib.encoding.compress(body, compress_level)[源代码]

在给定的压缩级别压缩“body”。

cherrypy.lib.encoding.decode(encoding=None, default_encoding='utf-8')[源代码]

替换或扩展用于解码请求实体的字符集列表。

参数可以是单个字符串或字符串列表。

编码

如果不是“无”,则限制将请求实体解码到给定集时尝试的字符集集(即使在内容类型请求头中给定了不同的字符集)。

default_encoding

仅在未给定“encoding”参数时有效。如果给定,则在解码请求实体时尝试的字符集集为 扩展的 具有给定值。

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

尝试gzip响应主体,如果内容类型为mime_类型。

cherrypy.response.headers ['Content-Type'] 在调用此函数之前,必须设置为mime_types arg中的一个值。

提供的mime类型列表必须采用以下形式之一:
  • type/subtype

  • type/*

  • type/*+subtype

如果存在以下任何一种情况,则不执行压缩:
  • 客户端不发送接受编码请求头

  • 接受编码头中不存在“gzip”或“x-gzip”

  • 不存在qvalue>0的“gzip”或“x-gzip”

  • “Identity”值的qValue大于0。

cherrypy.lib.encoding.prepare_iter(value)[源代码]

确保响应主体是可重写的,并且在为空时解析为false。