|
| 1 | +# NB: SocketServer.pyi and socketserver.pyi must remain consistent! |
| 2 | +# Stubs for socketserver |
| 3 | + |
| 4 | +from typing import Any, BinaryIO, Optional, Tuple, Type |
| 5 | +from socket import SocketType |
| 6 | +import sys |
| 7 | +import types |
| 8 | + |
| 9 | +class BaseServer: |
| 10 | + address_family = ... # type: int |
| 11 | + RequestHandlerClass = ... # type: type |
| 12 | + server_address = ... # type: Tuple[str, int] |
| 13 | + socket = ... # type: SocketType |
| 14 | + allow_reuse_address = ... # type: bool |
| 15 | + request_queue_size = ... # type: int |
| 16 | + socket_type = ... # type: int |
| 17 | + timeout = ... # type: Optional[float] |
| 18 | + def __init__(self, server_address: Tuple[str, int], |
| 19 | + RequestHandlerClass: type) -> None: ... |
| 20 | + def fileno(self) -> int: ... |
| 21 | + def handle_request(self) -> None: ... |
| 22 | + def serve_forever(self, poll_interval: float = ...) -> None: ... |
| 23 | + def shutdown(self) -> None: ... |
| 24 | + def server_close(self) -> None: ... |
| 25 | + def finish_request(self, request: bytes, |
| 26 | + client_address: Tuple[str, int]) -> None: ... |
| 27 | + def get_request(self) -> None: ... |
| 28 | + def handle_error(self, request: bytes, |
| 29 | + client_address: Tuple[str, int]) -> None: ... |
| 30 | + def handle_timeout(self) -> None: ... |
| 31 | + def process_request(self, request: bytes, |
| 32 | + client_address: Tuple[str, int]) -> None: ... |
| 33 | + def server_activate(self) -> None: ... |
| 34 | + def server_bind(self) -> None: ... |
| 35 | + def verify_request(self, request: bytes, |
| 36 | + client_address: Tuple[str, int]) -> bool: ... |
| 37 | + if sys.version_info >= (3, 6): |
| 38 | + def __enter__(self) -> 'BaseServer': ... |
| 39 | + def __exit__(self, exc_type: Optional[Type[BaseException]], |
| 40 | + exc_val: Optional[BaseException], |
| 41 | + exc_tb: Optional[types.TracebackType]) -> bool: ... |
| 42 | + if sys.version_info >= (3, 3): |
| 43 | + def service_actions(self) -> None: ... |
| 44 | + |
| 45 | +class TCPServer(BaseServer): |
| 46 | + def __init__(self, server_address: Tuple[str, int], |
| 47 | + RequestHandlerClass: type, |
| 48 | + bind_and_activate: bool = ...) -> None: ... |
| 49 | + |
| 50 | +class UDPServer(BaseServer): |
| 51 | + def __init__(self, server_address: Tuple[str, int], |
| 52 | + RequestHandlerClass: type, |
| 53 | + bind_and_activate: bool = ...) -> None: ... |
| 54 | + |
| 55 | +if sys.platform != 'win32': |
| 56 | + class UnixStreamServer(BaseServer): |
| 57 | + def __init__(self, server_address: Tuple[str, int], |
| 58 | + RequestHandlerClass: type, |
| 59 | + bind_and_activate: bool = ...) -> None: ... |
| 60 | + |
| 61 | + class UnixDatagramServer(BaseServer): |
| 62 | + def __init__(self, server_address: Tuple[str, int], |
| 63 | + RequestHandlerClass: type, |
| 64 | + bind_and_activate: bool = ...) -> None: ... |
| 65 | + |
| 66 | +class ForkingMixIn: ... |
| 67 | +class ThreadingMixIn: ... |
| 68 | + |
| 69 | +class ForkingTCPServer(ForkingMixIn, TCPServer): ... |
| 70 | +class ForkingUDPServer(ForkingMixIn, UDPServer): ... |
| 71 | +class ThreadingTCPServer(ThreadingMixIn, TCPServer): ... |
| 72 | +class ThreadingUDPServer(ThreadingMixIn, UDPServer): ... |
| 73 | +if sys.platform != 'win32': |
| 74 | + class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer): ... |
| 75 | + class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): ... |
| 76 | + |
| 77 | + |
| 78 | +class BaseRequestHandler: |
| 79 | + # Those are technically of types, respectively: |
| 80 | + # * Union[SocketType, Tuple[bytes, SocketType]] |
| 81 | + # * Union[Tuple[str, int], str] |
| 82 | + # But there are some concerns that having unions here would cause |
| 83 | + # too much inconvenience to people using it (see |
| 84 | + # https://github.com/python/typeshed/pull/384#issuecomment-234649696) |
| 85 | + request = ... # type: Any |
| 86 | + client_address = ... # type: Any |
| 87 | + |
| 88 | + server = ... # type: BaseServer |
| 89 | + def setup(self) -> None: ... |
| 90 | + def handle(self) -> None: ... |
| 91 | + def finish(self) -> None: ... |
| 92 | + |
| 93 | +class StreamRequestHandler(BaseRequestHandler): |
| 94 | + rfile = ... # type: BinaryIO |
| 95 | + wfile = ... # type: BinaryIO |
| 96 | + |
| 97 | +class DatagramRequestHandler(BaseRequestHandler): |
| 98 | + rfile = ... # type: BinaryIO |
| 99 | + wfile = ... # type: BinaryIO |
0 commit comments