解析ietf rfcs中定义的格式。
ietfparse的Python项目详细描述
等等…为什么?什么??
这是对大量解析url、mime头的方法的本能反应, http消息和ietf-rfcs描述的其他东西。它们的范围从 python标准库(urllib)将埋在其他 kitchen sink库(werkzeug)中的大多数库在一个库中被破坏 不管怎样。
那为什么还要创造另一个呢?好问题…很高兴你问了。这是 一个与伟大的软件包相关的图书馆 与其他系统通信。我将集中精力提供 一组清晰且可用的api,主要用于解析文本。没别的了。 希望通过专注于分析事物的特定任务,结果 将是一个漂亮且可用的文本字符串接口,该文本字符串为 互联网世界。
下面是这个库允许您编写的代码示例:
from ietfparse import algorithms, headers def negotiate_versioned_representation(request, handler, data_dict): requested = headers.parse_accept(request.headers['Accept']) selected = algorithms.select_content_type(requested, [ headers.parse_content_type('application/example+json; v=1'), headers.parse_content_type('application/example+json; v=2'), headers.parse_content_type('application/json'), ]) output_version = selected.parameters.get('v', '2') if output_version == '1': handler.set_header('Content-Type', 'application/example+json; v=1') handler.write(generate_legacy_json(data_dict)) else: handler.set_header('Content-Type', 'application/example+json; v=2') handler.write(generate_modern_json(data_dict)) def redirect_to_peer(host, port=80): flask.redirect(algorithms.rewrite_url(flask.request.url, host=host, port=port))