mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
gh-114887 Reject only sockets of type SOCK_STREAM in create_datagram_endpoint() (#114893)
Also improve exception message. Co-authored-by: Donghee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
6b53d5fe04
commit
94ec2b9c9c
@ -1340,9 +1340,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):
|
||||
|
@ -1232,7 +1232,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):
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user