home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import cStringIO
- import struct
- import dns.exception as dns
- import dns.rdata as dns
- _pows = (0x1L, 0xAL, 0x64L, 0x3E8L, 0x2710L, 0x186A0L, 0xF4240L, 0x989680L, 0x5F5E100L, 0x3B9ACA00L, 0x2540BE400L)
-
- def _exponent_of(what, desc):
- exp = None
- for i in xrange(len(_pows)):
- if what // _pows[i] == 0x0L:
- exp = i - 1
- break
- continue
-
- if exp is None or exp < 0:
- raise dns.exception.SyntaxError, '%s value out of bounds' % desc
- exp < 0
- return exp
-
-
- def _float_to_tuple(what):
- if what < 0:
- sign = -1
- what *= -1
- else:
- sign = 1
- what = long(round(what * 3600000))
- degrees = int(what // 3600000)
- what -= degrees * 3600000
- minutes = int(what // 60000)
- what -= minutes * 60000
- seconds = int(what // 1000)
- what -= int(seconds * 1000)
- what = int(what)
- return (degrees * sign, minutes, seconds, what)
-
-
- def _tuple_to_float(what):
- if what[0] < 0:
- sign = -1
- value = float(what[0]) * -1
- else:
- sign = 1
- value = float(what[0])
- value += float(what[1]) / 60
- value += float(what[2]) / 3600
- value += float(what[3]) / 3.6e+06
- return sign * value
-
-
- def _encode_size(what, desc):
- what = long(what)
- exponent = _exponent_of(what, desc) & 15
- base = what // pow(10, exponent) & 15
- return base * 16 + exponent
-
-
- def _decode_size(what, desc):
- exponent = what & 15
- if exponent > 9:
- raise dns.exception.SyntaxError, 'bad %s exponent' % desc
- exponent > 9
- base = (what & 240) >> 4
- if base > 9:
- raise dns.exception.SyntaxError, 'bad %s base' % desc
- base > 9
- return long(base) * pow(10, exponent)
-
-
- class LOC(dns.rdata.Rdata):
- __slots__ = [
- 'latitude',
- 'longitude',
- 'altitude',
- 'size',
- 'horizontal_precision',
- 'vertical_precision']
-
- def __init__(self, rdclass, rdtype, latitude, longitude, altitude, size = 1, hprec = 10000, vprec = 10):
- super(LOC, self).__init__(rdclass, rdtype)
- if isinstance(latitude, int) or isinstance(latitude, long):
- latitude = float(latitude)
-
- if isinstance(latitude, float):
- latitude = _float_to_tuple(latitude)
-
- self.latitude = latitude
- if isinstance(longitude, int) or isinstance(longitude, long):
- longitude = float(longitude)
-
- if isinstance(longitude, float):
- longitude = _float_to_tuple(longitude)
-
- self.longitude = longitude
- self.altitude = float(altitude)
- self.size = float(size)
- self.horizontal_precision = float(hprec)
- self.vertical_precision = float(vprec)
-
-
- def to_text(self, origin = None, relativize = True, **kw):
- if self.latitude[0] > 0:
- lat_hemisphere = 'N'
- lat_degrees = self.latitude[0]
- else:
- lat_hemisphere = 'S'
- lat_degrees = -1 * self.latitude[0]
- if self.longitude[0] > 0:
- long_hemisphere = 'E'
- long_degrees = self.longitude[0]
- else:
- long_hemisphere = 'W'
- long_degrees = -1 * self.longitude[0]
- text = '%d %d %d.%03d %s %d %d %d.%03d %s %0.2fm' % (lat_degrees, self.latitude[1], self.latitude[2], self.latitude[3], lat_hemisphere, long_degrees, self.longitude[1], self.longitude[2], self.longitude[3], long_hemisphere, self.altitude / 100)
- if self.size != 1 and self.horizontal_precision != 10000 or self.vertical_precision != 10:
- text += ' %0.2fm %0.2fm %0.2fm' % (self.size / 100, self.horizontal_precision / 100, self.vertical_precision / 100)
-
- return text
-
-
- def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
- latitude = [
- 0,
- 0,
- 0,
- 0]
- longitude = [
- 0,
- 0,
- 0,
- 0]
- size = 1
- hprec = 10000
- vprec = 10
- latitude[0] = tok.get_int()
- t = tok.get_string()
- if t.isdigit():
- latitude[1] = int(t)
- t = tok.get_string()
- if '.' in t:
- (seconds, milliseconds) = t.split('.')
- if not seconds.isdigit():
- raise dns.exception.SyntaxError, 'bad latitude seconds value'
- seconds.isdigit()
- latitude[2] = int(seconds)
- if latitude[2] >= 60:
- raise dns.exception.SyntaxError, 'latitude seconds >= 60'
- latitude[2] >= 60
- l = len(milliseconds)
- if l == 0 and l > 3 or not milliseconds.isdigit():
- raise dns.exception.SyntaxError, 'bad latitude milliseconds value'
- not milliseconds.isdigit()
- if l == 1:
- m = 100
- elif l == 2:
- m = 10
- else:
- m = 1
- latitude[3] = m * int(milliseconds)
- t = tok.get_string()
- elif t.isdigit():
- latitude[2] = int(t)
- t = tok.get_string()
-
-
- if t == 'S':
- latitude[0] *= -1
- elif t != 'N':
- raise dns.exception.SyntaxError, 'bad latitude hemisphere value'
-
- longitude[0] = tok.get_int()
- t = tok.get_string()
- if t.isdigit():
- longitude[1] = int(t)
- t = tok.get_string()
- if '.' in t:
- (seconds, milliseconds) = t.split('.')
- if not seconds.isdigit():
- raise dns.exception.SyntaxError, 'bad longitude seconds value'
- seconds.isdigit()
- longitude[2] = int(seconds)
- if longitude[2] >= 60:
- raise dns.exception.SyntaxError, 'longitude seconds >= 60'
- longitude[2] >= 60
- l = len(milliseconds)
- if l == 0 and l > 3 or not milliseconds.isdigit():
- raise dns.exception.SyntaxError, 'bad longitude milliseconds value'
- not milliseconds.isdigit()
- if l == 1:
- m = 100
- elif l == 2:
- m = 10
- else:
- m = 1
- longitude[3] = m * int(milliseconds)
- t = tok.get_string()
- elif t.isdigit():
- longitude[2] = int(t)
- t = tok.get_string()
-
-
- if t == 'W':
- longitude[0] *= -1
- elif t != 'E':
- raise dns.exception.SyntaxError, 'bad longitude hemisphere value'
-
- t = tok.get_string()
- if t[-1] == 'm':
- t = t[0:-1]
-
- altitude = float(t) * 100
- (ttype, value) = tok.get()
- if ttype != dns.tokenizer.EOL and ttype != dns.tokenizer.EOF:
- if value[-1] == 'm':
- value = value[0:-1]
-
- size = float(value) * 100
- (ttype, value) = tok.get()
- if ttype != dns.tokenizer.EOL and ttype != dns.tokenizer.EOF:
- if value[-1] == 'm':
- value = value[0:-1]
-
- hprec = float(value) * 100
- (ttype, value) = tok.get()
- if ttype != dns.tokenizer.EOL and ttype != dns.tokenizer.EOF:
- if value[-1] == 'm':
- value = value[0:-1]
- vprec = float(value) * 100
- (ttype, value) = tok.get()
- if ttype != dns.tokenizer.EOL and ttype != dns.tokenizer.EOF:
- raise dns.exception.SyntaxError, 'expected EOL or EOF'
- ttype != dns.tokenizer.EOF
-
-
-
-
- return cls(rdclass, rdtype, latitude, longitude, altitude, size, hprec, vprec)
-
- from_text = classmethod(from_text)
-
- def to_wire(self, file, compress = None, origin = None):
- if self.latitude[0] < 0:
- sign = -1
- degrees = long(-1 * self.latitude[0])
- else:
- sign = 1
- degrees = long(self.latitude[0])
- milliseconds = (degrees * 3600000 + self.latitude[1] * 60000 + self.latitude[2] * 1000 + self.latitude[3]) * sign
- latitude = 0x80000000L + milliseconds
- if self.longitude[0] < 0:
- sign = -1
- degrees = long(-1 * self.longitude[0])
- else:
- sign = 1
- degrees = long(self.longitude[0])
- milliseconds = (degrees * 3600000 + self.longitude[1] * 60000 + self.longitude[2] * 1000 + self.longitude[3]) * sign
- longitude = 0x80000000L + milliseconds
- altitude = long(self.altitude) + 0x989680L
- size = _encode_size(self.size, 'size')
- hprec = _encode_size(self.horizontal_precision, 'horizontal precision')
- vprec = _encode_size(self.vertical_precision, 'vertical precision')
- wire = struct.pack('!BBBBIII', 0, size, hprec, vprec, latitude, longitude, altitude)
- file.write(wire)
-
-
- def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
- (version, size, hprec, vprec, latitude, longitude, altitude) = struct.unpack('!BBBBIII', wire[current:current + rdlen])
- if latitude > 0x80000000L:
- latitude = float(latitude - 0x80000000L) / 3600000
- else:
- latitude = -1 * float(0x80000000L - latitude) / 3600000
- if latitude < -90 or latitude > 90:
- raise dns.exception.FormError, 'bad latitude'
- latitude > 90
- if longitude > 0x80000000L:
- longitude = float(longitude - 0x80000000L) / 3600000
- else:
- longitude = -1 * float(0x80000000L - longitude) / 3600000
- if longitude < -180 or longitude > 180:
- raise dns.exception.FormError, 'bad longitude'
- longitude > 180
- altitude = float(altitude) - 1e+07
- size = _decode_size(size, 'size')
- hprec = _decode_size(hprec, 'horizontal precision')
- vprec = _decode_size(vprec, 'vertical precision')
- return cls(rdclass, rdtype, latitude, longitude, altitude, size, hprec, vprec)
-
- from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- f = cStringIO.StringIO()
- self.to_wire(f)
- wire1 = f.getvalue()
- f.seek(0)
- f.truncate()
- other.to_wire(f)
- wire2 = f.getvalue()
- f.close()
- return cmp(wire1, wire2)
-
-
- def _get_float_latitude(self):
- return _tuple_to_float(self.latitude)
-
-
- def _set_float_latitude(self, value):
- self.latitude = _float_to_tuple(value)
-
- float_latitude = property(_get_float_latitude, _set_float_latitude, doc = 'latitude as a floating point value')
-
- def _get_float_longitude(self):
- return _tuple_to_float(self.longitude)
-
-
- def _set_float_longitude(self, value):
- self.longitude = _float_to_tuple(value)
-
- float_longitude = property(_get_float_longitude, _set_float_longitude, doc = 'longitude as a floating point value')
-
-