From 11a005894b2908b7ea9a04f0e61e9c692c37a5a0 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Sun, 1 Dec 2019 20:06:59 -0500 Subject: [PATCH 01/10] support new Python3 IPv4Address and IPv6Address Add support for new Python3 IPv4Address and IPv6Address inet types. This is tested and forwards and backwards compatible with different host types. --- Lib/asyncio/base_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index b2d446a51fedb5..3748da6e260207 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -139,6 +139,7 @@ def _ipaddr_info(host, port, family, type, proto, flowinfo=0, scopeid=0): if isinstance(host, bytes): host = host.decode('idna') + host = str(host) if '%' in host: # Linux's inet_pton doesn't accept an IPv6 zone index after host, # like '::1%lo0'. From 3af5c9ef70564631177fe1bdd09486b09fb7c3fc Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Tue, 9 Jun 2020 20:35:44 -0400 Subject: [PATCH 02/10] bpo-35019: Add tests for IPAddress in asyncio --- Lib/test/test_asyncio/test_base_events.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 533d5cc7f50382..a715ef12835e5f 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -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 @@ -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)), @@ -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)) From d84137e81c5ccd79bd1ccdd4d906b78ede50fec3 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Tue, 9 Jun 2020 21:30:17 -0400 Subject: [PATCH 03/10] bpo-35019: Add Doc and ACKS --- Doc/library/asyncio-stream.rst | 6 ++++++ Misc/ACKS | 1 + 2 files changed, 7 insertions(+) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index b76ed379c7f4c8..d038b1b47f4692 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -73,6 +73,9 @@ and work with streams: The *ssl_handshake_timeout* parameter. + .. versionadded:: 3.9 + Added support for IPAddress + .. coroutinefunction:: start_server(client_connected_cb, host=None, \ port=None, \*, loop=None, limit=None, \ family=socket.AF_UNSPEC, \ @@ -106,6 +109,9 @@ and work with streams: The *ssl_handshake_timeout* and *start_serving* parameters. + .. versionadded:: 3.9 + Added support for IPAddress + .. rubric:: Unix Sockets diff --git a/Misc/ACKS b/Misc/ACKS index a505a3d7840369..380ffa7292508e 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -346,6 +346,7 @@ David M. Cooke Jason R. Coombs Garrett Cooper Greg Copeland +Max Coplan 🤘 Ian Cordasco Aldo Cortesi Mircea Cosbuc From a3e6bc220669073bb61da7d3972b5bbf86a13b6a Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:33:28 +0000 Subject: [PATCH 04/10] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst diff --git a/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst b/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst new file mode 100644 index 00000000000000..f976c15275d5ba --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst @@ -0,0 +1 @@ +support IPAddress in asyncio.start_server() \ No newline at end of file From e9d57856f5b6270b1405228aab81e067d3ebe1d1 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 13:06:37 -0400 Subject: [PATCH 05/10] Update Misc/ACKS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémi Lapeyre --- Misc/ACKS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 380ffa7292508e..b3d75f4095cf48 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -346,7 +346,7 @@ David M. Cooke Jason R. Coombs Garrett Cooper Greg Copeland -Max Coplan 🤘 +Max Coplan Ian Cordasco Aldo Cortesi Mircea Cosbuc From d086d954fa090165496b89153cef516ff5403db4 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 13:06:49 -0400 Subject: [PATCH 06/10] Update Doc/library/asyncio-stream.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémi Lapeyre --- Doc/library/asyncio-stream.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index d038b1b47f4692..77ecc3ef3aaf77 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -73,7 +73,7 @@ and work with streams: The *ssl_handshake_timeout* parameter. - .. versionadded:: 3.9 + .. versionadded:: 3.10 Added support for IPAddress .. coroutinefunction:: start_server(client_connected_cb, host=None, \ From be0755c6d7403439f04a7b94487c0d1b07d43ec1 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 13:07:01 -0400 Subject: [PATCH 07/10] Update Doc/library/asyncio-stream.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémi Lapeyre --- Doc/library/asyncio-stream.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index 77ecc3ef3aaf77..89ca4bc4f7d92e 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -109,7 +109,7 @@ and work with streams: The *ssl_handshake_timeout* and *start_serving* parameters. - .. versionadded:: 3.9 + .. versionadded:: 3.10 Added support for IPAddress From ba7c66a56f59cef290685f9f2314cd7d9962f64f Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 13:07:21 -0400 Subject: [PATCH 08/10] Update Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémi Lapeyre --- .../next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst b/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst index f976c15275d5ba..034f9f8d82ff0f 100644 --- a/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst +++ b/Misc/NEWS.d/next/Library/2020-06-10-01-33-27.bpo-35019.dwhOOO.rst @@ -1 +1 @@ -support IPAddress in asyncio.start_server() \ No newline at end of file +Added support for IPAddress in asyncio.start_server() From 87f466f0e7f1c30567adee7337c6034be269e8a4 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 14:01:41 -0400 Subject: [PATCH 09/10] bpo-35019: Fix whitespace --- Lib/test/test_asyncio/test_base_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index a715ef12835e5f..63e85150610dbf 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -110,7 +110,7 @@ def test_ipaddr_info(self): (INET6, STREAM, TCP, '', ('::3', 1, 0, 0)), base_events._ipaddr_info('::3', 1, UNSPEC, STREAM, TCP)) - # IPv6Address + # IPv6Address self.assertEqual( (INET6, STREAM, TCP, '', ('::3', 1, 0, 0)), base_events._ipaddr_info(IPv6Address('::3'), 1, UNSPEC, STREAM, TCP)) From 106afad09c384a44106af2e227fbd019680683fb Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 10 Jun 2020 16:36:17 -0400 Subject: [PATCH 10/10] Document base_events.py --- Lib/asyncio/base_events.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 3748da6e260207..4e6be9f70511f1 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -139,6 +139,8 @@ 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) if '%' in host: # Linux's inet_pton doesn't accept an IPv6 zone index after host,