Skip to content

Commit

Permalink
Fix cares tests on py2
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 23, 2020
1 parent 401729c commit 12a07de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gevent/resolver/dnspython.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _patch_dns():
def extra_all(mod_name):
return extras.get(mod_name, ())

def after_import_hook(dns): # pylint;disable=redefined-outer-name
def after_import_hook(dns): # pylint:disable=redefined-outer-name
# Runs while still in the original patching scope.
# The dns.rdata:get_rdata_class() function tries to
# dynamically import modules using __import__ and then walk
Expand Down
15 changes: 14 additions & 1 deletion src/gevent/tests/test__socket_dns6.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

from gevent.testing.sysinfo import OSX
from gevent.testing.sysinfo import RESOLVER_DNSPYTHON
from gevent.testing.sysinfo import RESOLVER_ARES
from gevent.testing.sysinfo import PYPY

from gevent.testing.sysinfo import PY2

# We can't control the DNS servers on CI (or in general...)
# for the system. This works best with the google DNS servers
Expand Down Expand Up @@ -45,6 +46,18 @@ def _normalize_result_gethostbyaddr(self, result):
# of the system and ares. They don't match exactly.
return ()

if RESOLVER_ARES and PY2:
def _normalize_result_getnameinfo(self, result):
# Beginning 2020-07-23,
# c-ares returns a scope id on the result:
# ('2001:470:1:18::115%0', 'http')
# The standard library does not (on linux or os x).
# I've only seen '%0', so only remove that
ipaddr, service = result
if ipaddr.endswith('%0'):
ipaddr = ipaddr[:-2]
return (ipaddr, service)

if not OSX and RESOLVER_DNSPYTHON:
# It raises gaierror instead of socket.error,
# which is not great and leads to failures.
Expand Down

0 comments on commit 12a07de

Please sign in to comment.