|
| 1 | +from collections.abc import Callable, Iterable |
| 2 | +from typing import Any, Literal, SupportsIndex |
| 3 | +from typing_extensions import Self, TypeAlias |
| 4 | + |
| 5 | +_H1CProtocol: TypeAlias = Any # gunicorn_h1c H1CProtocol class |
| 6 | + |
| 7 | +class ParseError(Exception): ... |
| 8 | +class LimitRequestLine(ParseError): ... |
| 9 | +class LimitRequestHeaders(ParseError): ... |
| 10 | +class InvalidRequestMethod(ParseError): ... |
| 11 | +class InvalidHTTPVersion(ParseError): ... |
| 12 | +class InvalidHeaderName(ParseError): ... |
| 13 | +class InvalidHeader(ParseError): ... |
| 14 | + |
| 15 | +class PythonProtocol: |
| 16 | + __slots__ = ( |
| 17 | + "_on_message_begin", |
| 18 | + "_on_url", |
| 19 | + "_on_header", |
| 20 | + "_on_headers_complete", |
| 21 | + "_on_body", |
| 22 | + "_on_message_complete", |
| 23 | + "_state", |
| 24 | + "_buffer", |
| 25 | + "_headers_list", |
| 26 | + "method", |
| 27 | + "path", |
| 28 | + "http_version", |
| 29 | + "headers", |
| 30 | + "content_length", |
| 31 | + "is_chunked", |
| 32 | + "should_keep_alive", |
| 33 | + "is_complete", |
| 34 | + "_body_remaining", |
| 35 | + "_skip_body", |
| 36 | + "_chunk_state", |
| 37 | + "_chunk_size", |
| 38 | + "_chunk_remaining", |
| 39 | + "_limit_request_line", |
| 40 | + "_limit_request_fields", |
| 41 | + "_limit_request_field_size", |
| 42 | + "_permit_unconventional_http_method", |
| 43 | + "_permit_unconventional_http_version", |
| 44 | + "_header_count", |
| 45 | + ) |
| 46 | + method: bytes | None |
| 47 | + path: bytes | None |
| 48 | + http_version: tuple[int, int] | None |
| 49 | + headers: list[tuple[bytes, bytes]] |
| 50 | + content_length: int | None |
| 51 | + is_chunked: bool |
| 52 | + should_keep_alive: bool |
| 53 | + is_complete: bool |
| 54 | + |
| 55 | + def __init__( |
| 56 | + self, |
| 57 | + on_message_begin: Callable[[], object] | None = None, |
| 58 | + on_url: Callable[[bytes], object] | None = None, |
| 59 | + on_header: Callable[[bytes, bytes], object] | None = None, |
| 60 | + on_headers_complete: Callable[[], bool] | None = None, |
| 61 | + on_body: Callable[[bytes], object] | None = None, |
| 62 | + on_message_complete: Callable[[], object] | None = None, |
| 63 | + limit_request_line: int = 8190, |
| 64 | + limit_request_fields: int = 100, |
| 65 | + limit_request_field_size: int = 8190, |
| 66 | + permit_unconventional_http_method: bool = False, |
| 67 | + permit_unconventional_http_version: bool = False, |
| 68 | + ) -> None: ... |
| 69 | + def feed(self, data: Iterable[SupportsIndex]) -> None: ... |
| 70 | + def reset(self) -> None: ... |
| 71 | + |
| 72 | +class CallbackRequest: |
| 73 | + __slots__ = ( |
| 74 | + "method", |
| 75 | + "uri", |
| 76 | + "path", |
| 77 | + "query", |
| 78 | + "fragment", |
| 79 | + "version", |
| 80 | + "headers", |
| 81 | + "headers_bytes", |
| 82 | + "scheme", |
| 83 | + "raw_path", |
| 84 | + "content_length", |
| 85 | + "chunked", |
| 86 | + "must_close", |
| 87 | + "proxy_protocol_info", |
| 88 | + "_expect_100_continue", |
| 89 | + ) |
| 90 | + method: str | None |
| 91 | + uri: str | None |
| 92 | + path: str | None |
| 93 | + query: str | None |
| 94 | + fragment: str | None |
| 95 | + version: tuple[int, int] | None |
| 96 | + headers: list[tuple[str, str]] |
| 97 | + headers_bytes: list[tuple[bytes, bytes]] |
| 98 | + scheme: Literal["https", "http"] |
| 99 | + raw_path: bytes |
| 100 | + content_length: int |
| 101 | + chunked: bool |
| 102 | + must_close: bool |
| 103 | + proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict |
| 104 | + |
| 105 | + def __init__(self) -> None: ... |
| 106 | + @classmethod |
| 107 | + def from_parser(cls, parser: _H1CProtocol | PythonProtocol, is_ssl: bool = False) -> Self: ... |
| 108 | + def should_close(self) -> bool: ... |
| 109 | + def get_header(self, name: str) -> str | None: ... |
0 commit comments