diff options
| author | Yury Selivanov <yselivanov@sprymix.com> | 2016-06-02 20:51:07 (GMT) |
|---|---|---|
| committer | Yury Selivanov <yselivanov@sprymix.com> | 2016-06-02 20:51:07 (GMT) |
| commit | a714616d36131860f4f3f18bc2cfaf9a578db053 (patch) | |
| tree | bb7461f019d61925f098861476baf4710d09e08f /Lib/asyncio | |
| parent | a8f895f051588cc5186650f13118b0149ae7e3d5 (diff) | |
| download | cpython-a714616d36131860f4f3f18bc2cfaf9a578db053.zip cpython-a714616d36131860f4f3f18bc2cfaf9a578db053.tar.gz cpython-a714616d36131860f4f3f18bc2cfaf9a578db053.tar.bz2 | |
asyncio: Fix getaddrinfo to accept service names (for port)
Patch by A. Jesse Jiryu Davis
Diffstat (limited to 'Lib/asyncio')
| -rw-r--r-- | Lib/asyncio/base_events.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index e5feb99..2b2c185 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: |
