support: greendns: always resolve port
Fixes https://bitbucket.org/eventlet/eventlet/issue/152
This commit is contained in:
@@ -252,12 +252,13 @@ def getnameinfo(sockaddr, flags):
|
|||||||
raise socket.gaierror(
|
raise socket.gaierror(
|
||||||
(socket.EAI_NODATA, 'No address associated with hostname'))
|
(socket.EAI_NODATA, 'No address associated with hostname'))
|
||||||
|
|
||||||
if not (flags & socket.NI_NUMERICSERV):
|
if not (flags & socket.NI_NUMERICSERV):
|
||||||
proto = (flags & socket.NI_DGRAM) and 'udp' or 'tcp'
|
proto = (flags & socket.NI_DGRAM) and 'udp' or 'tcp'
|
||||||
port = socket.getservbyport(port, proto)
|
port = socket.getservbyport(port, proto)
|
||||||
|
|
||||||
return (host, port)
|
return (host, port)
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4_addr(host):
|
def is_ipv4_addr(host):
|
||||||
"""is_ipv4_addr returns true if host is a valid IPv4 address in
|
"""is_ipv4_addr returns true if host is a valid IPv4 address in
|
||||||
dotted quad notation.
|
dotted quad notation.
|
||||||
|
13
tests/greendns_test.py
Normal file
13
tests/greendns_test.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
|
|
||||||
|
def test_greendns_getnameinfo_resolve_port():
|
||||||
|
try:
|
||||||
|
from eventlet.support import greendns
|
||||||
|
except ImportError:
|
||||||
|
raise SkipTest('greendns requires package dnspython')
|
||||||
|
|
||||||
|
# https://bitbucket.org/eventlet/eventlet/issue/152
|
||||||
|
_, port1 = greendns.getnameinfo(('127.0.0.1', 80), 0)
|
||||||
|
_, port2 = greendns.getnameinfo(('localhost', 80), 0)
|
||||||
|
assert port1 == port2 == 'http'
|
Reference in New Issue
Block a user