]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-114887 Reject only sockets of type SOCK_STREAM in create_da… (#114979)
authorTravis Howse <tjhowse@gmail.com>
Mon, 5 Feb 2024 04:01:37 +0000 (14:01 +1000)
committerGitHub <noreply@github.com>
Mon, 5 Feb 2024 04:01:37 +0000 (20:01 -0800)
Also improve exception message.

(cherry picked from commit 94ec2b9c9ce898723c3fe61fbc64d6c8f4f68700)

Co-authored-by: Donghee Na <donghee.na92@gmail.com>
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_base_events.py
Misc/NEWS.d/next/Core and Builtins/2024-02-03-04-07-18.gh-issue-114887.uLSFmN.rst [new file with mode: 0644]

index c5dfc15729a734607a01a69392f99ff4fb57fd7e..5fa28cae9c31caaff35cc90542e95124e351dd8d 100644 (file)
@@ -1281,9 +1281,9 @@ class BaseEventLoop(events.AbstractEventLoop):
                                        allow_broadcast=None, sock=None):
         """Create datagram connection."""
         if sock is not None:
-            if sock.type != socket.SOCK_DGRAM:
+            if sock.type == socket.SOCK_STREAM:
                 raise ValueError(
-                    f'A UDP Socket was expected, got {sock!r}')
+                    f'A datagram socket was expected, got {sock!r}')
             if (local_addr or remote_addr or
                     family or proto or flags or
                     reuse_port or allow_broadcast):
index f3f83ad318c954cf9a60fc0cd0119995c7057a43..e1fc7e63632331a4d7d13a55e79edc11d723ac91 100644 (file)
@@ -1191,7 +1191,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
         with sock:
             coro = self.loop.create_datagram_endpoint(MyProto, sock=sock)
             with self.assertRaisesRegex(ValueError,
-                                        'A UDP Socket was expected'):
+                                        'A datagram socket was expected'):
                 self.loop.run_until_complete(coro)
 
     def test_create_connection_no_host_port_sock(self):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-02-03-04-07-18.gh-issue-114887.uLSFmN.rst b/Misc/NEWS.d/next/Core and Builtins/2024-02-03-04-07-18.gh-issue-114887.uLSFmN.rst
new file mode 100644 (file)
index 0000000..b4d8cf4
--- /dev/null
@@ -0,0 +1,2 @@
+Changed socket type validation in :meth:`~asyncio.loop.create_datagram_endpoint` to accept all non-stream sockets.
+This fixes a regression in compatibility with raw sockets.