cherrypy.lib.编码模块¶
- class cherrypy.lib.encoding.ResponseEncoder(**kwargs)[源代码]¶
基类:
object
- add_charset = True¶
- debug = False¶
- default_encoding = 'utf-8'¶
- encoding = None¶
- errors = 'strict'¶
- failmsg = 'Response body could not be encoded with %r.'¶
- text_only = True¶
- cherrypy.lib.encoding.decode(encoding=None, default_encoding='utf-8')[源代码]¶
替换或扩展用于解码请求实体的字符集列表。
参数可以是单个字符串或字符串列表。
- 编码
如果不是“无”,则限制将请求实体解码到给定集时尝试的字符集集(即使在内容类型请求头中给定了不同的字符集)。
- default_encoding
仅在未给定“encoding”参数时有效。如果给定,则在解码请求实体时尝试的字符集集为 扩展的 具有给定值。
- 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。