一组独立于框架的http协议实用程序。

httptools的Python项目详细描述


Build Status

httptools是nodejs http解析器的python绑定。它仍然在一个 很早的开发阶段,预计api会崩溃。

该包在pypi上可用:pip install httptools

API

httptools包含两个类httptools.HttpRequestParserhttptools.HttpResponseParser和解析url的函数 httptools.parse_url。有关示例,请参见单元测试。

classHttpRequestParser:def__init__(self,protocol):"""HttpRequestParser        protocol -- a Python object with the following methods        (all optional):          - on_message_begin()          - on_url(url: bytes)          - on_header(name: bytes, value: bytes)          - on_headers_complete()          - on_body(body: bytes)          - on_message_complete()          - on_chunk_header()          - on_chunk_complete()          - on_status(status: bytes)        """defget_http_version(self)->str:"""Return an HTTP protocol version."""defshould_keep_alive(self)->bool:"""Return ``True`` if keep-alive mode is preferred."""defshould_upgrade(self)->bool:"""Return ``True`` if the parsed request is a valid Upgrade request.	The method exposes a flag set just before on_headers_complete.	Calling this method earlier will only yield `False`.	"""deffeed_data(self,data:bytes):"""Feed data to the parser.        Will eventually trigger callbacks on the ``protocol``        object.        On HTTP upgrade, this method will raise an        ``HttpParserUpgrade`` exception, with its sole argument        set to the offset of the non-HTTP data in ``data``.        """defget_method(self)->bytes:"""Return HTTP request method (GET, HEAD, etc)"""classHttpResponseParser:"""Has all methods except ``get_method()`` that    HttpRequestParser has."""defget_status_code(self)->int:"""Return the status code of the HTTP response"""defparse_url(url:bytes):"""Parse URL strings into a structured Python object.    Returns an instance of ``httptools.URL`` class with the    following attributes:      - schema: bytes      - host: bytes      - port: int      - path: bytes      - query: bytes      - fragment: bytes      - userinfo: bytes    """

开发

  1. 使用克隆此存储库 git clone --recursive git@github.com:MagicStack/httptools.git

  2. 使用Python3.5创建虚拟环境: python3.5 -m venv envname

  3. 使用source envname/bin/activate

    激活环境
  4. pip install cython安装cython

  5. 运行makemake test

许可证

麻省理工学院。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
serversocket Java服务器socket中断如何   java通过随机类和排序为数组生成数据   @Column length大于255个字符的java实体   java在使用NIO2 API时消除检查异常   java使用用户凭据通过Microsoft Graph API上的控制台应用程序发送电子邮件   java将2个ArrayList一个接一个地显示到jTextArea中,根据输入的数据多次显示   java无法使用导入的库。安卓工作室。谷歌云端点jar   spring boot Neo4j Apoc在java中获取结果摘要时的情况   转义特殊字符javajson   无法在java中使用OpenCV读取图像,涉及unicode路径   swing Document Listener java“无法实例化DocumentListener类型”   java Piglatin,难以理解如何移动“.”一串   java映射请求基于一个可观察对象中的每个元素,使用改进?   java在可扩展字符串中搜索时,如何忽略字符的大小写?   在包中分组类的java约定   python为Java应用程序创建Ubuntu指示小程序   java Camunda:如何通过processInstanceId获取所有已完成的任务