From f8ad77491f1e8c87625920062d2ef34ae0af6968 Mon Sep 17 00:00:00 2001 From: Petr Spacek Date: Tue, 21 Jan 2014 13:49:21 +0100 Subject: Fix default size, horizontal and vertical precition values for LOC records. Default values in RFC 1876 are in meters but the old code used the numerical value as centimeters. --- dns/rdtypes/ANY/LOC.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dns/rdtypes/ANY/LOC.py b/dns/rdtypes/ANY/LOC.py index 154546d..4d4b886 100644 --- a/dns/rdtypes/ANY/LOC.py +++ b/dns/rdtypes/ANY/LOC.py @@ -22,6 +22,11 @@ import dns.rdata _pows = (1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L, 10000000000L) +# default values are in centimeters +_default_size = 100.0 +_default_hprec = 1000000.0 +_default_vprec = 1000.0 + def _exponent_of(what, desc): exp = None for i in xrange(len(_pows)): @@ -98,13 +103,14 @@ class LOC(dns.rdata.Rdata): 'horizontal_precision', 'vertical_precision'] def __init__(self, rdclass, rdtype, latitude, longitude, altitude, - size=1.0, hprec=10000.0, vprec=10.0): + size=_default_size, hprec=_default_hprec, vprec=_default_vprec): """Initialize a LOC record instance. The parameters I{latitude} and I{longitude} may be either a 4-tuple of integers specifying (degrees, minutes, seconds, milliseconds), or they may be floating point values specifying the number of - degrees. The other parameters are floats.""" + degrees. The other parameters are floats. Size, horizontal precision, + and vertical precision are specified in centimeters.""" super(LOC, self).__init__(rdclass, rdtype) if isinstance(latitude, int) or isinstance(latitude, long): @@ -141,8 +147,10 @@ class LOC(dns.rdata.Rdata): self.longitude[3], long_hemisphere, self.altitude / 100.0 ) - if self.size != 1.0 or self.horizontal_precision != 10000.0 or \ - self.vertical_precision != 10.0: + # do not print default values + if self.size != _default_size or \ + self.horizontal_precision != _default_hprec or \ + self.vertical_precision != _default_vprec: text += " %0.2fm %0.2fm %0.2fm" % ( self.size / 100.0, self.horizontal_precision / 100.0, self.vertical_precision / 100.0 @@ -152,9 +160,9 @@ class LOC(dns.rdata.Rdata): def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): latitude = [0, 0, 0, 0] longitude = [0, 0, 0, 0] - size = 1.0 - hprec = 10000.0 - vprec = 10.0 + size = _default_size + hprec = _default_hprec + vprec = _default_vprec latitude[0] = tok.get_int() t = tok.get_string() -- cgit v1.2.1