Last active
June 10, 2018 07:09
-
-
Save dahlia/e618b303ab64c0e7e32b1f7957ca283a to your computer and use it in GitHub Desktop.
WSGI application object type specified using typing
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
import types | |
from typing import (Any, Callable, Iterable, Mapping, | |
Optional, Sequence, Tuple, Union) | |
__all__ = ('Environ', 'ExcInfo', 'ResponseStream', 'StartResponse', | |
'StartResponseCallable', 'StartResponseCallableWithExcInfo', | |
'WriteCallable', 'WsgiApplication') | |
# https://www.python.org/dev/peps/pep-3333/#the-write-callable | |
WriteCallable = Callable[[bytes], Any] | |
# https://docs.python.org/3/library/sys.html#sys.exc_info | |
ExcInfo = Tuple[type, BaseException, types.TracebackType] | |
# https://www.python.org/dev/peps/pep-3333/#the-start-response-callable | |
StartResponseCallable = Callable[ | |
[ | |
str, # status | |
Sequence[Tuple[str, str]], # response headers | |
], | |
WriteCallable # write() callable | |
] | |
StartResponseCallableWithExcInfo = Callable[ | |
[ | |
str, # status | |
Sequence[Tuple[str, str]], # response headers | |
Optional[ExcInfo] # exc_info | |
], | |
WriteCallable # write() callable | |
] | |
StartResponse = Union[StartResponseCallable, StartResponseCallableWithExcInfo] | |
# https://www.python.org/dev/peps/pep-3333/#environ-variables | |
Environ = Mapping[str, object] | |
# https://www.python.org/dev/peps/pep-3333/#buffering-and-streaming | |
ResponseStream = Iterable[bytes] | |
# https://www.python.org/dev/peps/pep-3333/#specification-details | |
WsgiApplication = Callable[ | |
[ | |
Environ, # environ | |
StartResponse, # start_response() function | |
], | |
ResponseStream # bytestring chunks | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment