Browse Source

* Always display latitude before longtitude

* Display altitude in meters. Closes #51
master
Stephane Bortzmeyer 2 years ago
parent
commit
e2fef64a18
  1. 24
      DNSLG/Formatter.py
  2. 10
      test_service.py

24
DNSLG/Formatter.py

@ -121,10 +121,10 @@ class TextFormatter(Formatter):
elif rdata.rdtype == dns.rdatatype.NSEC or rdata.rdtype == dns.rdatatype.NSEC3:
pass # Should we show NSEC*?
elif rdata.rdtype == dns.rdatatype.LOC:
self.output += "Location: longitude %i degrees %i' %i\" latitude %i degrees %i' %i\" altitude %f\n" % \
(rdata.longitude[0], rdata.longitude[1], rdata.longitude[2],
rdata.latitude[0], rdata.latitude[1], rdata.latitude[2],
rdata.altitude)
self.output += "Location: latitude %i degrees %i' %i\" longitude %i degrees %i' %i\" altitude %f meters\n" % \
(rdata.latitude[0], rdata.latitude[1], rdata.latitude[2],
rdata.longitude[0], rdata.longitude[1], rdata.longitude[2],
float(rdata.altitude)/100)
elif rdata.rdtype == dns.rdatatype.URI:
self.output += "URI: %s\n" % (rdata.target) # TODO display priority and weight?
elif rdata.rdtype == dns.rdatatype.SRV:
@ -312,9 +312,9 @@ class JsonFormatter(Formatter):
self.object['AnswerSection'].append({'Type': 'AAAA', 'Address': rdata.address})
elif rdata.rdtype == dns.rdatatype.LOC:
self.object['AnswerSection'].append({'Type': 'LOC',
'Longitude': '%f' % rdata.float_longitude,
'Latitude': '%f' % rdata.float_latitude,
'Altitude': '%f' % rdata.altitude})
'Longitude': '%f' % rdata.float_longitude,
'Altitude': '%f' % (float(rdata.altitude)/100)})
elif rdata.rdtype == dns.rdatatype.URI:
self.object['AnswerSection'].append({'Type': 'URI',
'Target': '%s' % rdata.target,
@ -457,7 +457,7 @@ spf_xml_template = """
<SPF tal:attributes="rdata text"/>
"""
loc_xml_template = """
<LOC tal:attributes="longitude longitude; latitude latitude; altitude altitude"/>
<LOC tal:attributes="latitude latitude; longitude longitude; altitude altitude"/>
"""
uri_xml_template = """
<URI tal:attributes="target target; priority priority; weight weight"/>
@ -678,9 +678,9 @@ class XmlFormatter(Formatter):
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.LOC:
icontext.addGlobal ("longitude", rdata.float_longitude)
icontext.addGlobal ("latitude", rdata.float_latitude)
icontext.addGlobal ("altitude", rdata.altitude)
icontext.addGlobal ("longitude", rdata.float_longitude)
icontext.addGlobal ("altitude", float(rdata.altitude)/100)
self.loc_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
@ -830,7 +830,7 @@ naptr_html_template = """
"""
# TODO: link to Open Street Map
loc_html_template = """
<span>Location: <span tal:replace="longitude"/> / <span tal:replace="latitude"/> (altitude <span tal:replace="altitude"/>)</span>
<span>Location: Latitude <span tal:replace="latitude"/> degrees / Longitude <span tal:replace="longitude"/> degrees (altitude <span tal:replace="altitude"/> m)</span>
"""
uri_html_template = """
<span>Priority: <span tal:replace="priority"/>, <span tal:replace="weight"/>, <a class="hostname" tal:attributes="href target" tal:content="target"/></span>
@ -1042,9 +1042,9 @@ class HtmlFormatter(Formatter):
outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.LOC:
# TODO: expanded longitude and latitude instead of floats?
icontext.addGlobal ("longitude", rdata.float_longitude)
icontext.addGlobal ("latitude", rdata.float_latitude)
icontext.addGlobal ("altitude", rdata.altitude)
icontext.addGlobal ("longitude", rdata.float_longitude)
icontext.addGlobal ("altitude", float(rdata.altitude)/100)
self.loc_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)

10
test_service.py

@ -51,25 +51,25 @@ def test_defaulttype(prefix): # ADDR by default
for format in formats:
r = requests.get(prefix + 'www.ietf.org/%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'104.20.0.85' in r.text, 'format is %s' % format
'104.20.' in r.text, 'format is %s' % format
def test_addr(prefix):
for format in formats:
r = requests.get(prefix + 'www.ietf.org/ADDR%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'104.20.0.85' in r.text, 'format is %s' % format
'104.20.' in r.text, 'format is %s' % format
def test_addr_v4(prefix):
for format in formats:
r = requests.get(prefix + 'www.ietf.org/A%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'104.20.0.85' in r.text, 'format is %s' % format
'104.20.' in r.text, 'format is %s' % format
def test_addr_v6(prefix):
for format in formats:
r = requests.get(prefix + 'www.ietf.org/AAAA%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'2606:4700:10::6814:155' in r.text, 'format is %s' % format
'2606:4700:10::' in r.text, 'format is %s' % format
def test_mx(prefix):
for format in formats:
@ -262,5 +262,5 @@ def test_content_negotiation(prefix):
continue
r = requests.get(prefix + 'www.ietf.org/ADDR', headers={'Accept': sstring(format)})
assert r.status_code == 200 and r.headers['content-type'].startswith(formats[format]) and \
'104.20.0.85' in r.text, 'format is %s' % format
'104.20.' in r.text, 'format is %s' % format

Loading…
Cancel
Save