Many small bugs catched by the extensive tests

master
Stephane Bortzmeyer 3 years ago
parent b804f5dd39
commit b6cdf22be6
  1. 21
      DNSLG/Formatter.py
  2. 10
      DNSLG/__init__.py

@ -21,7 +21,7 @@ from . import Answer
def to_hexstring(str):
result = ""
for char in str:
result += ("%x" % ord(char))
result += ("%x" % char)
return result.upper()
def keylength(alg, key):
@ -96,7 +96,7 @@ class TextFormatter(Formatter):
self.output += "Mail exchanger: %s (preference %i)\n" % \
(rdata.exchange, rdata.preference)
elif rdata.rdtype == dns.rdatatype.TXT:
self.output += "Text: %s\n" % " ".join(rdata.strings)
self.output += "Text: %s\n" % (b" ".join(rdata.strings)).decode()
elif rdata.rdtype == dns.rdatatype.SPF:
self.output += "SPF policy: %s\n" % " ".join(rdata.strings)
elif rdata.rdtype == dns.rdatatype.SOA:
@ -198,7 +198,7 @@ class ZoneFormatter(Formatter):
for rdata in rrset:
# TODO: do not hardwire the class
if rdata.rdtype != dns.rdatatype.RRSIG:
self.output += "%s\tIN\t" % answer.qname.decode() # TODO: do not repeat the name if there is a RRset
self.output += "%s\tIN\t" % answer.qname # TODO: do not repeat the name if there is a RRset
# TODO: it could use some refactoring: most (but _not all_) of types
# use the same code.
if rdata.rdtype == dns.rdatatype.A:
@ -310,7 +310,7 @@ class JsonFormatter(Formatter):
'MailExchanger': str(rdata.exchange),
'Preference': rdata.preference})
elif rdata.rdtype == dns.rdatatype.TXT:
self.object['AnswerSection'].append({'Type': 'TXT', 'Text': " ".join(rdata.strings)})
self.object['AnswerSection'].append({'Type': 'TXT', 'Text': (b" ".join(rdata.strings)).decode()})
elif rdata.rdtype == dns.rdatatype.SPF:
self.object['AnswerSection'].append({'Type': 'SPF', 'Text': " ".join(rdata.strings)})
elif rdata.rdtype == dns.rdatatype.SOA:
@ -354,11 +354,11 @@ class JsonFormatter(Formatter):
'Fingerprint': to_hexstring(rdata.fingerprint)})
elif rdata.rdtype == dns.rdatatype.NAPTR:
self.object['AnswerSection'].append({'Type': 'NAPTR',
'Flags': rdata.flags,
'Services': rdata.service,
'Flags': str(rdata.flags),
'Services': str(rdata.service),
'Order': rdata.order,
'Preference': rdata.preference,
'Regexp': rdata.regexp,
'Preference': str(rdata.preference),
'Regexp': str(rdata.regexp),
'Replacement': str(rdata.replacement)})
elif rdata.rdtype == dns.rdatatype.SRV:
self.object['AnswerSection'].append({'Type': 'SRV', 'Server': str(rdata.target),
@ -488,6 +488,7 @@ class XmlFormatter(Formatter):
self.txt_template = simpleTAL.compileXMLTemplate (txt_xml_template)
self.spf_template = simpleTAL.compileXMLTemplate (spf_xml_template)
self.loc_template = simpleTAL.compileXMLTemplate (loc_xml_template)
self.uri_template = simpleTAL.compileXMLTemplate (uri_xml_template)
self.ns_template = simpleTAL.compileXMLTemplate (ns_xml_template)
self.ptr_template = simpleTAL.compileXMLTemplate (ptr_xml_template)
self.cname_template = simpleTAL.compileXMLTemplate (cname_xml_template)
@ -635,7 +636,7 @@ class XmlFormatter(Formatter):
# Yes, some people add Unicode in TXT records,
# see mailclub.tel for instance. We assume
# UTF-8
text = str(" ".join(rdata.strings), "UTF-8")
text = str((b" ".join(rdata.strings)).decode())
icontext.addGlobal ("text", text)
self.txt_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
@ -666,7 +667,7 @@ class XmlFormatter(Formatter):
icontext.addGlobal ("target", rdata.target)
icontext.addGlobal ("weight", rdata.weight)
icontext.addGlobal ("priority", rdata.priority)
self.loc_template.expand (icontext, iresult,
self.uri_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.NS:

@ -242,10 +242,14 @@ Disallow: /
send_response(start_response, '403 Local domain is private',
output, plaintype)
return [output.encode()]
punycode_domain = domain.encode("idna").decode()
if punycode_domain != domain:
qdomain = punycode_domain
if domain != '.':
punycode_domain = domain.encode("idna").decode()
if punycode_domain != domain:
qdomain = punycode_domain
else:
qdomain = domain
else:
punycode_domain = domain
qdomain = domain
self.logger.info("Domain is %s, punycode is %s, qdomain is %s" % (domain, punycode_domain, qdomain))
try:

Loading…
Cancel
Save