您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

127 行
4.2 KiB

  1. Metadata-Version: 1.1
  2. Name: httptools
  3. Version: 0.0.13
  4. Summary: A collection of framework independent HTTP protocol utils.
  5. Home-page: https://github.com/MagicStack/httptools
  6. Author: Yury Selivanov
  7. Author-email: yury@magic.io
  8. License: MIT
  9. Description-Content-Type: text/markdown
  10. Description: [![Build Status](https://travis-ci.org/MagicStack/httptools.svg?branch=master)](https://travis-ci.org/MagicStack/httptools)
  11. httptools is a Python binding for nodejs HTTP parser. It's still in a
  12. very early development stage, expect APIs to break.
  13. The package is available on PyPI: `pip install httptools`.
  14. # APIs
  15. httptools contains two classes `httptools.HttpRequestParser`,
  16. `httptools.HttpResponseParser` and a function for parsing URLs
  17. `httptools.parse_url`. See unittests for examples.
  18. ```python
  19. class HttpRequestParser:
  20. def __init__(self, protocol):
  21. """HttpRequestParser
  22. protocol -- a Python object with the following methods
  23. (all optional):
  24. - on_message_begin()
  25. - on_url(url: bytes)
  26. - on_header(name: bytes, value: bytes)
  27. - on_headers_complete()
  28. - on_body(body: bytes)
  29. - on_message_complete()
  30. - on_chunk_header()
  31. - on_chunk_complete()
  32. - on_status(status: bytes)
  33. """
  34. def get_http_version(self) -> str:
  35. """Return an HTTP protocol version."""
  36. def should_keep_alive(self) -> bool:
  37. """Return ``True`` if keep-alive mode is preferred."""
  38. def should_upgrade(self) -> bool:
  39. """Return ``True`` if the parsed request is a valid Upgrade request.
  40. The method exposes a flag set just before on_headers_complete.
  41. Calling this method earlier will only yield `False`.
  42. """
  43. def feed_data(self, data: bytes):
  44. """Feed data to the parser.
  45. Will eventually trigger callbacks on the ``protocol``
  46. object.
  47. On HTTP upgrade, this method will raise an
  48. ``HttpParserUpgrade`` exception, with its sole argument
  49. set to the offset of the non-HTTP data in ``data``.
  50. """
  51. def get_method(self) -> bytes:
  52. """Return HTTP request method (GET, HEAD, etc)"""
  53. class HttpResponseParser:
  54. """Has all methods except ``get_method()`` that
  55. HttpRequestParser has."""
  56. def get_status_code(self) -> int:
  57. """Return the status code of the HTTP response"""
  58. def parse_url(url: bytes):
  59. """Parse URL strings into a structured Python object.
  60. Returns an instance of ``httptools.URL`` class with the
  61. following attributes:
  62. - schema: bytes
  63. - host: bytes
  64. - port: int
  65. - path: bytes
  66. - query: bytes
  67. - fragment: bytes
  68. - userinfo: bytes
  69. """
  70. ```
  71. # Development
  72. 1. Clone this repository with
  73. `git clone --recursive git@github.com:MagicStack/httptools.git`
  74. 2. Create a virtual environment with Python 3.5:
  75. `python3.5 -m venv envname`
  76. 3. Activate the environment with `source envname/bin/activate`
  77. 4. Install Cython with `pip install cython`
  78. 5. Run `make` and `make test`.
  79. # License
  80. MIT.
  81. Platform: POSIX
  82. Classifier: License :: OSI Approved :: MIT License
  83. Classifier: Intended Audience :: Developers
  84. Classifier: Programming Language :: Python :: 3
  85. Classifier: Operating System :: POSIX
  86. Classifier: Operating System :: MacOS :: MacOS X
  87. Classifier: Environment :: Web Environment
  88. Classifier: Development Status :: 5 - Production/Stable
  89. Provides: httptools