[Python-checkins] [3.8] bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457) (#17496)

Andrew Svetlov webhook-mailer at python.org
Sat Dec 7 07:44:25 EST 2019


https://github.com/python/cpython/commit/930cef2770b641f49e69b67840daaa53b65cd0e0
commit: 930cef2770b641f49e69b67840daaa53b65cd0e0
branch: 3.8
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019年12月07日T14:44:20+02:00
summary:
[3.8] bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457) (#17496)
https://bugs.python.org/issue37404
(cherry picked from commit 892f9e0777f262d366d4747a54c33a1c15a49da6)
Co-authored-by: idomic <michael.ido at gmail.com>
files:
A Misc/NEWS.d/next/Build/2019-12-01-21-45-24.bpo-37404.cNsA7S.rst
M Lib/asyncio/selector_events.py
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 00e3244bfb294..e1abf5118619c 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -348,6 +348,8 @@ def remove_writer(self, fd):
 The maximum amount of data to be received at once is specified by
 nbytes.
 """
+ if isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
 if self._debug and sock.gettimeout() != 0:
 raise ValueError("the socket must be non-blocking")
 try:
@@ -386,6 +388,8 @@ def _sock_recv(self, fut, sock, n):
 The received data is written into *buf* (a writable buffer).
 The return value is the number of bytes written.
 """
+ if isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
 if self._debug and sock.gettimeout() != 0:
 raise ValueError("the socket must be non-blocking")
 try:
@@ -425,6 +429,8 @@ def _sock_recv_into(self, fut, sock, buf):
 raised, and there is no way to determine how much data, if any, was
 successfully processed by the receiving end of the connection.
 """
+ if isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
 if self._debug and sock.gettimeout() != 0:
 raise ValueError("the socket must be non-blocking")
 try:
@@ -472,6 +478,8 @@ def _sock_sendall(self, fut, sock, view, pos):
 
 This method is a coroutine.
 """
+ if isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
 if self._debug and sock.gettimeout() != 0:
 raise ValueError("the socket must be non-blocking")
 
@@ -533,6 +541,8 @@ def _sock_connect_cb(self, fut, sock, address):
 object usable to send and receive data on the connection, and address
 is the address bound to the socket on the other end of the connection.
 """
+ if isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
 if self._debug and sock.gettimeout() != 0:
 raise ValueError("the socket must be non-blocking")
 fut = self.create_future()
diff --git a/Misc/NEWS.d/next/Build/2019-12-01-21-45-24.bpo-37404.cNsA7S.rst b/Misc/NEWS.d/next/Build/2019-12-01-21-45-24.bpo-37404.cNsA7S.rst
new file mode 100644
index 0000000000000..067fc9d3f189d
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2019-12-01-21-45-24.bpo-37404.cNsA7S.rst
@@ -0,0 +1,2 @@
+:mod:`asyncio` now raises :exc:`TyperError` when calling incompatible methods
+with an :class:`ssl.SSLSocket` socket. Patch by Ido Michael.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /