From 9dbf246f0bfcac2c4ce538431ee629f126c86447 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 8 Nov 2010 09:14:17 +0800 Subject: [PATCH] Doesn't fail if host has NO SRV record Just catch an other exception type coming from the dns resolver that could be raised with hosts like "anon.example.com" which just don't have any SRV record. --- sleekxmpp/basexmpp.py | 9 --------- sleekxmpp/clientxmpp.py | 2 +- sleekxmpp/componentxmpp.py | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 77191e77..cd7d2510 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -28,15 +28,6 @@ from sleekxmpp.xmlstream.handler import * log = logging.getLogger(__name__) - -# Flag indicating if DNS SRV records are available for use. -SRV_SUPPORT = True -try: - import dns.resolver -except: - SRV_SUPPORT = False - - # In order to make sure that Unicode is handled properly # in Python 2.x, reset the default encoding. if sys.version_info < (3, 0): diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py index a88c5ccb..1c600812 100644 --- a/sleekxmpp/clientxmpp.py +++ b/sleekxmpp/clientxmpp.py @@ -164,7 +164,7 @@ class ClientXMPP(BaseXMPP): try: xmpp_srv = "_xmpp-client._tcp.%s" % self.server answers = dns.resolver.query(xmpp_srv, dns.rdatatype.SRV) - except dns.resolver.NXDOMAIN: + except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): log.debug("No appropriate SRV record found." + \ " Using JID server name.") else: diff --git a/sleekxmpp/componentxmpp.py b/sleekxmpp/componentxmpp.py index 8b0b6cc0..ae58c5f2 100644 --- a/sleekxmpp/componentxmpp.py +++ b/sleekxmpp/componentxmpp.py @@ -15,7 +15,7 @@ import hashlib from sleekxmpp import plugins from sleekxmpp import stanza -from sleekxmpp.basexmpp import BaseXMPP, SRV_SUPPORT +from sleekxmpp.basexmpp import BaseXMPP from sleekxmpp.xmlstream import XMLStream, RestartStream from sleekxmpp.xmlstream import StanzaBase, ET from sleekxmpp.xmlstream.matcher import *