Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active June 10, 2018 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dahlia/e618b303ab64c0e7e32b1f7957ca283a to your computer and use it in GitHub Desktop.
Save dahlia/e618b303ab64c0e7e32b1f7957ca283a to your computer and use it in GitHub Desktop.
WSGI application object type specified using typing
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