From 0917560195d7f3270507b2e650f9fd7a5191ad95 Mon Sep 17 00:00:00 2001 From: hashstat Date: Sat, 7 Oct 2017 08:41:06 -0700 Subject: [PATCH] Add new methods to socket stubs. (#1638) * Add new methods to socket stubs. Also fix a couple of invalid types in recv*_into() socket methods. * Add double-underscores to parameters for position-only arguments --- stdlib/2and3/socket.pyi | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 15750bba9..4fc8f0d03 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -6,7 +6,7 @@ # see: http://nullege.com/codes/search/socket # adapted for Python 2.7 by Michal Pokorny import sys -from typing import Any, Tuple, List, Optional, Union, overload, TypeVar +from typing import Any, Iterable, Tuple, List, Optional, Union, overload, TypeVar # ----- variables and constants ----- @@ -498,6 +498,7 @@ class timeout(error): # TODO AF_PACKET and AF_BLUETOOTH address objects +_CMSG = Tuple[int, int, bytes] _SelfT = TypeVar('_SelfT', bound=socket) # ----- classes ----- @@ -549,9 +550,9 @@ class socket: # return type is an address def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ... - def recvfrom_into(self, buffer: bytes, nbytes: int, + def recvfrom_into(self, buffer: bytearray, nbytes: int, flags: int = ...) -> Any: ... - def recv_into(self, buffer: bytes, nbytes: int, + def recv_into(self, buffer: bytearray, nbytes: int, flags: int = ...) -> Any: ... def send(self, data: bytes, flags: int = ...) -> int: ... def sendall(self, data: bytes, flags: int =...) -> None: @@ -565,6 +566,14 @@ class socket: def setsockopt(self, level: int, optname: int, value: Union[int, bytes]) -> None: ... def shutdown(self, how: int) -> None: ... + if sys.version_info >= (3, 3): + def recvmsg(self, __bufsize: int, __ancbufsize: int = ..., + __flags: int = ...) -> Tuple[bytes, List[_CMSG], int, Any]: ... + def recvmsg_into(self, __buffers: Iterable[bytearray], __ancbufsize: int = ..., + __flags: int = ...) -> Tuple[int, List[_CMSG], int, Any]: ... + def sendmsg(self, __buffers: Iterable[bytes], __ancdata: Iterable[_CMSG] = ..., + __flags: int = ..., __address: Any = ...) -> int: ... + # ----- functions ----- def create_connection(address: Tuple[str, int], @@ -603,3 +612,11 @@ def inet_pton(address_family: int, ip_string: str) -> bytes: ... def inet_ntop(address_family: int, packed_ip: bytes) -> str: ... def getdefaulttimeout() -> Optional[float]: ... def setdefaulttimeout(timeout: Optional[float]) -> None: ... + +if sys.version_info >= (3, 3): + def CMSG_LEN(length: int) -> int: ... + def CMSG_SPACE(length: int) -> int: ... + def sethostname(name: str) -> None: ... + def if_nameindex() -> List[Tuple[int, str]]: ... + def if_nametoindex(name: str) -> int: ... + def if_indextoname(index: int) -> str: ...