]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH...
authoridomic <michael.ido@gmail.com>
Sat, 7 Dec 2019 11:52:36 +0000 (06:52 -0500)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 7 Dec 2019 11:52:35 +0000 (03:52 -0800)
https://bugs.python.org/issue37404

Lib/asyncio/selector_events.py
Misc/NEWS.d/next/Build/2019-12-01-21-45-24.bpo-37404.cNsA7S.rst [new file with mode: 0644]

index 00e3244bfb294cc618d391ace9966931f9a5b88d..e1abf5118619cce607c18108770c96f3353ddb35 100644 (file)
@@ -348,6 +348,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
         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 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
         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 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
         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 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
 
         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 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
         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 (file)
index 0000000..067fc9d
--- /dev/null
@@ -0,0 +1,2 @@
+:mod:`asyncio` now raises :exc:`TyperError` when calling incompatible methods
+with an :class:`ssl.SSLSocket` socket.  Patch by Ido Michael.