Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitress: stubtest-complete and update usage of Any #11796

Merged
merged 1 commit into from
Apr 20, 2024
Merged
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
37 changes: 4 additions & 33 deletions stubs/waitress/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
waitress.adjustments.Adjustments.clear_untrusted_proxy_headers
waitress.adjustments.PY2
waitress.adjustments.string_types
waitress.channel.HTTPChannel.addr
waitress.channel.HTTPChannel.error_task_class
waitress.channel.HTTPChannel.parser_class
waitress.channel.HTTPChannel.request
waitress.channel.HTTPChannel.task_class
waitress.compat.PY2
waitress.compat.PY3
waitress.compat.ResourceWarning
waitress.compat.class_types
waitress.compat.exec_
waitress.compat.integer_types
waitress.compat.qualname
waitress.compat.reraise
waitress.compat.set_nonblocking
waitress.compat.string_types
waitress.compat.text_
waitress.compat.tobytes
waitress.compat.tostr
waitress.compat.unquote_bytes_to_wsgi
waitress.rfc7230.tobytes
waitress.server.BaseWSGIServer.channel_class
waitress.server.BaseWSGIServer.get_server_name
waitress.server.MultiSocketServer.__init__
waitress.server.WSGIServer
waitress.task.ErrorTask.content_length
waitress.task.ThreadedTaskDispatcher.start_new_thread
waitress.task.WSGITask.content_length
waitress.rfc7230.BWS
waitress.wasyncore.map
waitress.wasyncore.dispatcher_with_send.handle_write
waitress.__main__

# Leaked loop variable
waitress.utilities.i
1 change: 0 additions & 1 deletion stubs/waitress/@tests/stubtest_allowlist_darwin.txt

This file was deleted.

1 change: 0 additions & 1 deletion stubs/waitress/@tests/stubtest_allowlist_linux.txt

This file was deleted.

3 changes: 0 additions & 3 deletions stubs/waitress/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
version = "2.1.*"
upstream_repository = "https://github.com/Pylons/waitress"
requires = []
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
# linux and darwin are equivalent
platforms = ["linux", "win32"]
21 changes: 16 additions & 5 deletions stubs/waitress/waitress/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from typing import Any
from _typeshed import Unused
from _typeshed.wsgi import WSGIApplication
from collections.abc import Callable, Iterable
from typing import Any, Literal

from waitress.server import create_server as create_server
from waitress.adjustments import _AdjustmentsParams
from waitress.server import BaseWSGIServer

def serve(app: Any, **kw: Any) -> None: ...
def serve_paste(app: Any, global_conf: Any, **kw: Any) -> int: ...
def profile(cmd: Any, globals: Any, locals: Any, sort_order: tuple[str, ...], callers: bool) -> None: ...
def serve(
app: WSGIApplication,
*,
_server: Callable[..., BaseWSGIServer] = ...,
_quiet: bool = False,
_profile: bool = False,
**kw: _AdjustmentsParams,
) -> None: ...
def serve_paste(app: WSGIApplication, global_conf: Unused, **kw: _AdjustmentsParams) -> Literal[0]: ...
def profile(cmd: str, globals: dict[str, Any], locals: dict[str, Any], sort_order: Iterable[str], callers: bool) -> None: ...
20 changes: 12 additions & 8 deletions stubs/waitress/waitress/adjustments.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from _typeshed import Incomplete
from collections.abc import Iterable, Sequence
from socket import socket
from typing import Any
from typing import Final
from typing_extensions import TypeAlias

from .compat import HAS_IPV6 as HAS_IPV6, PY2 as PY2, WIN as WIN, string_types as string_types
from .proxy_headers import PROXY_HEADERS as PROXY_HEADERS
# Really complex, consider unpacking a TypedDict
_AdjustmentsParams: TypeAlias = Incomplete

truthy: frozenset[Any]
KNOWN_PROXY_HEADERS: frozenset[Any]
truthy: frozenset[str]
KNOWN_PROXY_HEADERS: Final[frozenset[str]]

def asbool(s: bool | str | int | None) -> bool: ...
def asoctal(s: str) -> int: ...
Expand All @@ -30,7 +32,7 @@ class Adjustments:
trusted_proxy_count: int | None
trusted_proxy_headers: set[str]
log_untrusted_proxy_headers: bool
clear_untrusted_proxy_headers: _bool_marker | bool
clear_untrusted_proxy_headers: type[_bool_marker] | bool
url_scheme: str
url_prefix: str
ident: str
Expand All @@ -55,8 +57,10 @@ class Adjustments:
ipv4: bool
ipv6: bool
sockets: list[socket]
def __init__(self, **kw: Any) -> None: ...
channel_request_lookahead: int
server_name: str
def __init__(self, **kw: _AdjustmentsParams) -> None: ...
@classmethod
def parse_args(cls, argv: str) -> tuple[dict[str, Any], Any]: ...
def parse_args(cls, argv: str) -> tuple[dict[str, bool], list[str]]: ...
@classmethod
def check_sockets(cls, sockets: Iterable[socket]) -> None: ...
17 changes: 8 additions & 9 deletions stubs/waitress/waitress/buffers.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from _typeshed import ReadableBuffer
from io import BufferedIOBase, BufferedRandom, BytesIO
from typing import Any, Literal
from typing import Final, Literal, NoReturn

COPY_BYTES: int
STRBUF_LIMIT: int
COPY_BYTES: Final = 262144
STRBUF_LIMIT: Final = 8192

class FileBasedBuffer:
remain: int
file: BytesIO
def __init__(self, file: BytesIO, from_buffer: BytesIO | None = None) -> None: ...
def __len__(self) -> int: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> Literal[True]: ...
def append(self, s: Any) -> None: ...
def append(self, s: ReadableBuffer) -> None: ...
def get(self, numbytes: int = -1, skip: bool = False) -> bytes: ...
def skip(self, numbytes: int, allow_prune: int = 0) -> None: ...
def newfile(self) -> Any: ...
def newfile(self) -> BufferedIOBase: ...
def prune(self) -> None: ...
def getfile(self) -> Any: ...
def getfile(self) -> BytesIO: ...
def close(self) -> None: ...

class TempfileBasedBuffer(FileBasedBuffer):
Expand All @@ -38,7 +38,7 @@ class ReadOnlyFileBasedBuffer(FileBasedBuffer):
def __iter__(self) -> ReadOnlyFileBasedBuffer: ...
def next(self) -> bytes | None: ...
__next__ = next
def append(self, s: Any) -> None: ...
def append(self, s: ReadableBuffer) -> NoReturn: ...

class OverflowableBuffer:
overflowed: bool
Expand All @@ -47,7 +47,6 @@ class OverflowableBuffer:
overflow: int
def __init__(self, overflow: int) -> None: ...
def __len__(self) -> int: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> bool: ...
def append(self, s: bytes) -> None: ...
def get(self, numbytes: int = -1, skip: bool = False) -> bytes: ...
Expand Down
25 changes: 14 additions & 11 deletions stubs/waitress/waitress/channel.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Mapping, Sequence
from socket import socket
from collections.abc import Sequence
from socket import _RetAddress, socket
from threading import Condition, Lock

from waitress.adjustments import Adjustments
Expand All @@ -8,15 +8,16 @@ from waitress.parser import HTTPRequestParser
from waitress.server import BaseWSGIServer
from waitress.task import ErrorTask, WSGITask

from . import wasyncore as wasyncore
from . import wasyncore
from .wasyncore import _SocketMap

class ClientDisconnected(Exception): ...

class HTTPChannel(wasyncore.dispatcher):
task_class: WSGITask
error_task_class: ErrorTask
parser_class: HTTPRequestParser
request: HTTPRequestParser
task_class: type[WSGITask]
error_task_class: type[ErrorTask]
parser_class: type[HTTPRequestParser]
request: HTTPRequestParser | None
last_activity: float
will_close: bool
close_when_flushed: bool
Expand All @@ -31,19 +32,21 @@ class HTTPChannel(wasyncore.dispatcher):
sendbuf_len: int
task_lock: Lock
outbuf_lock: Condition
addr: tuple[str, int]
addr: _RetAddress
def __init__(
self, server: BaseWSGIServer, sock: socket, addr: str, adj: Adjustments, map: Mapping[int, socket] | None = None
self, server: BaseWSGIServer, sock: socket, addr: _RetAddress, adj: Adjustments, map: _SocketMap | None = None
) -> None: ...
def check_client_disconnected(self) -> None: ...
def writable(self) -> bool: ...
def handle_write(self) -> None: ...
def readable(self) -> bool: ...
def handle_read(self) -> None: ...
def send_continue(self) -> None: ...
def received(self, data: bytes) -> bool: ...
connected: bool
def handle_close(self) -> None: ...
def add_channel(self, map: Mapping[int, socket] | None = None) -> None: ...
def del_channel(self, map: Mapping[int, socket] | None = None) -> None: ...
def add_channel(self, map: _SocketMap | None = None) -> None: ...
def del_channel(self, map: _SocketMap | None = None) -> None: ...
def write_soon(self, data: bytes) -> int: ...
def service(self) -> None: ...
def cancel(self) -> None: ...
34 changes: 6 additions & 28 deletions stubs/waitress/waitress/compat.pyi
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
from io import TextIOWrapper
from typing import Any, Literal
from typing import Final

PY2: Literal[False]
PY3: Literal[True]
WIN: bool
string_types: tuple[str]
integer_types: tuple[int]
class_types: tuple[type]

def unquote_bytes_to_wsgi(bytestring: bytes) -> str: ...
def text_(s: str, encoding: str = ..., errors: str = ...) -> str: ...
def tostr(s: str) -> str: ...
def tobytes(s: str) -> bytes: ...

exec_: Any

def reraise(tp: Any, value: BaseException, tb: str | None = ...) -> None: ...

MAXINT: int
HAS_IPV6: bool
IPPROTO_IPV6: int
IPV6_V6ONLY: int

def set_nonblocking(fd: TextIOWrapper) -> None: ...

ResourceWarning: Warning

def qualname(cls: Any) -> str: ...
WIN: Final[bool]
MAXINT: Final[int]
HAS_IPV6: Final[bool]
IPPROTO_IPV6: Final[int]
IPV6_V6ONLY: Final[int]
5 changes: 3 additions & 2 deletions stubs/waitress/waitress/parser.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from collections.abc import Mapping, Sequence
from io import BytesIO
from re import Pattern
from typing import Any

from waitress.adjustments import Adjustments
from waitress.receiver import ChunkedReceiver, FixedStreamReceiver
from waitress.utilities import Error

def unquote_bytes_to_wsgi(bytestring: str | bytes | bytearray) -> str: ...

class ParsingError(Exception): ...
class TransferEncodingNotImplemented(Exception): ...

Expand Down Expand Up @@ -38,6 +39,6 @@ class HTTPRequestParser:
def split_uri(uri: bytes) -> tuple[str, str, bytes, str, str]: ...
def get_header_lines(header: bytes) -> Sequence[bytes]: ...

first_line_re: Pattern[Any]
first_line_re: Pattern[str]

def crack_first_line(line: str) -> tuple[bytes, bytes, bytes]: ...
23 changes: 12 additions & 11 deletions stubs/waitress/waitress/proxy_headers.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from collections.abc import Callable, Mapping, Sequence
from _typeshed.wsgi import WSGIApplication
from collections.abc import Mapping, Sequence
from logging import Logger
from typing import Any, NamedTuple
from typing import Final, NamedTuple, TypeVar

from .utilities import BadRequest as BadRequest
_T = TypeVar("_T")

PROXY_HEADERS: frozenset[Any]
PROXY_HEADERS: Final[frozenset[str]]

class Forwarded(NamedTuple):
by: Any
for_: Any
host: Any
proto: Any
by: str
for_: str
host: str
proto: str

class MalformedProxyHeader(Exception):
header: str
Expand All @@ -19,18 +20,18 @@ class MalformedProxyHeader(Exception):
def __init__(self, header: str, reason: str, value: str) -> None: ...

def proxy_headers_middleware(
app: Any,
app: WSGIApplication,
trusted_proxy: str | None = None,
trusted_proxy_count: int = 1,
trusted_proxy_headers: set[str] | None = None,
clear_untrusted: bool = True,
log_untrusted: bool = False,
logger: Logger = ...,
) -> Callable[..., Any]: ...
) -> WSGIApplication: ...
def parse_proxy_headers(
environ: Mapping[str, str], trusted_proxy_count: int, trusted_proxy_headers: set[str], logger: Logger = ...
) -> set[str]: ...
def strip_brackets(addr: str) -> str: ...
def strip_brackets(addr: Sequence[_T]) -> Sequence[_T]: ...
def clear_untrusted_headers(
environ: Mapping[str, str], untrusted_headers: Sequence[str], log_warning: bool = False, logger: Logger = ...
) -> None: ...
39 changes: 27 additions & 12 deletions stubs/waitress/waitress/rfc7230.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
from .compat import tobytes as tobytes
from re import Pattern
from typing import Final

WS: str
OWS: str
RWS: str
BWS = str
TCHAR: str
OBS_TEXT: str
TOKEN: str
VCHAR: str
FIELD_VCHAR: str
FIELD_CONTENT: str
FIELD_VALUE: str
BWS: Final = r"[ \t]{0,}?"
CHUNK_EXT: Final[str]
CHUNK_EXT_NAME: Final = r"[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,}"
CHUNK_EXT_RE: Final[Pattern[str]]
CHUNK_EXT_VAL: Final[str]
DIGIT: Final = "[0-9]"
FIELD_CONTENT: Final[str]
FIELD_VALUE: Final[str]
FIELD_VCHAR: Final = r"[\x21-\x7e\x80-\xff]"
HEADER_FIELD_RE: Final[Pattern[str]]
HEXDIG: Final = r"[0-9a-fA-F]"
OBS_TEXT: Final = r"\x80-\xff"
ONLY_DIGIT_RE: Final[Pattern[str]]
ONLY_HEXDIG_RE: Final[Pattern[str]]
OWS: Final = r"[ \t]{0,}?"
QDTEXT: Final = r"[\t !#-[\]-~\x80-\xff]"
QUOTED_PAIR: Final = r"\\([\t \x21-\x7e\x80-\xff])"
QUOTED_PAIR_RE: Final[Pattern[str]]
QUOTED_STRING: Final[str]
QUOTED_STRING_RE: Final[Pattern[str]]
RWS: Final = r"[ \t]{1,}?"
TCHAR: Final = r"[!#$%&'*+\-.^_`|~0-9A-Za-z]"
TOKEN: Final = r"[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,}"
VCHAR: Final = r"\x21-\x7e"
WS: Final = r"[ \t]"
11 changes: 6 additions & 5 deletions stubs/waitress/waitress/runner.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from _typeshed import Unused
from collections.abc import Callable, Sequence
from io import TextIOWrapper
from re import Pattern
from typing import Any
from typing import Any, Final

HELP: str
RUNNER_PATTERN: Pattern[Any]
HELP: Final[str]
RUNNER_PATTERN: Final[Pattern[str]]

def match(obj_name: str) -> tuple[str, str]: ...
def resolve(module_name: str, object_name: str) -> Any: ...
def resolve(module_name: str, object_name: str) -> Any: ... # Any module attribute
def show_help(stream: TextIOWrapper, name: str, error: str | None = None) -> None: ...
def show_exception(stream: TextIOWrapper) -> None: ...
def run(argv: Sequence[str] = ..., _serve: Callable[..., object] = ...) -> None: ...
def run(argv: Sequence[str] = ..., _serve: Callable[..., Unused] = ...) -> None: ...
Loading