PYTHON-2667 Fix SRV support when running with eventlet (#612)

This commit is contained in:
Shane Harvey 2021-04-28 15:09:56 -07:00 committed by GitHub
parent 14ac9a3fde
commit acfa7b615c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,13 +16,6 @@
try:
from dns import resolver
try:
# dnspython >= 2
from dns.resolver import resolve as _resolve
except ImportError:
# dnspython 1.X
from dns.resolver import query as _resolve
_HAVE_DNSPYTHON = True
except ImportError:
_HAVE_DNSPYTHON = False
@ -39,6 +32,15 @@ def maybe_decode(text):
return text
# PYTHON-2667 Lazily call dns.resolver methods for compatibility with eventlet.
def _resolve(*args, **kwargs):
if hasattr(resolver, 'resolve'):
# dnspython >= 2
return resolver.resolve(*args, **kwargs)
# dnspython 1.X
return resolver.query(*args, **kwargs)
class _SrvResolver(object):
def __init__(self, fqdn, connect_timeout=None):
self.__fqdn = fqdn