Complete wsgiref (#2165)

* Add wsgiref.handlers

* Add wsgiref.simple_server
This commit is contained in:
Sebastian Rittau
2018-05-28 17:08:27 +02:00
committed by Jelle Zijlstra
parent dc0fcdcaa0
commit b1cd9fedf8
3 changed files with 132 additions and 10 deletions

View File

@@ -0,0 +1,87 @@
import sys
from abc import abstractmethod
from types import TracebackType
from typing import Optional, Dict, MutableMapping, Type, Text, Callable, List, Tuple, IO
from .headers import Headers
from .types import WSGIApplication, WSGIEnvironment, StartResponse, InputStream, ErrorStream
from .util import FileWrapper, guess_scheme
_exc_info = Tuple[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]]
def format_date_time(timestamp: Optional[float]) -> str: ... # undocumented
if sys.version_info >= (3, 2):
def read_environ() -> Dict[str, str]: ...
class BaseHandler:
wsgi_version: Tuple[int, int] # undocumented
wsgi_multithread: bool
wsgi_multiprocess: bool
wsgi_run_once: bool
origin_server: bool
http_version: str
server_software: Optional[str]
os_environ: MutableMapping[str, str]
wsgi_file_wrapper: Optional[Type[FileWrapper]]
headers_class: Type[Headers] # undocumented
traceback_limit: Optional[int]
error_status: str
error_headers: List[Tuple[Text, Text]]
error_body: bytes
def run(self, application: WSGIApplication) -> None: ...
def setup_environ(self) -> None: ...
def finish_response(self) -> None: ...
def get_scheme(self) -> str: ...
def set_content_length(self) -> None: ...
def cleanup_headers(self) -> None: ...
def start_response(self, status: Text, headers: List[Tuple[Text, Text]], exc_info: Optional[_exc_info] = ...) -> Callable[[bytes], None]: ...
def send_preamble(self) -> None: ...
def write(self, data: bytes) -> None: ...
def sendfile(self) -> bool: ...
def finish_content(self) -> None: ...
def close(self) -> None: ...
def send_headers(self) -> None: ...
def result_is_file(self) -> bool: ...
def client_is_modern(self) -> bool: ...
def log_exception(self, exc_info: _exc_info) -> None: ...
def handle_error(self) -> None: ...
def error_output(self, environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ...
@abstractmethod
def _write(self, data: bytes) -> None: ...
@abstractmethod
def _flush(self) -> None: ...
@abstractmethod
def get_stdin(self) -> InputStream: ...
@abstractmethod
def get_stderr(self) -> ErrorStream: ...
@abstractmethod
def add_cgi_vars(self) -> None: ...
class SimpleHandler(BaseHandler):
stdin: InputStream
stdout: IO[bytes]
stderr: ErrorStream
base_env: MutableMapping[str, str]
def __init__(self, stdin: InputStream, stdout: IO[bytes], stderr: ErrorStream, environ: MutableMapping[str, str], multithread: bool = ..., multiprocess: bool = ...) -> None: ...
def get_stdin(self) -> InputStream: ...
def get_stderr(self) -> ErrorStream: ...
def add_cgi_vars(self) -> None: ...
def _write(self, data: bytes) -> None: ...
def _flush(self) -> None: ...
class BaseCGIHandler(SimpleHandler): ...
class CGIHandler(BaseCGIHandler):
def __init__(self) -> None: ...
class IISCGIHandler(BaseCGIHandler):
def __init__(self) -> None: ...

View File

@@ -0,0 +1,40 @@
import sys
from typing import Optional, List, Type, TypeVar, overload
from .handlers import SimpleHandler
from .types import WSGIApplication, WSGIEnvironment, StartResponse, ErrorStream
if sys.version_info < (3,):
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
else:
from http.server import HTTPServer, BaseHTTPRequestHandler
server_version: str # undocumented
sys_version: str # undocumented
software_version: str # undocumented
class ServerHandler(SimpleHandler): # undocumented
server_software: str
def close(self) -> None: ...
class WSGIServer(HTTPServer):
application: Optional[WSGIApplication]
base_environ: WSGIEnvironment # only available after call to setup_environ()
def setup_environ(self) -> None: ...
def get_app(self) -> Optional[WSGIApplication]: ...
def set_app(self, application: Optional[WSGIApplication]) -> None: ...
class WSGIRequestHandler(BaseHTTPRequestHandler):
server_version: str
def get_environ(self) -> WSGIEnvironment: ...
def get_stderr(self) -> ErrorStream: ...
def handle(self) -> None: ...
def demo_app(environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ...
_S = TypeVar("_S", bound=WSGIServer)
@overload
def make_server(host: str, port: int, app: WSGIApplication, *, handler_class: Type[WSGIRequestHandler] = ...) -> WSGIServer: ...
@overload
def make_server(host: str, port: int, app: WSGIApplication, server_class: Type[_S], handler_class: Type[WSGIRequestHandler] = ...) -> _S: ...

View File

@@ -21,17 +21,12 @@ from types import TracebackType
_exc_info = Tuple[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]]
WSGIEnvironment = Dict[Text, Any]
WSGIApplication = Callable[
[
WSGIEnvironment,
Union[
Callable[[Text, List[Tuple[Text, Text]]], Callable[[bytes], None]],
Callable[[Text, List[Tuple[Text, Text]], _exc_info], Callable[[bytes], None]]
]
],
Iterable[bytes]
StartResponse = Union[
Callable[[Text, List[Tuple[Text, Text]]], Callable[[bytes], None]],
Callable[[Text, List[Tuple[Text, Text]], _exc_info], Callable[[bytes], None]]
]
WSGIEnvironment = Dict[Text, Any]
WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]]
# WSGI input streams per PEP 3333
class InputStream(Protocol):