summaryrefslogtreecommitdiff
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-06-02 16:51:27 -0400
committerYury Selivanov <yselivanov@sprymix.com>2016-06-02 16:51:27 -0400
commit1f56e5f6afa137300d655a40e00675195e0248fe (patch)
tree21dc853305640b3332f51e90a169a8d7257102a0 /Lib/asyncio/base_events.py
parent642afb3d3dcb5bcd359047d396343a1b3ca8370b (diff)
parenta714616d36131860f4f3f18bc2cfaf9a578db053 (diff)
downloadcpython-git-1f56e5f6afa137300d655a40e00675195e0248fe.tar.gz
Merge 3.5 (asyncio)
Diffstat (limited to 'Lib/asyncio/base_events.py')
-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: