clean python 3 specific stuff from stdlib/@python2 stubs (#5451)

This commit is contained in:
Akuli
2021-05-15 01:19:05 +03:00
committed by GitHub
parent f94d838814
commit 5ec4f06263
121 changed files with 1024 additions and 4801 deletions

View File

@@ -4,9 +4,6 @@ from _typeshed import StrPath
from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Optional, Set, Text, Tuple, Type, Union, overload
from typing_extensions import Literal
if sys.version_info >= (3, 4):
import enum
_PCTRTT = Tuple[Tuple[str, str], ...]
_PCTRTTT = Tuple[_PCTRTT, ...]
_PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]]
@@ -14,10 +11,7 @@ _PeerCertRetType = Union[_PeerCertRetDictType, bytes, None]
_EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]]
_PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes]
if sys.version_info >= (3, 5):
_SC1ArgT = Union[SSLSocket, SSLObject]
else:
_SC1ArgT = SSLSocket
_SC1ArgT = SSLSocket
_SrvnmeCbType = Callable[[_SC1ArgT, Optional[str], SSLSocket], Optional[int]]
class SSLError(OSError):
@@ -29,14 +23,7 @@ class SSLWantReadError(SSLError): ...
class SSLWantWriteError(SSLError): ...
class SSLSyscallError(SSLError): ...
class SSLEOFError(SSLError): ...
if sys.version_info >= (3, 7):
class SSLCertVerificationError(SSLError, ValueError):
verify_code: int
verify_message: str
CertificateError = SSLCertVerificationError
else:
class CertificateError(ValueError): ...
class CertificateError(ValueError): ...
def wrap_socket(
sock: socket.socket,
@@ -53,41 +40,21 @@ def wrap_socket(
def create_default_context(
purpose: Any = ..., *, cafile: Optional[str] = ..., capath: Optional[str] = ..., cadata: Union[Text, bytes, None] = ...
) -> SSLContext: ...
if sys.version_info >= (3, 7):
def _create_unverified_context(
protocol: int = ...,
*,
cert_reqs: int = ...,
check_hostname: bool = ...,
purpose: Any = ...,
certfile: Optional[str] = ...,
keyfile: Optional[str] = ...,
cafile: Optional[str] = ...,
capath: Optional[str] = ...,
cadata: Union[Text, bytes, None] = ...,
) -> SSLContext: ...
else:
def _create_unverified_context(
protocol: int = ...,
*,
cert_reqs: Optional[int] = ...,
check_hostname: bool = ...,
purpose: Any = ...,
certfile: Optional[str] = ...,
keyfile: Optional[str] = ...,
cafile: Optional[str] = ...,
capath: Optional[str] = ...,
cadata: Union[Text, bytes, None] = ...,
) -> SSLContext: ...
def _create_unverified_context(
protocol: int = ...,
*,
cert_reqs: Optional[int] = ...,
check_hostname: bool = ...,
purpose: Any = ...,
certfile: Optional[str] = ...,
keyfile: Optional[str] = ...,
cafile: Optional[str] = ...,
capath: Optional[str] = ...,
cadata: Union[Text, bytes, None] = ...,
) -> SSLContext: ...
_create_default_https_context: Callable[..., SSLContext]
if sys.version_info >= (3, 3):
def RAND_bytes(__num: int) -> bytes: ...
def RAND_pseudo_bytes(__num: int) -> Tuple[bytes, bool]: ...
def RAND_status() -> bool: ...
def RAND_egd(path: str) -> None: ...
def RAND_add(__s: bytes, __entropy: float) -> None: ...
@@ -128,64 +95,17 @@ PROTOCOL_TLSv1: int
PROTOCOL_TLSv1_1: int
PROTOCOL_TLSv1_2: int
PROTOCOL_TLS: int
if sys.version_info >= (3, 6):
PROTOCOL_TLS_CLIENT: int
PROTOCOL_TLS_SERVER: int
OP_ALL: int
OP_NO_SSLv2: int
OP_NO_SSLv3: int
OP_NO_TLSv1: int
OP_NO_TLSv1_1: int
OP_NO_TLSv1_2: int
OP_CIPHER_SERVER_PREFERENCE: int
OP_SINGLE_DH_USE: int
OP_SINGLE_ECDH_USE: int
OP_NO_COMPRESSION: int
if sys.version_info >= (3, 6):
class Options(enum.IntFlag):
OP_ALL: int
OP_NO_SSLv2: int
OP_NO_SSLv3: int
OP_NO_TLSv1: int
OP_NO_TLSv1_1: int
OP_NO_TLSv1_2: int
OP_NO_TLSv1_3: int
OP_CIPHER_SERVER_PREFERENCE: int
OP_SINGLE_DH_USE: int
OP_SINGLE_ECDH_USE: int
OP_NO_COMPRESSION: int
OP_NO_TICKET: int
if sys.version_info >= (3, 7):
OP_NO_RENEGOTIATION: int
if sys.version_info >= (3, 8):
OP_ENABLE_MIDDLEBOX_COMPAT: int
OP_ALL: Options
OP_NO_SSLv2: Options
OP_NO_SSLv3: Options
OP_NO_TLSv1: Options
OP_NO_TLSv1_1: Options
OP_NO_TLSv1_2: Options
OP_NO_TLSv1_3: Options
OP_CIPHER_SERVER_PREFERENCE: Options
OP_SINGLE_DH_USE: Options
OP_SINGLE_ECDH_USE: Options
OP_NO_COMPRESSION: Options
OP_NO_TICKET: Options
if sys.version_info >= (3, 7):
OP_NO_RENEGOTIATION: Options
if sys.version_info >= (3, 8):
OP_ENABLE_MIDDLEBOX_COMPAT: Options
else:
OP_ALL: int
OP_NO_SSLv2: int
OP_NO_SSLv3: int
OP_NO_TLSv1: int
OP_NO_TLSv1_1: int
OP_NO_TLSv1_2: int
OP_CIPHER_SERVER_PREFERENCE: int
OP_SINGLE_DH_USE: int
OP_SINGLE_ECDH_USE: int
OP_NO_COMPRESSION: int
if sys.version_info >= (3, 7):
HAS_NEVER_CHECK_COMMON_NAME: bool
HAS_SSLv2: bool
HAS_SSLv3: bool
HAS_TLSv1: bool
HAS_TLSv1_1: bool
HAS_TLSv1_2: bool
HAS_TLSv1_3: bool
HAS_ALPN: bool
HAS_ECDH: bool
HAS_SNI: bool
@@ -230,47 +150,35 @@ class _ASN1Object(NamedTuple):
longname: str
oid: str
if sys.version_info >= (3, 4):
class Purpose(_ASN1Object, enum.Enum):
SERVER_AUTH: _ASN1Object
CLIENT_AUTH: _ASN1Object
else:
class Purpose(_ASN1Object):
SERVER_AUTH: ClassVar[Purpose]
CLIENT_AUTH: ClassVar[Purpose]
class Purpose(_ASN1Object):
SERVER_AUTH: ClassVar[Purpose]
CLIENT_AUTH: ClassVar[Purpose]
class SSLSocket(socket.socket):
context: SSLContext
server_side: bool
server_hostname: Optional[str]
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 __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: ...
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: ...
@@ -293,8 +201,6 @@ class SSLSocket(socket.socket):
@overload
def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
def cipher(self) -> Optional[Tuple[str, str, int]]: ...
if sys.version_info >= (3, 5):
def shared_ciphers(self) -> Optional[List[Tuple[str, str, int]]]: ...
def compression(self) -> Optional[str]: ...
def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ...
def selected_alpn_protocol(self) -> Optional[str]: ...
@@ -303,39 +209,16 @@ class SSLSocket(socket.socket):
def unwrap(self) -> socket.socket: ...
def version(self) -> Optional[str]: ...
def pending(self) -> int: ...
if sys.version_info >= (3, 8):
def verify_client_post_handshake(self) -> None: ...
if sys.version_info >= (3, 7):
class TLSVersion(enum.IntEnum):
MINIMUM_SUPPORTED: int
MAXIMUM_SUPPORTED: int
SSLv3: int
TLSv1: int
TLSv1_1: int
TLSv1_2: int
TLSv1_3: int
class SSLContext:
check_hostname: bool
if sys.version_info >= (3, 6):
options: Options
else:
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: ...
options: int
def __new__(cls, protocol: int, *args: Any, **kwargs: Any) -> SSLContext: ...
@property
def protocol(self) -> int: ...
verify_flags: int
verify_mode: int
if sys.version_info >= (3, 5):
def __init__(self, protocol: int = ...) -> None: ...
else:
def __init__(self, protocol: int) -> None: ...
def __init__(self, protocol: int) -> None: ...
def cert_store_stats(self) -> Dict[str, int]: ...
def load_cert_chain(
self, certfile: StrPath, keyfile: Optional[StrPath] = ..., password: Optional[_PasswordType] = ...
@@ -348,112 +231,19 @@ class SSLContext:
def set_default_verify_paths(self) -> None: ...
def set_ciphers(self, __cipherlist: str) -> None: ...
def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ...
if sys.version_info >= (3, 7):
sni_callback: Optional[Callable[[SSLObject, str, SSLContext], Union[None, int]]]
sslobject_class: Type[SSLObject]
def set_npn_protocols(self, npn_protocols: Iterable[str]) -> None: ...
if sys.version_info >= (3, 7):
def set_servername_callback(self, server_name_callback: Optional[_SrvnmeCbType]) -> None: ...
else:
def set_servername_callback(self, __method: Optional[_SrvnmeCbType]) -> None: ...
def set_servername_callback(self, __method: Optional[_SrvnmeCbType]) -> None: ...
def load_dh_params(self, __path: str) -> None: ...
def set_ecdh_curve(self, __name: str) -> None: ...
if sys.version_info >= (3, 6):
def wrap_socket(
self,
sock: socket.socket,
server_side: bool = ...,
do_handshake_on_connect: bool = ...,
suppress_ragged_eofs: bool = ...,
server_hostname: Optional[str] = ...,
session: Optional[SSLSession] = ...,
) -> SSLSocket: ...
else:
def wrap_socket(
self,
sock: socket.socket,
server_side: bool = ...,
do_handshake_on_connect: bool = ...,
suppress_ragged_eofs: bool = ...,
server_hostname: Optional[str] = ...,
) -> SSLSocket: ...
if sys.version_info >= (3, 6):
def wrap_bio(
self,
incoming: MemoryBIO,
outgoing: MemoryBIO,
server_side: bool = ...,
server_hostname: Optional[str] = ...,
session: Optional[SSLSession] = ...,
) -> SSLObject: ...
elif sys.version_info >= (3, 5):
def wrap_bio(
self, incoming: MemoryBIO, outgoing: MemoryBIO, server_side: bool = ..., server_hostname: Optional[str] = ...
) -> SSLObject: ...
def wrap_socket(
self,
sock: socket.socket,
server_side: bool = ...,
do_handshake_on_connect: bool = ...,
suppress_ragged_eofs: bool = ...,
server_hostname: Optional[str] = ...,
) -> SSLSocket: ...
def session_stats(self) -> Dict[str, int]: ...
if sys.version_info >= (3, 7):
hostname_checks_common_name: bool
maximum_version: TLSVersion
minimum_version: TLSVersion
if sys.version_info >= (3, 5):
class SSLObject:
context: SSLContext
server_side: bool
server_hostname: Optional[str]
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
def getpeercert(self, binary_form: Literal[False] = ...) -> Optional[_PeerCertRetDictType]: ...
@overload
def getpeercert(self, binary_form: Literal[True]) -> Optional[bytes]: ...
@overload
def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
def selected_alpn_protocol(self) -> Optional[str]: ...
def selected_npn_protocol(self) -> Optional[str]: ...
def cipher(self) -> Optional[Tuple[str, str, int]]: ...
def shared_ciphers(self) -> Optional[List[Tuple[str, str, int]]]: ...
def compression(self) -> Optional[str]: ...
def pending(self) -> int: ...
def do_handshake(self) -> None: ...
def unwrap(self) -> None: ...
def version(self) -> Optional[str]: ...
def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ...
if sys.version_info >= (3, 8):
def verify_client_post_handshake(self) -> None: ...
class MemoryBIO:
pending: int
eof: bool
def read(self, __size: int = ...) -> bytes: ...
def write(self, __buf: bytes) -> int: ...
def write_eof(self) -> None: ...
if sys.version_info >= (3, 6):
class SSLSession:
id: bytes
time: int
timeout: int
ticket_lifetime_hint: int
has_ticket: bool
class VerifyFlags(enum.IntFlag):
VERIFY_DEFAULT: int
VERIFY_CRL_CHECK_LEAF: int
VERIFY_CRL_CHECK_CHAIN: int
VERIFY_X509_STRICT: int
VERIFY_X509_TRUSTED_FIRST: int
class VerifyMode(enum.IntEnum):
CERT_NONE: int
CERT_OPTIONAL: int
CERT_REQUIRED: int
# TODO below documented in cpython but not in docs.python.org
# taken from python 3.4
@@ -469,8 +259,7 @@ SSL_ERROR_ZERO_RETURN: int
def get_protocol_name(protocol_code: int) -> str: ...
if sys.version_info < (3, 9):
AF_INET: int
AF_INET: int
PEM_FOOTER: str
PEM_HEADER: str
SOCK_STREAM: int