summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-25 16:18:26 -0700
committerLance Stout <lancestout@gmail.com>2011-08-25 16:18:26 -0700
commitfe6bc31c604f86d8e85a7532f983850bb281922e (patch)
treebfa2820f0300c6cc2a467cd9ca147f9964e8605c /sleekxmpp/xmlstream
parent2162d6042e7eef953a957c0bcf81e65a66a963d4 (diff)
downloadslixmpp-fe6bc31c604f86d8e85a7532f983850bb281922e.tar.gz
slixmpp-fe6bc31c604f86d8e85a7532f983850bb281922e.tar.bz2
slixmpp-fe6bc31c604f86d8e85a7532f983850bb281922e.tar.xz
slixmpp-fe6bc31c604f86d8e85a7532f983850bb281922e.zip
Added XMLStream.configure_dns.
This can be overridden to do custom configuration for the DNS resolver, or any other DNS related tasks such as calling the system's res_init().
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index a079cce3..0f01afd3 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -561,6 +561,23 @@ class XMLStream(object):
"""
self.socket.settimeout(None)
+ def configure_dns(self, resolver, domain=None, port=None):
+ """
+ Configure and set options for a dns.resolver.Resolver
+ instance, and other DNS related tasks. For example, you
+ can also check Socket.getaddrinfo to see if you need to
+ call out to libresolv.so.2 to run res_init().
+
+ Meant to be overridden.
+
+ Arguments:
+ resolver -- A dns.resolver.Resolver instance, or None
+ if dnspython is not installed.
+ domain -- The initial domain under consideration.
+ port -- The initial port under consideration.
+ """
+ pass
+
def start_tls(self):
"""
Perform handshakes for TLS.
@@ -698,8 +715,11 @@ class XMLStream(object):
if port is None:
port = self.default_port
if DNSPYTHON:
+ resolver = dns.resolver.get_default_resolver()
+ self.configure_dns(resolver, domain=domain, port=port)
+
try:
- answers = dns.resolver.query(domain, dns.rdatatype.A)
+ answers = resolver.query(domain, dns.rdatatype.A)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
log.warning("No A records for %s" % domain)
return [((domain, port), 0, 0)]
@@ -712,6 +732,7 @@ class XMLStream(object):
else:
log.warning("dnspython is not installed -- " + \
"relying on OS A record resolution")
+ self.configure_dns(None, domain=domain, port=port)
return [((domain, port), 0, 0)]
def pick_dns_answer(self, domain, port=None):