revert last srv commit so svn is usable

This commit is contained in:
Nikos Kouremenos 2005-09-04 22:22:30 +00:00
parent 310baa5234
commit 3200801bc7
1 changed files with 8 additions and 16 deletions

View File

@ -33,13 +33,9 @@ from client import PlugIn
from protocol import *
try:
import DNS, random
DNS.ParseResolvConf()
HAVE_DNS = True
import dns.resolver
except:
HAVE_DNS = False
self.DEBUG("Warning: cannot perform SRV queries because 'dns' module is unavailable", 'warn')
pass
DATA_RECEIVED='DATA RECEIVED'
DATA_SENT='DATA SENT'
@ -64,23 +60,19 @@ class TCPsocket(PlugIn):
self._exported_methods=[self.send,self.disconnect]
# SRV resolver
if HAVE_DNS : # if dnspython is available support SRV
if 'dns' in globals(): # if dnspython is available support SRV
host, port = server
possible_queries = ['_xmpp-client._tcp.' + host]
dnsrequest = DNS.Request()
for query in possible_queries:
try:
response = dnsrequest.req(query, qtype='SRV')
answers = [x for x in response.answers]
answers = [x for x in dns.resolver.query(query, 'SRV')]
if answers:
# extract the data from a random SRV RR
rr = random.choice(answers)
_, _, port, host = rr['data']
port = int(port)
host = str (answers[0].target)
port = int (answers[0].port)
break
except DNS.DNSError, err :
self.DEBUG("An error occurred querying SRV record for %s" % query, 'warn')
except:
pass
server = (host, port)
# end of SRV resolver