diff --git a/stubs/gunicorn/METADATA.toml b/stubs/gunicorn/METADATA.toml index 60913393ea88..c1ac644bb118 100644 --- a/stubs/gunicorn/METADATA.toml +++ b/stubs/gunicorn/METADATA.toml @@ -1,4 +1,4 @@ -version = "26.2.0" +version = "27.0.1" upstream-repository = "https://github.com/benoitc/gunicorn" optional-dependencies = ["types-gevent"] diff --git a/stubs/gunicorn/gunicorn/asgi/lifespan.pyi b/stubs/gunicorn/gunicorn/asgi/lifespan.pyi index a55dca666674..8cb041d459cd 100644 --- a/stubs/gunicorn/gunicorn/asgi/lifespan.pyi +++ b/stubs/gunicorn/gunicorn/asgi/lifespan.pyi @@ -4,6 +4,8 @@ from gunicorn.glogging import Logger as GLogger from .._types import _ASGIAppType +class LifespanStartupFailed(RuntimeError): ... + class LifespanManager: app: _ASGIAppType logger: GLogger diff --git a/stubs/gunicorn/gunicorn/asgi/parser.pyi b/stubs/gunicorn/gunicorn/asgi/parser.pyi index 294d7681f0e0..3b6193f1ff36 100644 --- a/stubs/gunicorn/gunicorn/asgi/parser.pyi +++ b/stubs/gunicorn/gunicorn/asgi/parser.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable, Iterable from enum import IntEnum +from re import Pattern from typing import Any, Final, Literal, SupportsIndex, TypeAlias, TypedDict, type_check_only from typing_extensions import Self @@ -53,8 +54,14 @@ class InvalidHeader(ParseError): ... class UnsupportedTransferCoding(ParseError): ... class InvalidChunkSize(ParseError): ... class InvalidChunkExtension(ParseError): ... +class ChunkMissingTerminator(ParseError): ... RFC9110_5_3_SINGLETON_FIELDS: Final[frozenset[bytes]] +RFC9112_TARGET_INVALID: Final[Pattern[bytes]] + +MAX_UNLIMITED_REQUEST_LINE: Final[int] +DEFAULT_MAX_FIELD_LINE: Final[int] +DEFAULT_MAX_FIELDS: Final[int] class PythonProtocol: __slots__ = ( @@ -86,6 +93,8 @@ class PythonProtocol: "_permit_unconventional_http_method", "_permit_unconventional_http_version", "_header_count", + "_scan_from", + "_empty_line_skipped", "_proxy_protocol", "_proxy_protocol_info", "_proxy_protocol_done", @@ -131,7 +140,7 @@ class CallbackRequest: "query", "fragment", "version", - "headers", + "_headers", "headers_bytes", "scheme", "raw_path", @@ -140,6 +149,8 @@ class CallbackRequest: "must_close", "proxy_protocol_info", "_expect_100_continue", + "_connection", + "_has_upgrade", ) method: str | None uri: str | None @@ -147,7 +158,6 @@ class CallbackRequest: query: str | None fragment: str | None version: tuple[int, int] | None - headers: list[tuple[str, str]] headers_bytes: list[tuple[bytes, bytes]] scheme: Literal["https", "http"] raw_path: bytes @@ -157,7 +167,14 @@ class CallbackRequest: proxy_protocol_info: _ProxyProtocolInfo | _ProxyProtocolInfoUnknown | None def __init__(self) -> None: ... + + @property + def headers(self) -> list[tuple[str, str]]: ... + @headers.setter + def headers(self, value: list[tuple[str, str]]) -> None: ... + @classmethod def from_parser(cls, parser: _H1CProtocol | PythonProtocol, is_ssl: bool = False) -> Self: ... def should_close(self) -> bool: ... + def may_upgrade(self) -> bool: ... def get_header(self, name: str) -> str | None: ... diff --git a/stubs/gunicorn/gunicorn/asgi/protocol.pyi b/stubs/gunicorn/gunicorn/asgi/protocol.pyi index 376851ee89ab..70a3c5ddc7e4 100644 --- a/stubs/gunicorn/gunicorn/asgi/protocol.pyi +++ b/stubs/gunicorn/gunicorn/asgi/protocol.pyi @@ -10,8 +10,12 @@ from gunicorn.workers.gasgi import ASGIWorker from .._types import _ASGIAppType +def secure_scheme_names(secure_scheme_headers: Iterable[str]) -> frozenset[bytes]: ... + HIGH_WATER_LIMIT: Final = 65536 +class ClientDisconnected(OSError): ... + class FlowControl: __slots__ = ("_transport", "read_paused", "write_paused", "_is_writable_event") read_paused: bool @@ -38,12 +42,28 @@ class _BodyReceieverReceiveReturnType(TypedDict): more_body: NotRequired[bool] class BodyReceiver: - __slots__ = ("_chunks", "_complete", "_body_finished", "_closed", "_body_wait_expired", "_waiter", "request", "protocol") + __slots__ = ( + "_chunks", + "_complete", + "_source", + "_complete", + "_body_finished", + "_closed", + "_body_wait_expired", + "_waiter", + "request", + "protocol", + "expect_continue", + ) + request: CallbackRequest protocol: ASGIProtocol + expect_continue: bool def __init__(self, request: CallbackRequest, protocol: ASGIProtocol) -> None: ... def feed(self, chunk: bytes) -> None: ... + @property + def buffered(self) -> int: ... def set_complete(self) -> None: ... def signal_disconnect(self) -> None: ... async def receive(self) -> _BodyReceieverReceiveReturnType: ... diff --git a/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi b/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi index c76678bf8199..a7ebd928cd29 100644 --- a/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi +++ b/stubs/gunicorn/gunicorn/asgi/uwsgi.pyi @@ -17,6 +17,7 @@ class AsyncUWSGIRequest(UWSGIRequest): method: str | None uri: str | None path: str | None + raw_path: bytes | None query: str | None fragment: str | None version: tuple[int, int] diff --git a/stubs/gunicorn/gunicorn/asgi/websocket.pyi b/stubs/gunicorn/gunicorn/asgi/websocket.pyi index 457d53f0f637..6714f5a45006 100644 --- a/stubs/gunicorn/gunicorn/asgi/websocket.pyi +++ b/stubs/gunicorn/gunicorn/asgi/websocket.pyi @@ -1,16 +1,18 @@ import asyncio +from collections.abc import Awaitable, Callable from typing import Final +from gunicorn._types import _ASGIAppType, _ScopeType +from gunicorn.asgi.protocol import ClientDisconnected from gunicorn.glogging import Logger as GLogger -from .._types import _ASGIAppType, _ScopeType - OPCODE_CONTINUATION: Final = 0x0 OPCODE_TEXT: Final = 0x1 OPCODE_BINARY: Final = 0x2 OPCODE_CLOSE: Final = 0x8 OPCODE_PING: Final = 0x9 OPCODE_PONG: Final = 0xA + CLOSE_NORMAL: Final = 1000 CLOSE_GOING_AWAY: Final = 1001 CLOSE_PROTOCOL_ERROR: Final = 1002 @@ -20,10 +22,18 @@ CLOSE_ABNORMAL: Final = 1006 CLOSE_INVALID_DATA: Final = 1007 CLOSE_POLICY_VIOLATION: Final = 1008 CLOSE_MESSAGE_TOO_BIG: Final = 1009 +MAX_CONTROL_PAYLOAD: Final = 125 +KNOWN_OPCODES: Final[frozenset[int]] +DEFAULT_MAX_MESSAGE_SIZE: Final[int] +READ_BUFFER_HIGH_WATER: Final[int] +RECEIVE_QUEUE_HIGH_WATER: Final = 32 CLOSE_MANDATORY_EXT: Final = 1010 CLOSE_INTERNAL_ERROR: Final = 1011 + WS_GUID: Final = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11" +class WebSocketDisconnected(ClientDisconnected, RuntimeError): ... + class WebSocketProtocol: transport: asyncio.Transport scope: _ScopeType @@ -33,8 +43,17 @@ class WebSocketProtocol: closed: bool close_code: int | None close_reason: str | None + max_message_size: int - def __init__(self, transport: asyncio.Transport, scope: _ScopeType, app: _ASGIAppType, log: GLogger) -> None: ... + def __init__( + self, + transport: asyncio.Transport, + scope: _ScopeType, + app: _ASGIAppType, + log: GLogger, + max_message_size: int = DEFAULT_MAX_MESSAGE_SIZE, # noqa: Y011 + drain: Callable[[], Awaitable[object]] | None = None, + ) -> None: ... def feed_data(self, data: bytes) -> None: ... def feed_eof(self) -> None: ... async def run(self) -> None: ... diff --git a/stubs/gunicorn/gunicorn/config.pyi b/stubs/gunicorn/gunicorn/config.pyi index 390a6d591365..d5c369c18a55 100644 --- a/stubs/gunicorn/gunicorn/config.pyi +++ b/stubs/gunicorn/gunicorn/config.pyi @@ -113,6 +113,7 @@ class Config: def __getattr__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... def set(self, name: str, value: _ConfigValueType) -> None: ... + def validate(self) -> None: ... def get_cmd_args_from_env(self) -> list[str]: ... def parser(self) -> argparse.ArgumentParser: ... @property @@ -182,6 +183,8 @@ def validate_bool(val: Annotated[str, "Case-insensitive boolean string ('true'/' def validate_dict(val: dict[str, Any]) -> dict[str, Any]: ... def validate_pos_int(val: ConvertibleToInt) -> int: ... +def validate_http2_window_size(val: ConvertibleToInt) -> int: ... +def validate_http2_stream_limit(val: ConvertibleToInt) -> int: ... def validate_http2_frame_size(val: ConvertibleToInt) -> int: ... def validate_ssl_version(val: _SSLMethod) -> _SSLMethod: ... @@ -1210,6 +1213,15 @@ class ASGIDisconnectGracePeriod(Setting): default: ClassVar[int] desc: ClassVar[str] +class WebSocketMaxMessageSize(Setting): + name: ClassVar[str] + section: ClassVar[str] + cli: ClassVar[list[str]] + meta: ClassVar[str] + validator: ClassVar[_HttpParserValidatorType] + default: ClassVar[int] + desc: ClassVar[str] + class HttpParser(Setting): name: ClassVar[str] section: ClassVar[str] diff --git a/stubs/gunicorn/gunicorn/dirty/pidfile.pyi b/stubs/gunicorn/gunicorn/dirty/pidfile.pyi new file mode 100644 index 000000000000..15cfb4921368 --- /dev/null +++ b/stubs/gunicorn/gunicorn/dirty/pidfile.pyi @@ -0,0 +1,5 @@ +from _typeshed import StrOrBytesPath + +def write_pidfile(path: StrOrBytesPath, pid: int) -> bool: ... +def process_owned_by_us(pid: int) -> bool: ... +def read_trusted_pid(path: StrOrBytesPath) -> int | None: ... diff --git a/stubs/gunicorn/gunicorn/http/body.pyi b/stubs/gunicorn/gunicorn/http/body.pyi index a8ac9a698588..9788dc0f23a6 100644 --- a/stubs/gunicorn/gunicorn/http/body.pyi +++ b/stubs/gunicorn/gunicorn/http/body.pyi @@ -1,10 +1,17 @@ import io from collections.abc import Callable, Generator, Iterator -from typing import TypeAlias +from re import Pattern +from typing import Final, TypeAlias from gunicorn.http.message import Request from gunicorn.http.unreader import Unreader +CHUNK_EXT_RE: Final[Pattern[str]] + +MAX_READ_STEP: Final[int] +DEFAULT_MAX_CHUNK_SIZE_LINE: Final[int] +DEFAULT_MAX_TRAILER_SECTION: Final[int] + class ChunkedReader: req: Request parser: Generator[bytes] | None @@ -16,6 +23,7 @@ class ChunkedReader: def parse_chunked(self, unreader: Unreader) -> Generator[bytes]: ... def parse_chunk_size(self, unreader: Unreader, data: bytes | None = None) -> tuple[int, bytes | None]: ... def get_data(self, unreader: Unreader, buf: io.BytesIO) -> None: ... + def read_into(self, unreader: Unreader, buf: bytearray) -> None: ... class LengthReader: unreader: Unreader diff --git a/stubs/gunicorn/gunicorn/http/errors.pyi b/stubs/gunicorn/gunicorn/http/errors.pyi index 0e775b72a6f4..523693524b2b 100644 --- a/stubs/gunicorn/gunicorn/http/errors.pyi +++ b/stubs/gunicorn/gunicorn/http/errors.pyi @@ -52,24 +52,31 @@ class InvalidHeaderName(ParseException): def __init__(self, hdr: str) -> None: ... +class InvalidResponseHeader(InvalidHeader): ... +class InvalidResponseHeaderName(InvalidHeaderName): ... + class UnsupportedTransferCoding(ParseException): hdr: str code: int def __init__(self, hdr: str) -> None: ... -class InvalidChunkSize(IOError): +class InvalidChunkSize(ParseException): data: bytes + code: int def __init__(self, data: bytes) -> None: ... -class ChunkMissingTerminator(IOError): +class ChunkMissingTerminator(ParseException): term: bytes + code: int def __init__(self, term: bytes) -> None: ... -class InvalidChunkExtension(IOError): +class InvalidChunkExtension(ParseException): reason: str + code: int + def __init__(self, reason: str) -> None: ... class LimitRequestLine(ParseException): diff --git a/stubs/gunicorn/gunicorn/http/message.pyi b/stubs/gunicorn/gunicorn/http/message.pyi index c7b7da7d5e12..ae96fe9a7597 100644 --- a/stubs/gunicorn/gunicorn/http/message.pyi +++ b/stubs/gunicorn/gunicorn/http/message.pyi @@ -35,6 +35,7 @@ TOKEN_RE: Final[re.Pattern[str]] METHOD_BADCHAR_RE: Final[re.Pattern[str]] VERSION_RE: Final[re.Pattern[str]] RFC9110_5_5_INVALID_AND_DANGEROUS: Final[re.Pattern[str]] +RFC9112_TARGET_INVALID: Final[re.Pattern[str]] RFC9110_6_5_1_FORBIDDEN_TRAILER: Final[frozenset[str]] RFC9110_5_3_SINGLETON_FIELDS: Final[frozenset[str]] diff --git a/stubs/gunicorn/gunicorn/http/unreader.pyi b/stubs/gunicorn/gunicorn/http/unreader.pyi index bfc9992b9506..8c38fb58e345 100644 --- a/stubs/gunicorn/gunicorn/http/unreader.pyi +++ b/stubs/gunicorn/gunicorn/http/unreader.pyi @@ -2,25 +2,28 @@ import io import socket from _typeshed import ReadableBuffer from collections.abc import Iterable, Iterator +from typing import ClassVar class Unreader: buf: io.BytesIO def __init__(self) -> None: ... - def chunk(self) -> bytes: ... + def chunk(self, size_hint: int | None = None) -> bytes: ... def take_buffered(self) -> bytes: ... - def read(self, size: int | None = None) -> bytes: ... + def read(self, size: int | None = None, read_ahead: int | None = None) -> bytes: ... def unread(self, data: ReadableBuffer) -> None: ... class SocketUnreader(Unreader): + max_body_chunk: ClassVar[int] + sock: socket.socket mxchunk: int def __init__(self, sock: socket.socket, max_chunk: int = 8192) -> None: ... - def chunk(self) -> bytes: ... + def chunk(self, size_hint: int | None = None) -> bytes: ... class IterUnreader(Unreader): iter: Iterator[bytes] | None def __init__(self, iterable: Iterable[bytes]) -> None: ... - def chunk(self) -> bytes: ... + def chunk(self, size_hint: int | None = None) -> bytes: ... diff --git a/stubs/gunicorn/gunicorn/http/wsgi.pyi b/stubs/gunicorn/gunicorn/http/wsgi.pyi index cbf843149c9d..0128002726d7 100644 --- a/stubs/gunicorn/gunicorn/http/wsgi.pyi +++ b/stubs/gunicorn/gunicorn/http/wsgi.pyi @@ -7,13 +7,14 @@ from collections.abc import Callable from typing import Any, Final, Protocol, overload, type_check_only from typing_extensions import Self +from gunicorn._types import _AddressType, _EnvironType, _HeadersType, _StatusType from gunicorn.config import Config from gunicorn.http import Request -from .._types import _AddressType, _EnvironType, _HeadersType, _StatusType - BLKSIZE: Final = 0x3FFFFFFF HEADER_VALUE_RE: Final[re.Pattern[str]] +STATUS_RE: Final[re.Pattern[str]] + log: logging.Logger @type_check_only diff --git a/stubs/gunicorn/gunicorn/http2/async_connection.pyi b/stubs/gunicorn/gunicorn/http2/async_connection.pyi index 1cc1d687ea03..883b6a045776 100644 --- a/stubs/gunicorn/gunicorn/http2/async_connection.pyi +++ b/stubs/gunicorn/gunicorn/http2/async_connection.pyi @@ -1,15 +1,19 @@ from _typeshed import Incomplete from asyncio import StreamReader, StreamWriter from collections.abc import Iterable -from typing import ClassVar +from typing import ClassVar, Final +from gunicorn._types import _AddressType from gunicorn.config import Config from gunicorn.http.message import Request from gunicorn.http2.connection import _H2Connection from gunicorn.http2.request import HTTP2Request from gunicorn.http2.stream import HTTP2Stream -from .._types import _AddressType +RST_STREAM_RATE_LIMIT: Final = 200 +RST_STREAM_RATE_WINDOW: Final = 10.0 +CONTROL_FRAME_RATE_LIMIT: Final = 1000 +CONTROL_FRAME_RATE_WINDOW: Final = 10.0 class AsyncHTTP2Connection: READ_BUFFER_SIZE: ClassVar[int] @@ -18,6 +22,8 @@ class AsyncHTTP2Connection: writer: StreamWriter client_addr: _AddressType streams: dict[int, HTTP2Stream] + draining: bool + peer_last_stream_id: int | None initial_window_size: int max_concurrent_streams: int max_frame_size: int @@ -30,7 +36,12 @@ class AsyncHTTP2Connection: self, settings_header: bytes | None, http1_req: Request, body: bytes | None = b"" ) -> HTTP2Request: ... async def receive_data(self, timeout: float | None = None) -> list[HTTP2Request]: ... + def abort_streams_nowait(self) -> None: ... + def acknowledge_data(self, stream_id: int, size: int) -> None: ... async def send_informational(self, stream_id: int, status: int, headers: Iterable[tuple[str, Incomplete]]) -> None: ... + async def send_response_headers( + self, stream_id: int, headers: Iterable[tuple[str, str]], end_stream: bool = False + ) -> bool: ... async def send_response( self, stream_id: int, status: int, headers: Iterable[tuple[str, Incomplete]], body: bytes | None = None ) -> bool: ... @@ -38,6 +49,7 @@ class AsyncHTTP2Connection: async def send_trailers(self, stream_id: int, trailers: Iterable[tuple[str, Incomplete]]) -> bool: ... async def send_error(self, stream_id: int, status_code: int, message: str | None = None) -> None: ... async def reset_stream(self, stream_id: int, error_code: int = 0x8) -> None: ... + async def abort_stream(self, stream_id: int, error_code: int) -> None: ... async def close(self, error_code: int = 0x0, last_stream_id: int | None = None) -> None: ... @property def is_closed(self) -> bool: ... diff --git a/stubs/gunicorn/gunicorn/http2/connection.pyi b/stubs/gunicorn/gunicorn/http2/connection.pyi index d4425d160b6d..a5f08734aeba 100644 --- a/stubs/gunicorn/gunicorn/http2/connection.pyi +++ b/stubs/gunicorn/gunicorn/http2/connection.pyi @@ -1,7 +1,8 @@ from _typeshed import Incomplete +from collections import deque from collections.abc import Iterable from ssl import SSLSocket -from typing import Any, ClassVar, TypeAlias +from typing import Any, ClassVar, Final, TypeAlias from gunicorn.config import Config from gunicorn.http.message import Request @@ -12,12 +13,23 @@ from .._types import _AddressType _H2Connection: TypeAlias = Any # h2.connection.H2Connection class +RST_STREAM_RATE_LIMIT: Final = 200 +RST_STREAM_RATE_WINDOW: Final = 10.0 +CONTROL_FRAME_RATE_LIMIT: Final = 1000 +CONTROL_FRAME_RATE_WINDOW: Final = 10.0 +MAX_DEFERRED_EVENTS: Final = 10000 + class HTTP2ServerConnection: READ_BUFFER_SIZE: ClassVar[int] cfg: Config sock: SSLSocket client_addr: _AddressType streams: dict[int, HTTP2Stream] + pending_requests: deque[HTTP2Request] + draining: bool + peer_last_stream_id: int | None + stream_timeout: float | int | None + idle_timeout: float | int | None initial_window_size: int max_concurrent_streams: int max_frame_size: int @@ -28,11 +40,13 @@ class HTTP2ServerConnection: def initiate_connection(self) -> None: ... def initiate_upgrade(self, settings_header: bytes | None, http1_req: Request, body: bytes | None = None) -> HTTP2Request: ... def receive_data(self, data: bytes | None = None) -> list[HTTP2Request]: ... + def pump(self, stream_id: int | None = None) -> None: ... def send_informational(self, stream_id: int, status: int, headers: Iterable[tuple[str, Incomplete]]) -> None: ... def send_response_headers( self, stream_id: int, status: int, headers: Iterable[tuple[str, Incomplete]], end_stream: bool = False ) -> bool: ... def end_stream(self, stream_id: int, trailers: Iterable[tuple[str, Incomplete]] | None = None) -> bool: ... + def acknowledge_data(self, stream_id: int, size: int) -> None: ... def send_response( self, stream_id: int, status: int, headers: Iterable[tuple[str, Incomplete]], body: bytes | None = None ) -> bool: ... @@ -40,6 +54,7 @@ class HTTP2ServerConnection: def send_trailers(self, stream_id: int, trailers: Iterable[tuple[str, Incomplete]]) -> bool: ... def send_error(self, stream_id: int, status_code: int, message: str | None = None) -> None: ... def reset_stream(self, stream_id: int, error_code: int = 0x8) -> None: ... + def abort_stream(self, stream_id: int, error_code: int) -> None: ... def close(self, error_code: int = 0x0, last_stream_id: int | None = None) -> None: ... @property def is_closed(self) -> bool: ... diff --git a/stubs/gunicorn/gunicorn/http2/h2conn.pyi b/stubs/gunicorn/gunicorn/http2/h2conn.pyi new file mode 100644 index 000000000000..cdf9cf912810 --- /dev/null +++ b/stubs/gunicorn/gunicorn/http2/h2conn.pyi @@ -0,0 +1,5 @@ +from typing import Any, TypeAlias + +_H2Connection: TypeAlias = Any # h2.connection.H2Connection + +def server_connection_class() -> type[_H2Connection]: ... diff --git a/stubs/gunicorn/gunicorn/http2/negotiation.pyi b/stubs/gunicorn/gunicorn/http2/negotiation.pyi index f6e8bef46fdc..f7836bf076d5 100644 --- a/stubs/gunicorn/gunicorn/http2/negotiation.pyi +++ b/stubs/gunicorn/gunicorn/http2/negotiation.pyi @@ -25,3 +25,5 @@ def read_preface_blocking(sock: socket.socket, timeout: float | None = None) -> UPGRADE_101: Final[bytes] def upgrade_settings(req: _HasHeaders) -> bytes | None: ... + +H2C_UPGRADE_BODY_LIMIT: Final = 65536 diff --git a/stubs/gunicorn/gunicorn/http2/request.pyi b/stubs/gunicorn/gunicorn/http2/request.pyi index ae156235adce..dc351c624cf5 100644 --- a/stubs/gunicorn/gunicorn/http2/request.pyi +++ b/stubs/gunicorn/gunicorn/http2/request.pyi @@ -1,22 +1,20 @@ -from _typeshed import Incomplete, ReadableBuffer -from collections.abc import Iterator from typing import Literal +from typing_extensions import Self +from gunicorn._types import _AddressType +from gunicorn.asgi.parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown from gunicorn.config import Config from gunicorn.http.message import HeaderPolicy from gunicorn.http2.stream import HTTP2Stream -from .._types import _AddressType -from ..asgi.parser import _ProxyProtocolInfo, _ProxyProtocolInfoUnknown - class HTTP2Body: - def __init__(self, data: ReadableBuffer) -> None: ... + def __init__(self, source: HTTP2Stream | bytes | bytearray) -> None: ... def read(self, size: int | None = None) -> bytes: ... def readline(self, size: int | None = None) -> bytes: ... def readlines(self, hint: int | None = None) -> list[bytes]: ... - def __iter__(self) -> Iterator[bytes]: ... - def __len__(self) -> int: ... def close(self) -> None: ... + def __iter__(self) -> Self: ... + def __next__(self) -> bytes: ... class HTTP2Request(HeaderPolicy): stream: HTTP2Stream @@ -31,7 +29,6 @@ class HTTP2Request(HeaderPolicy): query: str fragment: str headers: list[tuple[str, str]] - trailers: list[tuple[str, Incomplete]] body: HTTP2Body must_close: bool req_number: int @@ -40,6 +37,8 @@ class HTTP2Request(HeaderPolicy): priority_depends_on: int def __init__(self, stream: HTTP2Stream, cfg: Config, peer_addr: _AddressType) -> None: ... + @property + def trailers(self) -> list[tuple[str, str]]: ... def force_close(self) -> None: ... def should_close(self) -> bool: ... def get_header(self, name: str) -> str | None: ... diff --git a/stubs/gunicorn/gunicorn/http2/stream.pyi b/stubs/gunicorn/gunicorn/http2/stream.pyi index 5e7eecb15c19..c5fac47eaee3 100644 --- a/stubs/gunicorn/gunicorn/http2/stream.pyi +++ b/stubs/gunicorn/gunicorn/http2/stream.pyi @@ -1,7 +1,6 @@ -from _typeshed import Incomplete, ReadableBuffer +from _typeshed import ReadableBuffer from collections.abc import Iterable from enum import Enum -from io import BytesIO from gunicorn.http2.connection import HTTP2ServerConnection @@ -18,18 +17,21 @@ class HTTP2Stream: stream_id: int connection: HTTP2ServerConnection state: StreamState - request_headers: list[tuple[str, Incomplete]] - request_body: BytesIO + request_headers: list[tuple[str, str]] request_complete: bool response_started: bool response_headers_sent: bool response_complete: bool window_size: int - trailers: list[tuple[str, Incomplete]] | None - response_trailers: list[tuple[str, Incomplete]] | None + trailers: list[tuple[str, str]] | None + response_trailers: list[tuple[str, str]] | None priority_weight: int priority_depends_on: int priority_exclusive: bool + body_size: int + acked_size: int + disconnected: bool + expect_continue: bool def __init__(self, stream_id: int, connection: HTTP2ServerConnection) -> None: ... @property @@ -40,20 +42,27 @@ class HTTP2Stream: def can_receive(self) -> bool: ... @property def can_send(self) -> bool: ... - def receive_headers(self, headers: Iterable[tuple[str, Incomplete]], end_stream: bool | None = False) -> None: ... + def receive_headers(self, headers: Iterable[tuple[str, str, str]], end_stream: bool | None = False) -> None: ... def receive_data(self, data: ReadableBuffer, end_stream: bool | None = False) -> None: ... - def receive_trailers(self, trailers: list[tuple[str, Incomplete]]) -> None: ... - def send_headers(self, headers: Iterable[tuple[str, Incomplete]], end_stream: bool | None = False) -> None: ... + def receive_trailers(self, trailers: list[tuple[str, str, str]]) -> None: ... + def send_headers(self, headers: Iterable[tuple[str, str]], end_stream: bool | None = False) -> None: ... def send_data(self, data: ReadableBuffer, end_stream: bool | None = False) -> None: ... - def send_trailers(self, trailers: list[tuple[str, Incomplete]]) -> None: ... + def send_trailers(self, trailers: list[tuple[str, str, str]]) -> None: ... def reset(self, error_code: int = 0x8) -> None: ... + def signal_disconnect(self) -> None: ... + async def wait_disconnect(self) -> None: ... def close(self) -> None: ... def update_priority( self, weight: int | None = None, depends_on: int | None = None, exclusive: bool | None = None ) -> None: ... + @property + def body_complete(self) -> bool: ... + @property + def unacked_size(self) -> int: ... def get_request_body(self) -> bytes: ... + def pop_chunk(self) -> bytes | None: ... async def read_body_chunk(self) -> bytes | None: ... - def get_pseudo_headers(self) -> dict[str, Incomplete]: ... - def get_regular_headers(self) -> list[tuple[str, Incomplete]]: ... + def get_pseudo_headers(self) -> dict[str, str]: ... + def get_regular_headers(self) -> list[tuple[str, str]]: ... __all__ = ["HTTP2Stream", "StreamState"] diff --git a/stubs/gunicorn/gunicorn/reloader.pyi b/stubs/gunicorn/gunicorn/reloader.pyi index 62371ed476e0..6e179dfb134e 100644 --- a/stubs/gunicorn/gunicorn/reloader.pyi +++ b/stubs/gunicorn/gunicorn/reloader.pyi @@ -1,12 +1,18 @@ import sys import threading from collections.abc import Callable, Iterable +from os import PathLike from re import Pattern -from typing import Final, TypeAlias, TypedDict, type_check_only +from typing import AnyStr, Final, TypeAlias, TypedDict, overload, type_check_only from typing_extensions import Never COMPILED_EXT_RE: Final[Pattern[str]] +@overload +def symlink_target_dir(filename: PathLike[AnyStr]) -> AnyStr | None: ... +@overload +def symlink_target_dir(filename: AnyStr) -> AnyStr | None: ... + class ReloaderBase(threading.Thread): daemon: bool diff --git a/stubs/gunicorn/gunicorn/uwsgi/message.pyi b/stubs/gunicorn/gunicorn/uwsgi/message.pyi index b89c893ad508..f5c8e4971b8b 100644 --- a/stubs/gunicorn/gunicorn/uwsgi/message.pyi +++ b/stubs/gunicorn/gunicorn/uwsgi/message.pyi @@ -18,6 +18,7 @@ class UWSGIRequest: method: str | None uri: str | None path: str | None + raw_path: bytes | None query: str | None fragment: str | None version: tuple[int, int] diff --git a/stubs/gunicorn/gunicorn/workers/gthread.pyi b/stubs/gunicorn/gunicorn/workers/gthread.pyi index 65e5058f9e2e..b6d12d74c2d2 100644 --- a/stubs/gunicorn/gunicorn/workers/gthread.pyi +++ b/stubs/gunicorn/gunicorn/workers/gthread.pyi @@ -17,6 +17,7 @@ from .._types import _AddressType from . import base DEFAULT_WORKER_DATA_TIMEOUT: Final = 5.0 +STOP_KEEPALIVE_LINGER: Final = 2.0 class TConn: cfg: Config @@ -68,7 +69,7 @@ class ThreadWorker(base.Worker): def accept(self, listener: socket.socket) -> None: ... def on_client_socket_readable(self, conn: TConn, client: socket.socket) -> None: ... def on_pending_socket_readable(self, conn: TConn, client: socket.socket) -> None: ... - def murder_keepalived(self) -> None: ... + def murder_keepalived(self, force: bool = False) -> None: ... def murder_pending(self) -> None: ... def is_parent_alive(self) -> bool: ... def wait_for_and_dispatch_events(self, timeout: float | None) -> None: ...