diff options
author | Guilhem Lettron <guilhem.lettron@optiflows.com> | 2013-12-09 15:44:35 +0100 |
---|---|---|
committer | Guilhem Lettron <guilhem.lettron@optiflows.com> | 2013-12-09 15:44:35 +0100 |
commit | f4e3c04bbfa90e298eb4f93b3410ceb866bfed03 (patch) | |
tree | e12e6f9c439e7acac4702a5de1de919c649f6e7f /sleekxmpp | |
parent | 540d6e9dbb5c4be190f4d114a438f80a9d9cd623 (diff) | |
download | slixmpp-f4e3c04bbfa90e298eb4f93b3410ceb866bfed03.tar.gz slixmpp-f4e3c04bbfa90e298eb4f93b3410ceb866bfed03.tar.bz2 slixmpp-f4e3c04bbfa90e298eb4f93b3410ceb866bfed03.tar.xz slixmpp-f4e3c04bbfa90e298eb4f93b3410ceb866bfed03.zip |
Don't use dnspython for A and AAAA (but keep it for SRV).
dnspython don't perform a full resolv.
For example it don't manage /etc/hosts on linux.
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/xmlstream/resolver.py | 70 |
1 files changed, 18 insertions, 52 deletions
diff --git a/sleekxmpp/xmlstream/resolver.py b/sleekxmpp/xmlstream/resolver.py index 6f26797f..e82bfdb7 100644 --- a/sleekxmpp/xmlstream/resolver.py +++ b/sleekxmpp/xmlstream/resolver.py @@ -131,16 +131,16 @@ def resolve(host, port=None, service=None, proto='tcp', results.append((host, '::1', port)) results.append((host, '127.0.0.1', port)) if use_ipv6: - for address in get_AAAA(host, resolver=resolver): + for address in get_AAAA(host): results.append((host, address, port)) - for address in get_A(host, resolver=resolver): + for address in get_A(host): results.append((host, address, port)) for host, address, port in results: yield host, address, port -def get_A(host, resolver=None): +def get_A(host): """Lookup DNS A records for a given host. If ``resolver`` is not provided, or is ``None``, then resolution will @@ -158,32 +158,15 @@ def get_A(host, resolver=None): # If not using dnspython, attempt lookup using the OS level # getaddrinfo() method. - if resolver is None: - try: - recs = socket.getaddrinfo(host, None, socket.AF_INET, - socket.SOCK_STREAM) - return [rec[4][0] for rec in recs] - except socket.gaierror: - log.debug("DNS: Error retreiving A address info for %s." % host) - return [] - - # Using dnspython: try: - recs = resolver.query(host, dns.rdatatype.A) - return [rec.to_text() for rec in recs] - except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): - log.debug("DNS: No A records for %s" % host) - return [] - except dns.exception.Timeout: - log.debug("DNS: A record resolution timed out for %s" % host) - return [] - except dns.exception.DNSException as e: - log.debug("DNS: Error querying A records for %s" % host) - log.exception(e) + recs = socket.getaddrinfo(host, None, socket.AF_INET, + socket.SOCK_STREAM) + return [rec[4][0] for rec in recs] + except socket.gaierror: + log.debug("DNS: Error retreiving A address info for %s." % host) return [] - -def get_AAAA(host, resolver=None): +def get_AAAA(host): """Lookup DNS AAAA records for a given host. If ``resolver`` is not provided, or is ``None``, then resolution will @@ -201,35 +184,18 @@ def get_AAAA(host, resolver=None): # If not using dnspython, attempt lookup using the OS level # getaddrinfo() method. - if resolver is None: - if not socket.has_ipv6: - log.debug("Unable to query %s for AAAA records: IPv6 is not supported", host) - return [] - try: - recs = socket.getaddrinfo(host, None, socket.AF_INET6, - socket.SOCK_STREAM) - return [rec[4][0] for rec in recs] - except (OSError, socket.gaierror): - log.debug("DNS: Error retreiving AAAA address " + \ - "info for %s." % host) - return [] - - # Using dnspython: - try: - recs = resolver.query(host, dns.rdatatype.AAAA) - return [rec.to_text() for rec in recs] - except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): - log.debug("DNS: No AAAA records for %s" % host) - return [] - except dns.exception.Timeout: - log.debug("DNS: AAAA record resolution timed out for %s" % host) + if not socket.has_ipv6: + log.debug("Unable to query %s for AAAA records: IPv6 is not supported", host) return [] - except dns.exception.DNSException as e: - log.debug("DNS: Error querying AAAA records for %s" % host) - log.exception(e) + try: + recs = socket.getaddrinfo(host, None, socket.AF_INET6, + socket.SOCK_STREAM) + return [rec[4][0] for rec in recs] + except (OSError, socket.gaierror): + log.debug("DNS: Error retreiving AAAA address " + \ + "info for %s." % host) return [] - def get_SRV(host, port, service, proto='tcp', resolver=None): """Perform SRV record resolution for a given host. |