|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +hyper/http11/parser |
| 4 | +~~~~~~~~~~~~~~~~~~~ |
| 5 | +
|
| 6 | +This module contains hyper's pure-Python HTTP/1.1 parser. This module defines |
| 7 | +an abstraction layer for HTTP/1.1 parsing that allows for dropping in other |
| 8 | +modules if needed, in order to obtain speedups on your chosen platform. |
| 9 | +""" |
| 10 | +from collections import namedtuple |
| 11 | + |
| 12 | + |
| 13 | +Request = namedtuple( |
| 14 | + 'Request', ['method', 'path', 'minor_version', 'headers', 'consumed'] |
| 15 | +) |
| 16 | +Response = namedtuple( |
| 17 | + 'Response', ['status', 'msg', 'minor_version', 'headers', 'consumed'] |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +class ParseError(Exception): |
| 22 | + """ |
| 23 | + An invalid HTTP message was passed to the parser. |
| 24 | + """ |
| 25 | + pass |
| 26 | + |
| 27 | + |
| 28 | +class Parser(object): |
| 29 | + """ |
| 30 | + A single HTTP parser object. This object can parse HTTP requests and |
| 31 | + responses using picohttpparser. |
| 32 | + This object is not thread-safe, and it does maintain state that is shared |
| 33 | + across parsing requests. For this reason, make sure that access to this |
| 34 | + object is synchronized if you use it across multiple threads. |
| 35 | + """ |
| 36 | + def __init__(self): |
| 37 | + pass |
| 38 | + |
| 39 | + def parse_request(self, buffer): |
| 40 | + """ |
| 41 | + Parses a single HTTP request from a buffer. |
| 42 | + :param buffer: A ``memoryview`` object wrapping a buffer containing a |
| 43 | + HTTP request. |
| 44 | + :returns: A :class:`Request <hyper.http11.parser.Request>` object, or |
| 45 | + ``None`` if there is not enough data in the buffer. |
| 46 | + """ |
| 47 | + pass |
| 48 | + |
| 49 | + def parse_response(self, buffer): |
| 50 | + """ |
| 51 | + Parses a single HTTP response from a buffer. |
| 52 | + :param buffer: A ``memoryview`` object wrapping a buffer containing a |
| 53 | + HTTP response. |
| 54 | + :returns: A :class:`Response <hyper.http11.parser.Response>` object, or |
| 55 | + ``None`` if there is not enough data in the buffer. |
| 56 | + """ |
| 57 | + pass |
0 commit comments