home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1647 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.1 KB  |  147 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import dns.exception as dns
  5. import dns.rdata as dns
  6. import dns.tokenizer as dns
  7.  
  8. def _validate_float_string(what):
  9.     if what[0] == '-' or what[0] == '+':
  10.         what = what[1:]
  11.     
  12.     if what.isdigit():
  13.         return None
  14.     (left, right) = what.split('.')
  15.     if left == '' and right == '':
  16.         raise dns.exception.FormError
  17.     right == ''
  18.     if not (left == '') and not left.isdigit():
  19.         raise dns.exception.FormError
  20.     not left.isdigit()
  21.     if not (right == '') and not right.isdigit():
  22.         raise dns.exception.FormError
  23.     not right.isdigit()
  24.  
  25.  
  26. class GPOS(dns.rdata.Rdata):
  27.     __slots__ = [
  28.         'latitude',
  29.         'longitude',
  30.         'altitude']
  31.     
  32.     def __init__(self, rdclass, rdtype, latitude, longitude, altitude):
  33.         super(GPOS, self).__init__(rdclass, rdtype)
  34.         if isinstance(latitude, float) and isinstance(latitude, int) or isinstance(latitude, long):
  35.             latitude = str(latitude)
  36.         
  37.         if isinstance(longitude, float) and isinstance(longitude, int) or isinstance(longitude, long):
  38.             longitude = str(longitude)
  39.         
  40.         if isinstance(altitude, float) and isinstance(altitude, int) or isinstance(altitude, long):
  41.             altitude = str(altitude)
  42.         
  43.         _validate_float_string(latitude)
  44.         _validate_float_string(longitude)
  45.         _validate_float_string(altitude)
  46.         self.latitude = latitude
  47.         self.longitude = longitude
  48.         self.altitude = altitude
  49.  
  50.     
  51.     def to_text(self, origin = None, relativize = True, **kw):
  52.         return '%s %s %s' % (self.latitude, self.longitude, self.altitude)
  53.  
  54.     
  55.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  56.         latitude = tok.get_string()
  57.         longitude = tok.get_string()
  58.         altitude = tok.get_string()
  59.         tok.get_eol()
  60.         return cls(rdclass, rdtype, latitude, longitude, altitude)
  61.  
  62.     from_text = classmethod(from_text)
  63.     
  64.     def to_wire(self, file, compress = None, origin = None):
  65.         l = len(self.latitude)
  66.         byte = chr(l)
  67.         file.write(byte)
  68.         file.write(self.latitude)
  69.         l = len(self.longitude)
  70.         byte = chr(l)
  71.         file.write(byte)
  72.         file.write(self.longitude)
  73.         l = len(self.altitude)
  74.         byte = chr(l)
  75.         file.write(byte)
  76.         file.write(self.altitude)
  77.  
  78.     
  79.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  80.         l = ord(wire[current])
  81.         current += 1
  82.         rdlen -= 1
  83.         if l > rdlen:
  84.             raise dns.exception.FormError
  85.         l > rdlen
  86.         latitude = wire[current:current + l]
  87.         current += l
  88.         rdlen -= l
  89.         l = ord(wire[current])
  90.         current += 1
  91.         rdlen -= 1
  92.         if l > rdlen:
  93.             raise dns.exception.FormError
  94.         l > rdlen
  95.         longitude = wire[current:current + l]
  96.         current += l
  97.         rdlen -= l
  98.         l = ord(wire[current])
  99.         current += 1
  100.         rdlen -= 1
  101.         if l != rdlen:
  102.             raise dns.exception.FormError
  103.         l != rdlen
  104.         altitude = wire[current:current + l]
  105.         return cls(rdclass, rdtype, latitude, longitude, altitude)
  106.  
  107.     from_wire = classmethod(from_wire)
  108.     
  109.     def _cmp(self, other):
  110.         v = cmp(self.latitude, other.latitude)
  111.         if v == 0:
  112.             v = cmp(self.longitude, other.longitude)
  113.             if v == 0:
  114.                 v = cmp(self.altitude, other.altitude)
  115.             
  116.         
  117.         return v
  118.  
  119.     
  120.     def _get_float_latitude(self):
  121.         return float(self.latitude)
  122.  
  123.     
  124.     def _set_float_latitude(self, value):
  125.         self.latitude = str(value)
  126.  
  127.     float_latitude = property(_get_float_latitude, _set_float_latitude, doc = 'latitude as a floating point value')
  128.     
  129.     def _get_float_longitude(self):
  130.         return float(self.longitude)
  131.  
  132.     
  133.     def _set_float_longitude(self, value):
  134.         self.longitude = str(value)
  135.  
  136.     float_longitude = property(_get_float_longitude, _set_float_longitude, doc = 'longitude as a floating point value')
  137.     
  138.     def _get_float_altitude(self):
  139.         return float(self.altitude)
  140.  
  141.     
  142.     def _set_float_altitude(self, value):
  143.         self.altitude = str(value)
  144.  
  145.     float_altitude = property(_get_float_altitude, _set_float_altitude, doc = 'altitude as a floating point value')
  146.  
  147.