-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
many more types including wsgiref.types
- Loading branch information
1 parent
706ab1c
commit f6dafc9
Showing
5 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
|
||
if sys.version_info >= (3, 11): | ||
from wsgiref.types import WSGIApplication | ||
else: | ||
from collections.abc import Callable, Iterable, Iterator | ||
from types import TracebackType | ||
from typing import Any, Dict, Protocol, Tuple, Type, Union | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
__all__ = [ | ||
"StartResponse", | ||
"WSGIEnvironment", | ||
"WSGIApplication", | ||
"InputStream", | ||
"ErrorStream", | ||
"FileWrapper", | ||
] | ||
|
||
_ExcInfo: TypeAlias = Tuple[Type[BaseException], BaseException, TracebackType] | ||
_OptExcInfo: TypeAlias = Union[_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: | ||
... | ||
|
||
# Optional: def close(self) -> object: ... | ||
|
||
class FileWrapper(Protocol): | ||
def __call__( | ||
self, __file: _Readable, __block_size: int = ... | ||
) -> Iterable[bytes]: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters