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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import struct
  5. import dns.exception as dns
  6. import dns.rdata as dns
  7. import dns.name as dns
  8.  
  9. class SRV(dns.rdata.Rdata):
  10.     __slots__ = [
  11.         'priority',
  12.         'weight',
  13.         'port',
  14.         'target']
  15.     
  16.     def __init__(self, rdclass, rdtype, priority, weight, port, target):
  17.         super(SRV, self).__init__(rdclass, rdtype)
  18.         self.priority = priority
  19.         self.weight = weight
  20.         self.port = port
  21.         self.target = target
  22.  
  23.     
  24.     def to_text(self, origin = None, relativize = True, **kw):
  25.         target = self.target.choose_relativity(origin, relativize)
  26.         return '%d %d %d %s' % (self.priority, self.weight, self.port, target)
  27.  
  28.     
  29.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  30.         priority = tok.get_uint16()
  31.         weight = tok.get_uint16()
  32.         port = tok.get_uint16()
  33.         target = tok.get_name(None)
  34.         target = target.choose_relativity(origin, relativize)
  35.         tok.get_eol()
  36.         return cls(rdclass, rdtype, priority, weight, port, target)
  37.  
  38.     from_text = classmethod(from_text)
  39.     
  40.     def to_wire(self, file, compress = None, origin = None):
  41.         three_ints = struct.pack('!HHH', self.priority, self.weight, self.port)
  42.         file.write(three_ints)
  43.         self.target.to_wire(file, compress, origin)
  44.  
  45.     
  46.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  47.         (priority, weight, port) = struct.unpack('!HHH', wire[current:current + 6])
  48.         current += 6
  49.         rdlen -= 6
  50.         (target, cused) = dns.name.from_wire(wire[:current + rdlen], current)
  51.         if cused != rdlen:
  52.             raise dns.exception.FormError
  53.         cused != rdlen
  54.         if origin is not None:
  55.             target = target.relativize(origin)
  56.         
  57.         return cls(rdclass, rdtype, priority, weight, port, target)
  58.  
  59.     from_wire = classmethod(from_wire)
  60.     
  61.     def choose_relativity(self, origin = None, relativize = True):
  62.         self.target = self.target.choose_relativity(origin, relativize)
  63.  
  64.     
  65.     def _cmp(self, other):
  66.         sp = struct.pack('!HHH', self.priority, self.weight, self.port)
  67.         op = struct.pack('!HHH', other.priority, self.weight, self.port)
  68.         v = cmp(sp, op)
  69.         if v == 0:
  70.             v = cmp(self.target, other.target)
  71.         
  72.         return v
  73.  
  74.  
  75.