From e26971a082c9333f28ba82f94f4f8b948fa53360 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Sat, 10 Apr 2021 18:00:35 +0300 Subject: [PATCH] ssl stubtest exception fix/explanation (#5137) --- stdlib/ssl.pyi | 49 +++++++++++++++++++++++- tests/stubtest_whitelists/linux-py36.txt | 4 +- tests/stubtest_whitelists/py36.txt | 1 - tests/stubtest_whitelists/py37.txt | 4 +- tests/stubtest_whitelists/py38.txt | 4 +- tests/stubtest_whitelists/py39.txt | 5 +-- tests/stubtest_whitelists/py3_common.txt | 15 ++------ 7 files changed, 59 insertions(+), 23 deletions(-) diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 4b9eec42c..c59df13e7 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -245,6 +245,42 @@ class SSLSocket(socket.socket): if sys.version_info >= (3, 6): session: Optional[SSLSession] session_reused: Optional[bool] + if sys.version_info < (3, 7): + def __init__( + self, + sock: Optional[socket.socket] = ..., + keyfile: Optional[str] = ..., + certfile: Optional[str] = ..., + server_side: bool = ..., + cert_reqs: int = ..., + ssl_version: int = ..., + ca_certs: Optional[str] = ..., + do_handshake_on_connect: bool = ..., + family: int = ..., + type: int = ..., + proto: int = ..., + fileno: Optional[int] = ..., + suppress_ragged_eofs: bool = ..., + npn_protocols: Optional[Iterable[str]] = ..., + ciphers: Optional[str] = ..., + server_hostname: Optional[str] = ..., + _context: Optional[SSLContext] = ..., + _session: Optional[Any] = ..., + ) -> None: ... + else: + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def connect(self, addr: Union[socket._Address, bytes]) -> None: ... + def connect_ex(self, addr: Union[socket._Address, bytes]) -> int: ... + def recv(self, buflen: int = ..., flags: int = ...) -> bytes: ... + def recv_into(self, buffer: socket._WriteBuffer, nbytes: Optional[int] = ..., flags: int = ...) -> int: ... + def recvfrom(self, buflen: int = ..., flags: int = ...) -> tuple[bytes, socket._RetAddress]: ... + def recvfrom_into( + self, buffer: socket._WriteBuffer, nbytes: Optional[int] = ..., flags: int = ... + ) -> tuple[int, socket._RetAddress]: ... + @overload + def sendto(self, data: bytes, flags_or_addr: socket._Address) -> int: ... + @overload + def sendto(self, data: bytes, flags_or_addr: Union[int, socket._Address], addr: Optional[socket._Address] = ...) -> int: ... def read(self, len: int = ..., buffer: Optional[bytearray] = ...) -> bytes: ... def write(self, data: bytes) -> int: ... def do_handshake(self, block: bool = ...) -> None: ... # block is undocumented @@ -286,6 +322,10 @@ class SSLContext: options: int if sys.version_info >= (3, 8): post_handshake_auth: bool + if sys.version_info >= (3, 5): + def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> SSLContext: ... + else: + def __new__(cls, protocol: int, *args: Any, **kwargs: Any) -> SSLContext: ... @property def protocol(self) -> int: ... verify_flags: int @@ -362,6 +402,12 @@ if sys.version_info >= (3, 5): if sys.version_info >= (3, 6): session: Optional[SSLSession] session_reused: bool + if sys.version_info >= (3, 7): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + else: + def __init__( + self, sslobj: Any, owner: Optional[Union[SSLSocket, SSLObject]] = ..., session: Optional[Any] = ... + ) -> None: ... def read(self, len: int = ..., buffer: Optional[bytearray] = ...) -> bytes: ... def write(self, data: bytes) -> int: ... @overload @@ -421,7 +467,8 @@ SSL_ERROR_ZERO_RETURN: int def get_protocol_name(protocol_code: int) -> str: ... -AF_INET: int +if sys.version_info < (3, 9): + AF_INET: int PEM_FOOTER: str PEM_HEADER: str SOCK_STREAM: int diff --git a/tests/stubtest_whitelists/linux-py36.txt b/tests/stubtest_whitelists/linux-py36.txt index f9c4b5f3b..088b045c4 100644 --- a/tests/stubtest_whitelists/linux-py36.txt +++ b/tests/stubtest_whitelists/linux-py36.txt @@ -1,4 +1,4 @@ ctypes.wintypes pwd.getpwnam -ssl.PROTOCOL_SSLv3 -ssl.RAND_egd +ssl.PROTOCOL_SSLv3 # Depends on openssl compilation +ssl.RAND_egd # Depends on openssl compilation diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index df9ae916a..cf51af947 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -42,7 +42,6 @@ random.randrange # missing undocumented arg _int secrets.SystemRandom.getstate smtplib.SMTP.sendmail sre_compile.dis -ssl.SSLSocket.__init__ typing.AsyncGenerator.ag_await typing.AsyncGenerator.ag_code typing.AsyncGenerator.ag_frame diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index 68493f58e..48747a556 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -52,8 +52,8 @@ random.randrange # missing undocumented arg _int secrets.SystemRandom.getstate smtplib.SMTP.sendmail sre_constants.RANGE_IGNORE -ssl.PROTOCOL_SSLv3 -ssl.RAND_egd +ssl.PROTOCOL_SSLv3 # Depends on ssl compilation +ssl.RAND_egd # Depends on openssl compilation types.ClassMethodDescriptorType.__get__ types.MethodDescriptorType.__get__ types.WrapperDescriptorType.__get__ diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index d4f516045..73cc05ba6 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -74,8 +74,8 @@ secrets.SystemRandom.getstate select.epoll.register smtplib.SMTP.sendmail sre_constants.RANGE_IGNORE -ssl.PROTOCOL_SSLv3 -ssl.RAND_egd +ssl.PROTOCOL_SSLv3 # Depends on ssl compilation +ssl.RAND_egd # Depends on openssl compilation sys.UnraisableHookArgs # Not exported from sys types.ClassMethodDescriptorType.__get__ types.CodeType.replace diff --git a/tests/stubtest_whitelists/py39.txt b/tests/stubtest_whitelists/py39.txt index 48775962a..858e3f071 100644 --- a/tests/stubtest_whitelists/py39.txt +++ b/tests/stubtest_whitelists/py39.txt @@ -96,9 +96,8 @@ select.epoll.register smtplib.LMTP.__init__ smtplib.SMTP.sendmail sre_constants.RANGE_IGNORE -ssl.AF_INET -ssl.PROTOCOL_SSLv3 -ssl.RAND_egd +ssl.PROTOCOL_SSLv3 # Depends on ssl compilation +ssl.RAND_egd # Depends on openssl compilation symtable.SymbolTable.has_exec sys.UnraisableHookArgs # Not exported from sys time.CLOCK_PROF diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 99e8b0d0d..e63fb667e 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -332,18 +332,9 @@ sqlite3.dbapi2.Row.__len__ sqlite3.dbapi2.version_info sqlite3.version_info sre_constants.error.__init__ -ssl.PROTOCOL_SSLv2 -ssl.Purpose.__new__ -ssl.SSLContext.__new__ -ssl.SSLObject.__init__ -ssl.SSLSocket.connect -ssl.SSLSocket.connect_ex -ssl.SSLSocket.recv -ssl.SSLSocket.recv_into -ssl.SSLSocket.recvfrom -ssl.SSLSocket.recvfrom_into -ssl.SSLSocket.sendto -ssl._ASN1Object.__new__ +ssl.PROTOCOL_SSLv2 # Defined only if compiled with ssl v2 +ssl.Purpose.__new__ # You cannot override __new__ in NamedTuple and runtime uses namedtuple. +ssl._ASN1Object.__new__ # You cannot override __new__ in NamedTuple and runtime uses namedtuple. subprocess.Popen.__init__ sunau.Au_write.getmark sunau.Au_write.getmarkers