Skip to content

Commit a85066d

Browse files
bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457)
https://bugs.python.org/issue37404 (cherry picked from commit 892f9e0) Co-authored-by: idomic <michael.ido@gmail.com>
1 parent 8ce85a3 commit a85066d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: Lib/asyncio/selector_events.py

+10
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ async def sock_recv(self, sock, n):
345345
The maximum amount of data to be received at once is specified by
346346
nbytes.
347347
"""
348+
if isinstance(sock, ssl.SSLSocket):
349+
raise TypeError("Socket cannot be of type SSLSocket")
348350
if self._debug and sock.gettimeout() != 0:
349351
raise ValueError("the socket must be non-blocking")
350352
fut = self.create_future()
@@ -378,6 +380,8 @@ async def sock_recv_into(self, sock, buf):
378380
The received data is written into *buf* (a writable buffer).
379381
The return value is the number of bytes written.
380382
"""
383+
if isinstance(sock, ssl.SSLSocket):
384+
raise TypeError("Socket cannot be of type SSLSocket")
381385
if self._debug and sock.gettimeout() != 0:
382386
raise ValueError("the socket must be non-blocking")
383387
fut = self.create_future()
@@ -415,6 +419,8 @@ async def sock_sendall(self, sock, data):
415419
raised, and there is no way to determine how much data, if any, was
416420
successfully processed by the receiving end of the connection.
417421
"""
422+
if isinstance(sock, ssl.SSLSocket):
423+
raise TypeError("Socket cannot be of type SSLSocket")
418424
if self._debug and sock.gettimeout() != 0:
419425
raise ValueError("the socket must be non-blocking")
420426
fut = self.create_future()
@@ -451,6 +457,8 @@ async def sock_connect(self, sock, address):
451457
452458
This method is a coroutine.
453459
"""
460+
if isinstance(sock, ssl.SSLSocket):
461+
raise TypeError("Socket cannot be of type SSLSocket")
454462
if self._debug and sock.gettimeout() != 0:
455463
raise ValueError("the socket must be non-blocking")
456464

@@ -508,6 +516,8 @@ async def sock_accept(self, sock):
508516
object usable to send and receive data on the connection, and address
509517
is the address bound to the socket on the other end of the connection.
510518
"""
519+
if isinstance(sock, ssl.SSLSocket):
520+
raise TypeError("Socket cannot be of type SSLSocket")
511521
if self._debug and sock.gettimeout() != 0:
512522
raise ValueError("the socket must be non-blocking")
513523
fut = self.create_future()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`asyncio` now raises :exc:`TyperError` when calling incompatible methods
2+
with an :class:`ssl.SSLSocket` socket. Patch by Ido Michael.

0 commit comments

Comments
 (0)