mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
[3.9] Raise TypeError if SSLSocket is passed to asyncio transport-based methods (GH-31442) (GH-31444)
(cherry picked from commit 1f9d4c93af
)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
This commit is contained in:
parent
a6116a980c
commit
64705e6a94
3 changed files with 22 additions and 10 deletions
|
@ -202,6 +202,11 @@ else:
|
|||
pass
|
||||
|
||||
|
||||
def _check_ssl_socket(sock):
|
||||
if ssl is not None and isinstance(sock, ssl.SSLSocket):
|
||||
raise TypeError("Socket cannot be of type SSLSocket")
|
||||
|
||||
|
||||
class _SendfileFallbackProtocol(protocols.Protocol):
|
||||
def __init__(self, transp):
|
||||
if not isinstance(transp, transports._FlowControlMixin):
|
||||
|
@ -864,6 +869,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
*, fallback=True):
|
||||
if self._debug and sock.gettimeout() != 0:
|
||||
raise ValueError("the socket must be non-blocking")
|
||||
_check_ssl_socket(sock)
|
||||
self._check_sendfile_params(sock, file, offset, count)
|
||||
try:
|
||||
return await self._sock_sendfile_native(sock, file,
|
||||
|
@ -1005,6 +1011,9 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
raise ValueError(
|
||||
'ssl_handshake_timeout is only meaningful with ssl')
|
||||
|
||||
if sock is not None:
|
||||
_check_ssl_socket(sock)
|
||||
|
||||
if happy_eyeballs_delay is not None and interleave is None:
|
||||
# If using happy eyeballs, default to interleave addresses by family
|
||||
interleave = 1
|
||||
|
@ -1438,6 +1447,9 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
raise ValueError(
|
||||
'ssl_handshake_timeout is only meaningful with ssl')
|
||||
|
||||
if sock is not None:
|
||||
_check_ssl_socket(sock)
|
||||
|
||||
if host is not None or port is not None:
|
||||
if sock is not None:
|
||||
raise ValueError(
|
||||
|
@ -1540,6 +1552,9 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
raise ValueError(
|
||||
'ssl_handshake_timeout is only meaningful with ssl')
|
||||
|
||||
if sock is not None:
|
||||
_check_ssl_socket(sock)
|
||||
|
||||
transport, protocol = await self._create_connection_transport(
|
||||
sock, protocol_factory, ssl, '', server_side=True,
|
||||
ssl_handshake_timeout=ssl_handshake_timeout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue