Skip to content

Commit 892f9e0

Browse files
idomicmiss-islington
authored andcommitted
bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (pythonGH-16457)
https://bugs.python.org/issue37404
1 parent 969ae7a commit 892f9e0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Lib/asyncio/selector_events.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ async def sock_recv(self, sock, n):
348348
The maximum amount of data to be received at once is specified by
349349
nbytes.
350350
"""
351+
if isinstance(sock, ssl.SSLSocket):
352+
raise TypeError("Socket cannot be of type SSLSocket")
351353
if self._debug and sock.gettimeout() != 0:
352354
raise ValueError("the socket must be non-blocking")
353355
try:
@@ -386,6 +388,8 @@ async def sock_recv_into(self, sock, buf):
386388
The received data is written into *buf* (a writable buffer).
387389
The return value is the number of bytes written.
388390
"""
391+
if isinstance(sock, ssl.SSLSocket):
392+
raise TypeError("Socket cannot be of type SSLSocket")
389393
if self._debug and sock.gettimeout() != 0:
390394
raise ValueError("the socket must be non-blocking")
391395
try:
@@ -425,6 +429,8 @@ async def sock_sendall(self, sock, data):
425429
raised, and there is no way to determine how much data, if any, was
426430
successfully processed by the receiving end of the connection.
427431
"""
432+
if isinstance(sock, ssl.SSLSocket):
433+
raise TypeError("Socket cannot be of type SSLSocket")
428434
if self._debug and sock.gettimeout() != 0:
429435
raise ValueError("the socket must be non-blocking")
430436
try:
@@ -472,6 +478,8 @@ async def sock_connect(self, sock, address):
472478
473479
This method is a coroutine.
474480
"""
481+
if isinstance(sock, ssl.SSLSocket):
482+
raise TypeError("Socket cannot be of type SSLSocket")
475483
if self._debug and sock.gettimeout() != 0:
476484
raise ValueError("the socket must be non-blocking")
477485

@@ -533,6 +541,8 @@ async def sock_accept(self, sock):
533541
object usable to send and receive data on the connection, and address
534542
is the address bound to the socket on the other end of the connection.
535543
"""
544+
if isinstance(sock, ssl.SSLSocket):
545+
raise TypeError("Socket cannot be of type SSLSocket")
536546
if self._debug and sock.gettimeout() != 0:
537547
raise ValueError("the socket must be non-blocking")
538548
fut = self.create_future()
Lines changed: 2 additions & 0 deletions
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)