Rework socket (#5545)

* Extract _socket.pyi from socket.pyi.
* Extract _socket.socket from socket.socket.
* Fix socket.family annotation.
* Annotate SocketIO properly.
* SocketType is an alias of _socket.socket.
* Sort items in socket.pyi in the same order as in socket.py.
* Remove socket.EINTR.
* Use _typeshed.WriteableBuffer instead of custom alias.
* Add errorTab (Windows only).
* Add _socket.dup().
* Mark positional-only argments.
* Remove constructors from socket exceptions.
* socket.timeout is an alias for TimeoutError, starting with Python 3.10.
* Use PEP 604 in changed lines.
* Add alias for fileno arguments.
* getaddrinfo() port can be bytes.
* Explicitly override some SSLSocket methods.
* Allow ReadableBuffer in _CMSG arguments.
This commit is contained in:
Sebastian Rittau
2021-05-30 20:17:33 +02:00
committed by GitHub
parent ee4d9fb106
commit 6ee67483a3
15 changed files with 1245 additions and 754 deletions

View File

@@ -1,4 +1,4 @@
from socket import SocketType
from socket import socket
from typing import Any, AnyStr, Mapping, Optional, Tuple, Type
from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name
@@ -128,7 +128,7 @@ class Connection:
def kill(self, thread_id): ...
def ping(self, reconnect: bool = ...) -> None: ...
def set_charset(self, charset) -> None: ...
def connect(self, sock: Optional[SocketType] = ...) -> None: ...
def connect(self, sock: Optional[socket] = ...) -> None: ...
def write_packet(self, payload) -> None: ...
def _read_packet(self, packet_type=...): ...
def insert_id(self): ...

View File

@@ -1,4 +1,4 @@
from socket import SocketType
from socket import socket
from typing import Any, Dict, FrozenSet, Iterable, List, Optional, Sequence, Set, Tuple, Union
from .compat import HAS_IPV6 as HAS_IPV6, PY2 as PY2, WIN as WIN, string_types as string_types
@@ -14,7 +14,7 @@ def aslist(value: str) -> List[str]: ...
def asset(value: Optional[str]) -> Set[str]: ...
def slash_fixed_str(s: Optional[str]) -> str: ...
def str_iftruthy(s: Optional[str]) -> Optional[str]: ...
def as_socket_list(sockets: Sequence[object]) -> List[SocketType]: ...
def as_socket_list(sockets: Sequence[object]) -> List[socket]: ...
class _str_marker(str): ...
class _int_marker(int): ...
@@ -53,9 +53,9 @@ class Adjustments:
asyncore_use_poll: bool = ...
ipv4: bool = ...
ipv6: bool = ...
sockets: List[SocketType] = ...
sockets: List[socket] = ...
def __init__(self, **kw: Any) -> None: ...
@classmethod
def parse_args(cls, argv: str) -> Tuple[Dict[str, Any], Any]: ...
@classmethod
def check_sockets(cls, sockets: Iterable[SocketType]) -> None: ...
def check_sockets(cls, sockets: Iterable[socket]) -> None: ...

View File

@@ -1,4 +1,4 @@
from socket import SocketType
from socket import socket
from threading import Condition, Lock
from typing import Mapping, Optional, Sequence, Tuple
@@ -33,7 +33,7 @@ class HTTPChannel(wasyncore.dispatcher):
outbuf_lock: Condition = ...
addr: Tuple[str, int] = ...
def __init__(
self, server: BaseWSGIServer, sock: SocketType, addr: str, adj: Adjustments, map: Optional[Mapping[int, SocketType]] = ...
self, server: BaseWSGIServer, sock: socket, addr: str, adj: Adjustments, map: Optional[Mapping[int, socket]] = ...
) -> None: ...
def writable(self) -> bool: ...
def handle_write(self) -> None: ...
@@ -42,8 +42,8 @@ class HTTPChannel(wasyncore.dispatcher):
def received(self, data: bytes) -> bool: ...
connected: bool = ...
def handle_close(self) -> None: ...
def add_channel(self, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def del_channel(self, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def add_channel(self, map: Optional[Mapping[int, socket]] = ...) -> None: ...
def del_channel(self, map: Optional[Mapping[int, socket]] = ...) -> None: ...
def write_soon(self, data: bytes) -> int: ...
def service(self) -> None: ...
def cancel(self) -> None: ...

View File

@@ -1,4 +1,4 @@
from socket import SocketType
from socket import socket
from typing import Any, Optional, Sequence, Tuple, Union
from waitress.adjustments import Adjustments
@@ -11,7 +11,7 @@ def create_server(
application: Any,
map: Optional[Any] = ...,
_start: bool = ...,
_sock: Optional[SocketType] = ...,
_sock: Optional[socket] = ...,
_dispatcher: Optional[ThreadedTaskDispatcher] = ...,
**kw: Any,
) -> Union[MultiSocketServer, BaseWSGIServer]: ...
@@ -36,7 +36,7 @@ class MultiSocketServer:
class BaseWSGIServer(wasyncore.dispatcher):
channel_class: HTTPChannel = ...
next_channel_cleanup: int = ...
socketmod: SocketType = ...
socketmod: socket = ...
asyncore: Any = ...
sockinfo: Tuple[int, int, int, Tuple[str, int]] = ...
family: int = ...
@@ -81,7 +81,7 @@ class BaseWSGIServer(wasyncore.dispatcher):
class TcpWSGIServer(BaseWSGIServer):
def bind_server_socket(self) -> None: ...
def getsockname(self) -> Tuple[str, Tuple[str, int]]: ...
def set_socket_options(self, conn: SocketType) -> None: ...
def set_socket_options(self, conn: socket) -> None: ...
class UnixWSGIServer(BaseWSGIServer):
def __init__(

View File

@@ -1,5 +1,5 @@
import sys
from socket import SocketType
from socket import socket
from threading import Lock
from typing import Callable, Mapping, Optional
from typing_extensions import Literal
@@ -27,5 +27,5 @@ if sys.platform == "linux" or sys.platform == "darwin":
else:
class trigger(_triggerbase, wasyncore.dispatcher):
kind: str = ...
trigger: SocketType = ...
trigger: socket = ...
def __init__(self, map: Mapping[str, _triggerbase]) -> None: ...

View File

@@ -1,25 +1,27 @@
from io import BytesIO
from logging import Logger
from socket import SocketType
from socket import socket
from typing import Any, Callable, Mapping, Optional, Tuple
from . import compat as compat, utilities as utilities
socket_map: Mapping[int, SocketType]
map: Mapping[int, SocketType]
_socket = socket
socket_map: Mapping[int, socket]
map: Mapping[int, socket]
class ExitNow(Exception): ...
def read(obj: dispatcher) -> None: ...
def write(obj: dispatcher) -> None: ...
def readwrite(obj: dispatcher, flags: int) -> None: ...
def poll(timeout: float = ..., map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def poll2(timeout: float = ..., map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def poll(timeout: float = ..., map: Optional[Mapping[int, socket]] = ...) -> None: ...
def poll2(timeout: float = ..., map: Optional[Mapping[int, socket]] = ...) -> None: ...
poll3 = poll2
def loop(
timeout: float = ..., use_poll: bool = ..., map: Optional[Mapping[int, SocketType]] = ..., count: Optional[int] = ...
timeout: float = ..., use_poll: bool = ..., map: Optional[Mapping[int, socket]] = ..., count: Optional[int] = ...
) -> None: ...
def compact_traceback() -> Tuple[Tuple[str, str, str], BaseException, BaseException, str]: ...
@@ -33,20 +35,20 @@ class dispatcher:
ignore_log_types: frozenset = ...
logger: Logger = ...
compact_traceback: Callable[[], Tuple[Tuple[str, str, str], BaseException, BaseException, str]] = ...
socket: Optional[SocketType] = ...
def __init__(self, sock: Optional[SocketType] = ..., map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def add_channel(self, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def del_channel(self, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
socket: Optional[_socket] = ...
def __init__(self, sock: Optional[_socket] = ..., map: Optional[Mapping[int, _socket]] = ...) -> None: ...
def add_channel(self, map: Optional[Mapping[int, _socket]] = ...) -> None: ...
def del_channel(self, map: Optional[Mapping[int, _socket]] = ...) -> None: ...
family_and_type: Tuple[int, int] = ...
def create_socket(self, family: int = ..., type: int = ...) -> None: ...
def set_socket(self, sock: SocketType, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def set_socket(self, sock: _socket, map: Optional[Mapping[int, _socket]] = ...) -> None: ...
def set_reuse_addr(self) -> None: ...
def readable(self) -> bool: ...
def writable(self) -> bool: ...
def listen(self, num: int) -> None: ...
def bind(self, addr: Tuple[str, int]) -> None: ...
def connect(self, address: Tuple[str, int]) -> None: ...
def accept(self) -> Optional[Tuple[SocketType, Tuple[str, int]]]: ...
def accept(self) -> Optional[Tuple[_socket, Tuple[str, int]]]: ...
def send(self, data: bytes) -> int: ...
def recv(self, buffer_size: int) -> bytes: ...
def close(self) -> None: ...
@@ -62,18 +64,18 @@ class dispatcher:
def handle_write(self) -> None: ...
def handle_connect(self) -> None: ...
def handle_accept(self) -> None: ...
def handle_accepted(self, sock: SocketType, addr: Any) -> None: ...
def handle_accepted(self, sock: _socket, addr: Any) -> None: ...
def handle_close(self) -> None: ...
class dispatcher_with_send(dispatcher):
out_buffer: bytes = ...
def __init__(self, sock: Optional[SocketType] = ..., map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
def __init__(self, sock: Optional[socket] = ..., map: Optional[Mapping[int, socket]] = ...) -> None: ...
def initiate_send(self) -> None: ...
handle_write: Callable[[], None] = ...
def writable(self) -> bool: ...
def send(self, data: bytes) -> None: ... # type: ignore
def close_all(map: Optional[Mapping[int, SocketType]] = ..., ignore_all: bool = ...) -> None: ...
def close_all(map: Optional[Mapping[int, socket]] = ..., ignore_all: bool = ...) -> None: ...
class file_wrapper:
fd: BytesIO = ...
@@ -89,6 +91,6 @@ class file_wrapper:
class file_dispatcher(dispatcher):
connected: bool = ...
def __init__(self, fd: BytesIO, map: Optional[Mapping[int, SocketType]] = ...) -> None: ...
socket: SocketType = ...
def __init__(self, fd: BytesIO, map: Optional[Mapping[int, _socket]] = ...) -> None: ...
socket: _socket = ...
def set_file(self, fd: BytesIO) -> None: ...