Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/asyncio-stream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ and work with streams:

The *ssl_handshake_timeout* parameter.

.. versionadded:: 3.10
Added support for IPAddress

.. coroutinefunction:: start_server(client_connected_cb, host=None, \
port=None, \*, loop=None, limit=None, \
family=socket.AF_UNSPEC, \
Expand Down Expand Up @@ -106,6 +109,9 @@ and work with streams:

The *ssl_handshake_timeout* and *start_serving* parameters.

.. versionadded:: 3.10
Added support for IPAddress


.. rubric:: Unix Sockets

Expand Down
3 changes: 3 additions & 0 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def _ipaddr_info(host, port, family, type, proto, flowinfo=0, scopeid=0):

if isinstance(host, bytes):
host = host.decode('idna')
# Even though we're calling str() on host (so we'll convert arbitrary objects to str),
# we're restricting it to a valid IP address later when calling socket.inet_pton().
host = str(host)
Comment thread
vegerot marked this conversation as resolved.
if '%' in host:
# Linux's inet_pton doesn't accept an IPv6 zone index after host,
# like '::1%lo0'.
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from test import support
from test.support.script_helper import assert_python_ok
from test.support import socket_helper
from ipaddress import IPv4Address, IPv6Address


MOCK_ANY = mock.ANY
Expand Down Expand Up @@ -77,6 +78,11 @@ def test_ipaddr_info(self):
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, DGRAM, UDP))

# IPv4Address
self.assertEqual(
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info(IPv4Address('1.2.3.4'), 1, UNSPEC, DGRAM, UDP))

# Socket type STREAM implies TCP protocol.
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
Expand Down Expand Up @@ -104,6 +110,11 @@ def test_ipaddr_info(self):
(INET6, STREAM, TCP, '', ('::3', 1, 0, 0)),
base_events._ipaddr_info('::3', 1, UNSPEC, STREAM, TCP))

# IPv6Address
self.assertEqual(
(INET6, STREAM, TCP, '', ('::3', 1, 0, 0)),
base_events._ipaddr_info(IPv6Address('::3'), 1, UNSPEC, STREAM, TCP))

# IPv6 address with family IPv4.
self.assertIsNone(
base_events._ipaddr_info('::3', 1, INET, STREAM, TCP))
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ David M. Cooke
Jason R. Coombs
Garrett Cooper
Greg Copeland
Max Coplan
Ian Cordasco
Aldo Cortesi
Mircea Cosbuc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for IPAddress in asyncio.start_server()