wsgirelated types for static type checking from collections abc import callable iterable iterator from types import tracebacktype from typing import any protocol typealias all startresponse wsgienvironment wsgiapplication inputstream errorstream filewrapper excinfo typealias tupletypebaseexception baseexception tracebacktype optexcinfo typealias excinfo tuplenone none none class startresponseprotocol wsgi input stream as defined in pep 3333 def readself size int bytes def readlineself size int bytes def readlinesself hint int listbytes def iterself iteratorbytes class errorstreamprotocol optional def closeself object wsgi file wrapper as defined in pep 3333 def call self file readable blocksize int iterablebytes start_response callable as defined in pep 3333 wsgi input stream as defined in pep 3333 wsgi error stream as defined in pep 3333 optional def close self object wsgi file wrapper as defined in pep 3333
from collections.abc import Callable, Iterable, Iterator
from types import TracebackType
from typing import Any, Protocol, TypeAlias

__all__ = [
    "StartResponse",
    "WSGIEnvironment",
    "WSGIApplication",
    "InputStream",
    "ErrorStream",
    "FileWrapper",
]

_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
_OptExcInfo: TypeAlias = _ExcInfo | tuple[None, None, None]

class StartResponse(Protocol):
    
    def __call__(
        self,
        status: str,
        headers: list[tuple[str, str]],
        exc_info: _OptExcInfo | None = ...,
        /,
    ) -> Callable[[bytes], object]: ...

WSGIEnvironment: TypeAlias = dict[str, Any]
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse],
    Iterable[bytes]]

class InputStream(Protocol):
    
    def read(self, size: int = ..., /) -> bytes: ...
    def readline(self, size: int = ..., /) -> bytes: ...
    def readlines(self, hint: int = ..., /) -> list[bytes]: ...
    def __iter__(self) -> Iterator[bytes]: ...

class ErrorStream(Protocol):
    
    def flush(self) -> object: ...
    def write(self, s: str, /) -> object: ...
    def writelines(self, seq: list[str], /) -> object: ...

class _Readable(Protocol):
    def read(self, size: int = ..., /) -> bytes: ...
    

class FileWrapper(Protocol):
    
    def __call__(
        self, file: _Readable, block_size: int = ..., /,
    ) -> Iterable[bytes]: ...