Werkzeug: 关于 werkzeug.utils.py 中的 JSON 编码

创建于 2016-01-12  ·  3评论  ·  资料来源: pallets/werkzeug

def get_content_type(mimetype,字符集):
"""返回具有 mimetype 字符集的完整内容类型字符串。
如果 mimetype 表示文本,则字符集将作为字符集附加
参数,否则返回 mimetype 不变。
:param mimetype:用作内容类型的 mimetype。
:param charset: 要附加的字符集,以防它是文本 mimetype。
:return: 内容类型。
"""
如果 mimetype.startswith('text/') 或 \
mimetype == '应用程序/xml' 或 \
(mimetype.startswith('application/') 和
mimetype.endswith('+xml')):
模仿类型 += '; 字符集=' + 字符集
返回 mimetype

我刚开始接触这个,有一个编码问题。
为什么不判断“mimetype == 'application/json'”?

最有用的评论

JSON 始终为 UTF-8。

所有3条评论

JSON 始终为 UTF-8。

@caiz还有另一个讨论: https ://github.com/request/request/issues/383,以及有关 JSON 字符集的更多详细信息: http ://tools.ietf.org/html/rfc4627#section -3

感谢您的帮助。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

golf-player picture golf-player  ·  10评论

sorenh picture sorenh  ·  4评论

Nessphoro picture Nessphoro  ·  6评论

ngaya-ll picture ngaya-ll  ·  8评论

paihu picture paihu  ·  7评论