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:
Travis Howse 2024-02-04 03:14:02 +10:00 committed by GitHub
parent 6b53d5fe04
commit 94ec2b9c9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View file

@ -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):