File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1818import warnings
1919
2020try :
21+ # Eventlet monkey patches dnspython with a copy it bundles.
22+ # We have to import dns.exception to ensure we can catch the
23+ # patched DNSException.
24+ import dns .exception
2125 from dns import rdata , resolver
22- from dns .exception import DNSException
2326 _HAVE_DNSPYTHON = True
2427except ImportError :
2528 _HAVE_DNSPYTHON = False
@@ -267,12 +270,24 @@ def split_hosts(hosts, default_port=DEFAULT_PORT):
267270_BAD_DB_CHARS = re .compile ('[' + re .escape (r'/ "$' ) + ']' )
268271
269272
273+ if PY3 :
274+ def maybe_decode (text ):
275+ if isinstance (text , bytes ):
276+ return text .decode ()
277+ return text
278+ else :
279+ def maybe_decode (text ):
280+ return text
281+
282+
270283def _get_dns_srv_hosts (hostname ):
271284 try :
272285 results = resolver .query ('_mongodb._tcp.' + hostname , 'SRV' )
273- return [(res .target .to_text (omit_final_dot = True ), res .port )
286+ # Some older versions of dnspython return bytes for target.to_text.
287+ return [(maybe_decode (
288+ res .target .to_text (omit_final_dot = True )), res .port )
274289 for res in results ]
275- except DNSException as exc :
290+ except dns . exception . DNSException as exc :
276291 raise ConfigurationError (str (exc ))
277292
278293
Original file line number Diff line number Diff line change @@ -320,7 +320,7 @@ def build_extension(self, ext):
320320if vi [0 ] == 2 :
321321 extras_require = {'tls' : ["ipaddress" ], 'srv' : ["dnspython>=1.8.0,<2.0.0" ]}
322322else :
323- extras_require = {'tls' : [], 'srv' : ["dnspython>=1.15 .0,<2.0.0" ]}
323+ extras_require = {'tls' : [], 'srv' : ["dnspython>=1.13 .0,<2.0.0" ]}
324324if sys .platform == 'win32' :
325325 extras_require ['gssapi' ] = ["winkerberos>=0.5.0" ]
326326 if vi [0 ] == 2 and vi < (2 , 7 , 9 ) or vi [0 ] == 3 and vi < (3 , 4 ):
You can’t perform that action at this time.
0 commit comments