import sys import typing def bytes2str(bstr: bytes) -> str: assert isinstance(bstr, bytes) return bstr.decode("iso-8859-1") # always successful def str2bytes(sstr: str) -> bytes: assert isinstance(sstr, str) return sstr.encode("iso-8859-1") # might fail, but spec says it doesn't def textopen(filename: str, mode: str) -> typing.TextIO: # We use the same encoding as for all wsgi strings here. return open(filename, mode, encoding="iso-8859-1") Environ = typing.Dict[str, typing.Any] HeaderList = typing.List[typing.Tuple[str, str]] if sys.version_info >= (3, 11): OptExcInfo = typing.Optional[ typing.Tuple[type[BaseException], BaseException, typing.Any] ] else: OptExcInfo = typing.Optional[ typing.Tuple[typing.Any, BaseException, typing.Any] ] WriteCallback = typing.Callable[[bytes], None] if sys.version_info >= (3, 11): class StartResponse(typing.Protocol): def __call__( self, status: str, headers: HeaderList, exc_info: OptExcInfo = None ) -> WriteCallback: ... else: StartResponse = typing.Callable[ [str, HeaderList, OptExcInfo], WriteCallback ] WsgiApp = typing.Callable[[Environ, StartResponse], typing.Iterable[bytes]]