summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-09-30 15:18:34 (GMT)
committerGuido van Rossum <guido@python.org>2016-09-30 15:18:34 (GMT)
commit0035be3fee832ebccd8c86576b9c604ca321cefa (patch)
tree4622d6c8636aa54e1aee845cd9bdb394b54e537b /Lib/asyncio/base_events.py
parent61cd726d1abca5601f85d0029466ab9ec3216cc0 (diff)
parente3c65a7a228a5808a7af48a47fdd77e982f95d00 (diff)
downloadcpython-0035be3fee832ebccd8c86576b9c604ca321cefa.zip
cpython-0035be3fee832ebccd8c86576b9c604ca321cefa.tar.gz
cpython-0035be3fee832ebccd8c86576b9c604ca321cefa.tar.bz2
Misc asyncio improvements from upstream (merge 3.5->3.6)
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py28
1 files changed, 10 insertions, 18 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index ac6e8f2..86b4291 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -115,24 +115,16 @@ def _ipaddr_info(host, port, family, type, proto):
if port is None:
port = 0
- 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)
+ elif isinstance(port, bytes) and port == b'':
+ port = 0
+ elif isinstance(port, str) and port == '':
+ port = 0
+ else:
+ # If port's a service name like "http", don't skip getaddrinfo.
+ try:
+ port = int(port)
+ except (TypeError, ValueError):
+ return None
if family == socket.AF_UNSPEC:
afs = [socket.AF_INET, socket.AF_INET6]