summaryrefslogtreecommitdiff
path: root/wsgitools/internal.py
diff options
context:
space:
mode:
Diffstat (limited to 'wsgitools/internal.py')
-rw-r--r--wsgitools/internal.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/wsgitools/internal.py b/wsgitools/internal.py
index 9bf7ded..86a9d5a 100644
--- a/wsgitools/internal.py
+++ b/wsgitools/internal.py
@@ -1,11 +1,42 @@
-def bytes2str(bstr):
+import sys
+import typing
+
+def bytes2str(bstr: bytes) -> str:
assert isinstance(bstr, bytes)
return bstr.decode("iso-8859-1") # always successful
-def str2bytes(sstr):
+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, mode):
+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]]