| 
									
										
										
										
											2022-04-16 19:37:58 +02:00
										 |  |  | """WSGI-related types for static type checking""" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-21 13:26:04 -07:00
										 |  |  | from collections.abc import Callable, Iterable, Iterator | 
					
						
							| 
									
										
										
										
											2022-04-16 19:37:58 +02:00
										 |  |  | from types import TracebackType | 
					
						
							|  |  |  | from typing import Any, Protocol, TypeAlias | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __all__ = [ | 
					
						
							|  |  |  |     "StartResponse", | 
					
						
							|  |  |  |     "WSGIEnvironment", | 
					
						
							|  |  |  |     "WSGIApplication", | 
					
						
							|  |  |  |     "InputStream", | 
					
						
							|  |  |  |     "ErrorStream", | 
					
						
							|  |  |  |     "FileWrapper", | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-16 22:37:02 +02:00
										 |  |  | _ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType] | 
					
						
							|  |  |  | _OptExcInfo: TypeAlias = _ExcInfo | tuple[None, None, None] | 
					
						
							| 
									
										
										
										
											2022-04-16 19:37:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class StartResponse(Protocol): | 
					
						
							|  |  |  |     """start_response() callable as defined in PEP 3333""" | 
					
						
							|  |  |  |     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): | 
					
						
							|  |  |  |     """WSGI input stream as defined in PEP 3333""" | 
					
						
							|  |  |  |     def read(self, size: int = ..., /) -> bytes: ... | 
					
						
							|  |  |  |     def readline(self, size: int = ..., /) -> bytes: ... | 
					
						
							|  |  |  |     def readlines(self, hint: int = ..., /) -> list[bytes]: ... | 
					
						
							| 
									
										
										
										
											2022-07-21 13:26:04 -07:00
										 |  |  |     def __iter__(self) -> Iterator[bytes]: ... | 
					
						
							| 
									
										
										
										
											2022-04-16 19:37:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ErrorStream(Protocol): | 
					
						
							|  |  |  |     """WSGI error stream as defined in PEP 3333""" | 
					
						
							|  |  |  |     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): | 
					
						
							|  |  |  |     """WSGI file wrapper as defined in PEP 3333""" | 
					
						
							|  |  |  |     def __call__( | 
					
						
							|  |  |  |         self, file: _Readable, block_size: int = ..., /, | 
					
						
							|  |  |  |     ) -> Iterable[bytes]: ... |