Package SPF :: Module dnspython
[hide private]
[frames] | no frames]

Source Code for Module SPF.dnspython

 1  import dns.resolver  # http://www.dnspython.org 
 2  import dns.exception 
 3  import spf 
 4   
 5  if not hasattr(dns.rdatatype,'SPF'): 
 6    # patch in type99 support 
 7    dns.rdatatype.SPF = 99 
 8    dns.rdatatype._by_text['SPF'] = dns.rdatatype.SPF 
 9   
10 -def DNSLookup(name,qtype):
11 retVal = [] 12 try: 13 answers = dns.resolver.query(name, qtype) 14 for rdata in answers: 15 if qtype == 'A' or qtype == 'AAAA': 16 retVal.append(((name, qtype), rdata.address)) 17 elif qtype == 'MX': 18 retVal.append(((name, qtype), (rdata.preference, rdata.exchange))) 19 elif qtype == 'PTR': 20 retVal.append(((name, qtype), rdata.target.to_text(True))) 21 elif qtype == 'TXT' or qtype == 'SPF': 22 retVal.append(((name, qtype), rdata.strings)) 23 except dns.resolver.NoAnswer: 24 pass 25 except dns.resolver.NXDOMAIN: 26 pass 27 except dns.exception.DNSException,x: 28 raise spf.TempError,'DNS ' + str(x) 29 return retVal
30 31 spf.DNSLookup = DNSLookup 32