summaryrefslogtreecommitdiff
path: root/Lib/asyncio
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 41dd681ef4..b2a412c032 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -102,10 +102,26 @@ def _ipaddr_info(host, port, family, type, proto):
else:
return None
- if port in {None, '', b''}:
+ if port is None:
port = 0
- elif isinstance(port, (bytes, str)):
- port = int(port)
+ elif isinstance(port, bytes):
+ if port == b'':
+ port = 0
+ else:
+ try:
+ port = int(port)
+ except ValueError:
+ # Might be a service name like b"http".
+ port = socket.getservbyname(port.decode('ascii'))
+ elif isinstance(port, str):
+ if port == '':
+ port = 0
+ else:
+ try:
+ port = int(port)
+ except ValueError:
+ # Might be a service name like "http".
+ port = socket.getservbyname(port)
if hasattr(socket, 'inet_pton'):
if family == socket.AF_UNSPEC: