summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-05-20 21:44:44 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2016-05-20 21:44:44 (GMT)
commit010f361dadcbc9f124c7b55b5965b982d60edac8 (patch)
tree40b459cde5dac726da8d1a93c7ea206a79e7a784 /Lib
parent742206d95c38f382bd02858a8c61b6cf18ac0ad0 (diff)
parenteaaaee8c569475614d16e3abf087228673bce9fc (diff)
downloadcpython-010f361dadcbc9f124c7b55b5965b982d60edac8.zip
cpython-010f361dadcbc9f124c7b55b5965b982d60edac8.tar.gz
cpython-010f361dadcbc9f124c7b55b5965b982d60edac8.tar.bz2
Merge 3.5 (asyncio)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/base_events.py5
-rw-r--r--Lib/test/test_asyncio/test_base_events.py22
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 4aac4ac..23dfef4 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -102,6 +102,11 @@ def _ipaddr_info(host, port, family, type, proto):
else:
return None
+ if port in {None, ''}:
+ port = 0
+ elif isinstance(port, (bytes, str)):
+ port = int(port)
+
if hasattr(socket, 'inet_pton'):
if family == socket.AF_UNSPEC:
afs = [socket.AF_INET, socket.AF_INET6]
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index ef93dc0..678ba30 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -120,6 +120,28 @@ class BaseEventTests(test_utils.TestCase):
(INET6, STREAM, TCP, '', ('::3%lo0', 1)),
base_events._ipaddr_info('::3%lo0', 1, INET6, STREAM, TCP))
+ def test_port_parameter_types(self):
+ # Test obscure kinds of arguments for "port".
+ INET = socket.AF_INET
+ STREAM = socket.SOCK_STREAM
+ TCP = socket.IPPROTO_TCP
+
+ self.assertEqual(
+ (INET, STREAM, TCP, '', ('1.2.3.4', 0)),
+ base_events._ipaddr_info('1.2.3.4', None, INET, STREAM, TCP))
+
+ self.assertEqual(
+ (INET, STREAM, TCP, '', ('1.2.3.4', 0)),
+ base_events._ipaddr_info('1.2.3.4', '', INET, STREAM, TCP))
+
+ self.assertEqual(
+ (INET, STREAM, TCP, '', ('1.2.3.4', 1)),
+ base_events._ipaddr_info('1.2.3.4', '1', INET, STREAM, TCP))
+
+ self.assertEqual(
+ (INET, STREAM, TCP, '', ('1.2.3.4', 1)),
+ base_events._ipaddr_info('1.2.3.4', b'1', INET, STREAM, TCP))
+
@patch_socket
def test_ipaddr_info_no_inet_pton(self, m_socket):
del m_socket.inet_pton