一组独立于框架的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第三方库


热门话题
正则表达式Java使用关键字拆分字符串   Neo4j Java API模式索引范围查找?   java访问JButton[]   java如何混淆tomcat日志文件中的请求属性   apache运行CGI Java程序   java从一个Eclipse插件开始,我如何通过编程使Eclipse编辑某个文件?   从php中的SQL数据库到Java中的多个值作为单独的变量   java如何在多个osgi捆绑包之间共享资源   datetime Java time,无法从历元秒解析年份   java无法在安卓应用程序中使用morpho指纹扫描仪设备捕获指纹   java使用groovy/ratpack发送电子邮件   javascript在jsp页面中添加验证,但在控制台中仍然显示一些错误   java如何修复com。mysql。jdbc。DocsConnectionPropsHelper   java AlertDialog dispatchTouchEvent