diff --git a/stubs/gunicorn/gunicorn/asgi/parser.pyi b/stubs/gunicorn/gunicorn/asgi/parser.pyi index 69606932ee00..f98f04a0f178 100644 --- a/stubs/gunicorn/gunicorn/asgi/parser.pyi +++ b/stubs/gunicorn/gunicorn/asgi/parser.pyi @@ -9,6 +9,22 @@ class ParseError(Exception): ... class InvalidProxyLine(ParseError): ... class InvalidProxyHeader(ParseError): ... +@type_check_only +class _ProxyProtocolInfo(TypedDict): + proxy_protocol: Literal["TCP4", "TCP6", "UDP4", "UDP6"] + client_addr: str + client_port: int + proxy_addr: str + proxy_port: int + +@type_check_only +class _ProxyProtocolInfoUnknown(TypedDict): + proxy_protocol: Literal["UNKNOWN", "LOCAL", "UNSPEC"] + client_addr: None + client_port: None + proxy_addr: None + proxy_port: None + PP_V2_SIGNATURE: Final[bytes] RFC9110_6_5_1_FORBIDDEN_TRAILER: Final[frozenset[bytes]] @@ -38,22 +54,6 @@ class UnsupportedTransferCoding(ParseError): ... class InvalidChunkSize(ParseError): ... class InvalidChunkExtension(ParseError): ... -@type_check_only -class _ProxyProtocolInfo(TypedDict): - proxy_protocol: Literal["TCP4", "TCP6", "UDP4", "UDP6"] - client_addr: str - client_port: int - proxy_addr: str - proxy_port: int - -@type_check_only -class _ProxyProtocolInfoUnknown(TypedDict): - proxy_protocol: Literal["UNKNOWN", "LOCAL", "UNSPEC"] - client_addr: None - client_port: None - proxy_addr: None - proxy_port: None - class PythonProtocol: __slots__ = ( "_on_message_begin", @@ -149,7 +149,7 @@ class CallbackRequest: content_length: int chunked: bool must_close: bool - proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict + proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None def __init__(self) -> None: ... @classmethod diff --git a/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi b/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi index 651dcdd416d1..c76678bf8199 100644 --- a/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi +++ b/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi @@ -6,6 +6,7 @@ from gunicorn.config import Config from gunicorn.uwsgi.message import UWSGIRequest from .._types import _AddressType +from .parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown class AsyncUWSGIRequest(UWSGIRequest): cfg: Config @@ -26,7 +27,7 @@ class AsyncUWSGIRequest(UWSGIRequest): uwsgi_vars: dict[str, str] modifier1: int modifier2: int - proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict + proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None content_length: int chunked: bool diff --git a/stubs/gunicorn/gunicorn/http/message.pyi b/stubs/gunicorn/gunicorn/http/message.pyi index 4243ef9eb75a..4819ab116870 100644 --- a/stubs/gunicorn/gunicorn/http/message.pyi +++ b/stubs/gunicorn/gunicorn/http/message.pyi @@ -8,6 +8,7 @@ from gunicorn.http.body import Body from gunicorn.http.unreader import Unreader from .._types import _AddressType +from ..asgi.parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown PP_V2_SIGNATURE: Final = b"\x0d\x0a\x0d\x0a\x00\x0d\x0a\x51\x55\x49\x54\x0a" @@ -66,7 +67,7 @@ class Request(Message): fragment: str | None limit_request_line: int req_number: int - proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict + proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None def __init__(self, cfg: Config, unreader: Unreader, peer_addr: _AddressType, req_number: int = 1) -> None: ... def get_data(self, unreader: Unreader, buf: io.BytesIO, stop: bool = False) -> None: ... diff --git a/stubs/gunicorn/gunicorn/http2/request.pyi b/stubs/gunicorn/gunicorn/http2/request.pyi index 6f933b1c0265..b9a3a377d865 100644 --- a/stubs/gunicorn/gunicorn/http2/request.pyi +++ b/stubs/gunicorn/gunicorn/http2/request.pyi @@ -6,6 +6,7 @@ from gunicorn.config import Config from gunicorn.http2.stream import HTTP2Stream from .._types import _AddressType +from ..asgi.parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown class HTTP2Body: def __init__(self, data: ReadableBuffer) -> None: ... @@ -33,7 +34,7 @@ class HTTP2Request: body: HTTP2Body must_close: bool req_number: int - proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict + proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None priority_weight: int priority_depends_on: int diff --git a/stubs/gunicorn/gunicorn/uwsgi/message.pyi b/stubs/gunicorn/gunicorn/uwsgi/message.pyi index fbd9f318ebc7..b89c893ad508 100644 --- a/stubs/gunicorn/gunicorn/uwsgi/message.pyi +++ b/stubs/gunicorn/gunicorn/uwsgi/message.pyi @@ -5,6 +5,7 @@ from gunicorn.http.body import Body from gunicorn.http.unreader import Unreader from .._types import _AddressType +from ..asgi.parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown MAX_UWSGI_VARS: Final = 1000 @@ -28,7 +29,7 @@ class UWSGIRequest: uwsgi_vars: dict[str, str] modifier1: int modifier2: int - proxy_protocol_info: dict[str, str | int | None] | None # TODO: Use TypedDict + proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None def __init__(self, cfg: Config, unreader: Unreader, peer_addr: _AddressType, req_number: int = 1) -> None: ... def force_close(self) -> None: ...