No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

134 líneas
3.5 KiB

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