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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import random
  5. import StringIO
  6. import struct
  7. import dns.exception as dns
  8. import dns.rdatatype as dns
  9. import dns.rdataclass as dns
  10. import dns.rdata as dns
  11. import dns.set as dns
  12. SimpleSet = dns.set.Set
  13.  
  14. class DifferingCovers(dns.exception.DNSException):
  15.     pass
  16.  
  17.  
  18. class IncompatibleTypes(dns.exception.DNSException):
  19.     pass
  20.  
  21.  
  22. class Rdataset(dns.set.Set):
  23.     __slots__ = [
  24.         'rdclass',
  25.         'rdtype',
  26.         'covers',
  27.         'ttl']
  28.     
  29.     def __init__(self, rdclass, rdtype, covers = dns.rdatatype.NONE):
  30.         super(Rdataset, self).__init__()
  31.         self.rdclass = rdclass
  32.         self.rdtype = rdtype
  33.         self.covers = covers
  34.         self.ttl = 0
  35.  
  36.     
  37.     def _clone(self):
  38.         obj = super(Rdataset, self)._clone()
  39.         obj.rdclass = self.rdclass
  40.         obj.rdtype = self.rdtype
  41.         obj.covers = self.covers
  42.         obj.ttl = self.ttl
  43.         return obj
  44.  
  45.     
  46.     def update_ttl(self, ttl):
  47.         if len(self) == 0:
  48.             self.ttl = ttl
  49.         elif ttl < self.ttl:
  50.             self.ttl = ttl
  51.         
  52.  
  53.     
  54.     def add(self, rd, ttl = None):
  55.         if self.rdclass != rd.rdclass or self.rdtype != rd.rdtype:
  56.             raise IncompatibleTypes
  57.         self.rdtype != rd.rdtype
  58.         if ttl is not None:
  59.             self.update_ttl(ttl)
  60.         
  61.         if self.rdtype == dns.rdatatype.RRSIG or self.rdtype == dns.rdatatype.SIG:
  62.             covers = rd.covers()
  63.             if len(self) == 0 and self.covers == dns.rdatatype.NONE:
  64.                 self.covers = covers
  65.             elif self.covers != covers:
  66.                 raise DifferingCovers
  67.             
  68.         
  69.         if dns.rdatatype.is_singleton(rd.rdtype) and len(self) > 0:
  70.             self.clear()
  71.         
  72.         super(Rdataset, self).add(rd)
  73.  
  74.     
  75.     def union_update(self, other):
  76.         self.update_ttl(other.ttl)
  77.         super(Rdataset, self).union_update(other)
  78.  
  79.     
  80.     def intersection_update(self, other):
  81.         self.update_ttl(other.ttl)
  82.         super(Rdataset, self).intersection_update(other)
  83.  
  84.     
  85.     def update(self, other):
  86.         self.update_ttl(other.ttl)
  87.         super(Rdataset, self).update(other)
  88.  
  89.     
  90.     def __repr__(self):
  91.         if self.covers == 0:
  92.             ctext = ''
  93.         else:
  94.             ctext = '(' + dns.rdatatype.to_text(self.covers) + ')'
  95.         return '<DNS ' + dns.rdataclass.to_text(self.rdclass) + ' ' + dns.rdatatype.to_text(self.rdtype) + ctext + ' rdataset>'
  96.  
  97.     
  98.     def __str__(self):
  99.         return self.to_text()
  100.  
  101.     
  102.     def __eq__(self, other):
  103.         if not isinstance(other, Rdataset):
  104.             return False
  105.         if self.rdclass != other.rdclass and self.rdtype != other.rdtype or self.covers != other.covers:
  106.             return False
  107.         return super(Rdataset, self).__eq__(other)
  108.  
  109.     
  110.     def __ne__(self, other):
  111.         return not self.__eq__(other)
  112.  
  113.     
  114.     def to_text(self, name = None, origin = None, relativize = True, override_rdclass = None, **kw):
  115.         if name is not None:
  116.             name = name.choose_relativity(origin, relativize)
  117.             ntext = str(name)
  118.             pad = ' '
  119.         else:
  120.             ntext = ''
  121.             pad = ''
  122.         s = StringIO.StringIO()
  123.         if override_rdclass is not None:
  124.             rdclass = override_rdclass
  125.         else:
  126.             rdclass = self.rdclass
  127.         if len(self) == 0:
  128.             print >>s, '%s%s%s %s' % (ntext, pad, dns.rdataclass.to_text(rdclass), dns.rdatatype.to_text(self.rdtype))
  129.         else:
  130.             for rd in self:
  131.                 print >>s, '%s%s%d %s %s %s' % (ntext, pad, self.ttl, dns.rdataclass.to_text(rdclass), dns.rdatatype.to_text(self.rdtype), rd.to_text(origin = origin, relativize = relativize, **kw))
  132.             
  133.         return s.getvalue()[:-1]
  134.  
  135.     
  136.     def to_wire(self, name, file, compress = None, origin = None, override_rdclass = None, want_shuffle = True):
  137.         if override_rdclass is not None:
  138.             rdclass = override_rdclass
  139.             want_shuffle = False
  140.         else:
  141.             rdclass = self.rdclass
  142.         file.seek(0, 2)
  143.         if len(self) == 0:
  144.             name.to_wire(file, compress, origin)
  145.             stuff = struct.pack('!HHIH', self.rdtype, rdclass, 0, 0)
  146.             file.write(stuff)
  147.             return 1
  148.         if want_shuffle:
  149.             l = list(self)
  150.             random.shuffle(l)
  151.         else:
  152.             l = self
  153.         for rd in l:
  154.             name.to_wire(file, compress, origin)
  155.             stuff = struct.pack('!HHIH', self.rdtype, rdclass, self.ttl, 0)
  156.             file.write(stuff)
  157.             start = file.tell()
  158.             rd.to_wire(file, compress, origin)
  159.             end = file.tell()
  160.             file.seek(start - 2)
  161.             stuff = struct.pack('!H', end - start)
  162.             file.write(stuff)
  163.             file.seek(0, 2)
  164.         
  165.         return len(self)
  166.  
  167.     
  168.     def match(self, rdclass, rdtype, covers):
  169.         if self.rdclass == rdclass and self.rdtype == rdtype and self.covers == covers:
  170.             return True
  171.         return False
  172.  
  173.  
  174.  
  175. def from_text_list(rdclass, rdtype, ttl, text_rdatas):
  176.     if isinstance(rdclass, str):
  177.         rdclass = dns.rdataclass.from_text(rdclass)
  178.     
  179.     if isinstance(rdtype, str):
  180.         rdtype = dns.rdatatype.from_text(rdtype)
  181.     
  182.     r = Rdataset(rdclass, rdtype)
  183.     r.update_ttl(ttl)
  184.     for t in text_rdatas:
  185.         rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
  186.         r.add(rd)
  187.     
  188.     return r
  189.  
  190.  
  191. def from_text(rdclass, rdtype, ttl, *text_rdatas):
  192.     return from_text_list(rdclass, rdtype, ttl, text_rdatas)
  193.  
  194.  
  195. def from_rdata_list(ttl, rdatas):
  196.     if len(rdatas) == 0:
  197.         raise ValueError, 'rdata list must not be empty'
  198.     len(rdatas) == 0
  199.     r = None
  200.     for rd in rdatas:
  201.         if r is None:
  202.             r = Rdataset(rd.rdclass, rd.rdtype)
  203.             r.update_ttl(ttl)
  204.             first_time = False
  205.         
  206.         r.add(rd)
  207.     
  208.     return r
  209.  
  210.  
  211. def from_rdata(ttl, *rdatas):
  212.     return from_rdata_list(ttl, rdatas)
  213.  
  214.