跳转到主要内容

一套框架无关的HTTP协议工具。

项目描述

Tests

httptools是nodejs HTTP解析器的Python绑定。

此软件包可在PyPI上获取: pip install httptools

APIs

httptools包含两个类 httptools.HttpRequestParser, httptools.HttpResponseParser(通过 llhttp 实现),以及一个用于解析URL的函数 httptools.parse_url(目前通过 http-parse 实现)。请参阅单元测试以获取示例。

class HttpRequestParser:

    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)
        """

    def get_http_version(self) -> str:
        """Return an HTTP protocol version."""

    def should_keep_alive(self) -> bool:
        """Return ``True`` if keep-alive mode is preferred."""

    def should_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`.
	"""

    def feed_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``.
        """

    def get_method(self) -> bytes:
        """Return HTTP request method (GET, HEAD, etc)"""


class HttpResponseParser:

    """Has all methods except ``get_method()`` that
    HttpRequestParser has."""

    def get_status_code(self) -> int:
        """Return the status code of the HTTP response"""


def parse_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. 使用Python 3创建虚拟环境: python3 -m venv envname

  3. 使用以下命令激活环境: source envname/bin/activate

  4. 使用 pip install -e .[test] 安装开发需求。

  5. 运行 makemake test

许可

MIT。

项目详情


下载文件

下载适合您平台的项目文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

httptools-0.6.1.tar.gz (191.2 kB 查看哈希值)

上传时间 源代码

构建分发

httptools-0.6.1-cp312-cp312-win_amd64.whl (55.7 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

httptools-0.6.1-cp312-cp312-musllinux_1_1_x86_64.whl (343.5 kB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.1+ x86-64

httptools-0.6.1-cp312-cp312-musllinux_1_1_aarch64.whl (345.1 kB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.1+ ARM64

httptools-0.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (345.4 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ ARM64

httptools-0.6.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (344.7 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httptools-0.6.1-cp312-cp312-macosx_10_9_x86_64.whl (75.8 kB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ x86-64

httptools-0.6.1-cp312-cp312-macosx_10_9_universal2.whl (146.4 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

httptools-0.6.1-cp311-cp311-win_amd64.whl (55.4 kB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

httptools-0.6.1-cp311-cp311-musllinux_1_1_x86_64.whl (322.2 kB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.1+ x86-64

httptools-0.6.1-cp311-cp311-musllinux_1_1_aarch64.whl (330.2 kB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.1+ ARM64

httptools-0.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (324.8 kB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ ARM64

httptools-0.6.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318.5 kB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httptools-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl (75.6 kB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ x86-64

httptools-0.6.1-cp311-cp311-macosx_10_9_universal2.whl (145.9 kB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

httptools-0.6.1-cp310-cp310-win_amd64.whl (58.2 kB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

httptools-0.6.1-cp310-cp310-musllinux_1_1_x86_64.whl (347.8 kB 查看哈希值)

上传于 CPython 3.10 musllinux: musl 1.1+ x86-64

httptools-0.6.1-cp310-cp310-musllinux_1_1_aarch64.whl (354.5 kB 查看哈希值)

上传于 CPython 3.10 musllinux: musl 1.1+ ARM64

httptools-0.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (346.7 kB 查看哈希)

上传时间 CPython 3.10 manylinux: glibc 2.17+ ARM64

httptools-0.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.4 kB 查看哈希)

上传时间 CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httptools-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl (77.6 kB 查看哈希)

上传时间 CPython 3.10 macOS 10.9+ x86-64

httptools-0.6.1-cp310-cp310-macosx_10_9_universal2.whl (149.8 kB 查看哈希)

上传时间 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

httptools-0.6.1-cp39-cp39-win_amd64.whl (60.2 kB 查看哈希)

上传时间 CPython 3.9 Windows x86-64

httptools-0.6.1-cp39-cp39-musllinux_1_1_x86_64.whl (360.8 kB 查看哈希)

上传时间 CPython 3.9 musllinux: musl 1.1+ x86-64

httptools-0.6.1-cp39-cp39-musllinux_1_1_aarch64.whl (369.2 kB 查看哈希)

上传时间 CPython 3.9 musllinux: musl 1.1+ ARM64

httptools-0.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (351.2 kB 查看哈希)

上传时间 CPython 3.9 manylinux: glibc 2.17+ ARM64

httptools-0.6.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.2 kB 查看哈希)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httptools-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl (79.1 kB 查看哈希)

上传于 CPython 3.9 macOS 10.9+ x86-64

httptools-0.6.1-cp39-cp39-macosx_10_9_universal2.whl (152.9 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

httptools-0.6.1-cp38-cp38-win_amd64.whl (60.2 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

httptools-0.6.1-cp38-cp38-musllinux_1_1_x86_64.whl (375.4 kB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.1+ x86-64

httptools-0.6.1-cp38-cp38-musllinux_1_1_aarch64.whl (383.8 kB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.1+ ARM64

httptools-0.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (360.8 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ARM64

httptools-0.6.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (354.4 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

httptools-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl (78.4 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

httptools-0.6.1-cp38-cp38-macosx_10_9_universal2.whl (151.7 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

支持者