mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
PEP8 edits
This commit is contained in:
parent
a714fa82b2
commit
3e51126e18
3 changed files with 17 additions and 7 deletions
|
@ -143,7 +143,7 @@ class ClientXMPP(BaseXMPP):
|
||||||
def get_dns_records(self, domain, port=None):
|
def get_dns_records(self, domain, port=None):
|
||||||
"""
|
"""
|
||||||
Get the DNS records for a domain.
|
Get the DNS records for a domain.
|
||||||
Overridden XMLStream.get_dns_records to use SRV.
|
Overriddes XMLStream.get_dns_records to use SRV.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
domain -- The domain in question.
|
domain -- The domain in question.
|
||||||
|
@ -153,16 +153,22 @@ class ClientXMPP(BaseXMPP):
|
||||||
port = self.default_port
|
port = self.default_port
|
||||||
if DNSPYTHON:
|
if DNSPYTHON:
|
||||||
try:
|
try:
|
||||||
answers = [((answer.target.to_text()[:-1], answer.port), answer.priority, answer.weight) for answer in dns.resolver.query("_xmpp-client._tcp.%s" % domain, dns.rdatatype.SRV)]
|
record = "_xmpp-client._tcp.%s" % domain
|
||||||
|
answers = []
|
||||||
|
for answer in dns.resolver.query(record, dns.rdatatype.SRV):
|
||||||
|
address = (answer.target.to_text()[:-1], answer.port)
|
||||||
|
answers.append((address, answer.priority, answer.weight))
|
||||||
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
log.warning("No SRV records for %s" % domain)
|
log.warning("No SRV records for %s" % domain)
|
||||||
answers = super(ClientXMPP, self).get_dns_records(domain, port)
|
answers = super(ClientXMPP, self).get_dns_records(domain, port)
|
||||||
except dns.exception.Timeout:
|
except dns.exception.Timeout:
|
||||||
log.warning("DNS resolution timed out for SRV record of %s" % domain)
|
log.warning("DNS resolution timed out " + \
|
||||||
|
"for SRV record of %s" % domain)
|
||||||
answers = super(ClientXMPP, self).get_dns_records(domain, port)
|
answers = super(ClientXMPP, self).get_dns_records(domain, port)
|
||||||
return answers
|
return answers
|
||||||
else:
|
else:
|
||||||
log.warning("dnspython is not installed -- relying on OS A record resolution")
|
log.warning("dnspython is not installed -- " + \
|
||||||
|
"relying on OS A record resolution")
|
||||||
return [((domain, port), 0, 0)]
|
return [((domain, port), 0, 0)]
|
||||||
|
|
||||||
def register_feature(self, name, handler, restart=False, order=5000):
|
def register_feature(self, name, handler, restart=False, order=5000):
|
||||||
|
|
|
@ -64,6 +64,7 @@ class IqTimeout(Exception):
|
||||||
def __init__(self, iq):
|
def __init__(self, iq):
|
||||||
self.iq = iq
|
self.iq = iq
|
||||||
|
|
||||||
|
|
||||||
class IqError(Exception):
|
class IqError(Exception):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -338,7 +338,8 @@ class XMLStream(object):
|
||||||
def _connect(self):
|
def _connect(self):
|
||||||
self.stop.clear()
|
self.stop.clear()
|
||||||
if self.default_domain:
|
if self.default_domain:
|
||||||
self.address = self.pick_dns_answer(self.default_domain, self.address[1])
|
self.address = self.pick_dns_answer(self.default_domain,
|
||||||
|
self.address[1])
|
||||||
self.socket = self.socket_class(Socket.AF_INET, Socket.SOCK_STREAM)
|
self.socket = self.socket_class(Socket.AF_INET, Socket.SOCK_STREAM)
|
||||||
self.socket.settimeout(None)
|
self.socket.settimeout(None)
|
||||||
|
|
||||||
|
@ -672,11 +673,13 @@ class XMLStream(object):
|
||||||
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
log.warning("No A records for %s" % domain)
|
log.warning("No A records for %s" % domain)
|
||||||
except dns.exception.Timeout:
|
except dns.exception.Timeout:
|
||||||
log.warning("DNS resolution timed out for A record of %s" % domain)
|
log.warning("DNS resolution timed out " + \
|
||||||
|
"for A record of %s" % domain)
|
||||||
answers = [((answer.address, port), 0, 0) for answer in answers]
|
answers = [((answer.address, port), 0, 0) for answer in answers]
|
||||||
return answers
|
return answers
|
||||||
else:
|
else:
|
||||||
log.warning("dnspython is not installed -- relying on OS A record resolution")
|
log.warning("dnspython is not installed -- " + \
|
||||||
|
"relying on OS A record resolution")
|
||||||
return [((domain, port), 0, 0)]
|
return [((domain, port), 0, 0)]
|
||||||
|
|
||||||
def pick_dns_answer(self, domain, port=None):
|
def pick_dns_answer(self, domain, port=None):
|
||||||
|
|
Loading…
Reference in a new issue