Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/gunicorn/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "26.2.0"
version = "27.0.1"
upstream-repository = "https://github.com/benoitc/gunicorn"
optional-dependencies = ["types-gevent"]

Expand Down
2 changes: 2 additions & 0 deletions stubs/gunicorn/gunicorn/asgi/lifespan.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ from gunicorn.glogging import Logger as GLogger

from .._types import _ASGIAppType

class LifespanStartupFailed(RuntimeError): ...

class LifespanManager:
app: _ASGIAppType
logger: GLogger
Expand Down
21 changes: 19 additions & 2 deletions stubs/gunicorn/gunicorn/asgi/parser.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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__ = (
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -131,7 +140,7 @@ class CallbackRequest:
"query",
"fragment",
"version",
"headers",
"_headers",
"headers_bytes",
"scheme",
"raw_path",
Expand All @@ -140,14 +149,15 @@ class CallbackRequest:
"must_close",
"proxy_protocol_info",
"_expect_100_continue",
"_connection",
"_has_upgrade",
)
method: str | None
uri: str | None
path: str | None
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
Expand All @@ -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: ...
22 changes: 21 additions & 1 deletion stubs/gunicorn/gunicorn/asgi/protocol.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ...
Expand Down
1 change: 1 addition & 0 deletions stubs/gunicorn/gunicorn/asgi/uwsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 22 additions & 3 deletions stubs/gunicorn/gunicorn/asgi/websocket.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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: ...
12 changes: 12 additions & 0 deletions stubs/gunicorn/gunicorn/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...

Expand Down Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions stubs/gunicorn/gunicorn/dirty/pidfile.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
10 changes: 9 additions & 1 deletion stubs/gunicorn/gunicorn/http/body.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions stubs/gunicorn/gunicorn/http/errors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions stubs/gunicorn/gunicorn/http/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down
11 changes: 7 additions & 4 deletions stubs/gunicorn/gunicorn/http/unreader.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
5 changes: 3 additions & 2 deletions stubs/gunicorn/gunicorn/http/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading