home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1655 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.4 KB  |  106 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.rdatatype as dns
  7. import dns.name as dns
  8.  
  9. class NXT(dns.rdata.Rdata):
  10.     __slots__ = [
  11.         'next',
  12.         'bitmap']
  13.     
  14.     def __init__(self, rdclass, rdtype, next, bitmap):
  15.         super(NXT, self).__init__(rdclass, rdtype)
  16.         self.next = next
  17.         self.bitmap = bitmap
  18.  
  19.     
  20.     def to_text(self, origin = None, relativize = True, **kw):
  21.         next = self.next.choose_relativity(origin, relativize)
  22.         bits = []
  23.         for i in xrange(0, len(self.bitmap)):
  24.             byte = ord(self.bitmap[i])
  25.             for j in xrange(0, 8):
  26.                 if byte & 128 >> j:
  27.                     bits.append(dns.rdatatype.to_text(i * 8 + j))
  28.                     continue
  29.             
  30.         
  31.         text = ' '.join(bits)
  32.         return '%s %s' % (next, text)
  33.  
  34.     
  35.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  36.         next = tok.get_name()
  37.         next = next.choose_relativity(origin, relativize)
  38.         bitmap = [
  39.             '\x00',
  40.             '\x00',
  41.             '\x00',
  42.             '\x00',
  43.             '\x00',
  44.             '\x00',
  45.             '\x00',
  46.             '\x00',
  47.             '\x00',
  48.             '\x00',
  49.             '\x00',
  50.             '\x00',
  51.             '\x00',
  52.             '\x00',
  53.             '\x00',
  54.             '\x00']
  55.         while None:
  56.             (ttype, value) = tok.get()
  57.             if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
  58.                 break
  59.             
  60.             if value.isdigit():
  61.                 nrdtype = int(value)
  62.             else:
  63.                 nrdtype = dns.rdatatype.from_text(value)
  64.             if nrdtype == 0:
  65.                 raise dns.exception.SyntaxError, 'NXT with bit 0'
  66.             if nrdtype > 127:
  67.                 raise dns.exception.SyntaxError, 'NXT with bit > 127'
  68.             nrdtype > 127
  69.             i = nrdtype // 8
  70.             bitmap[i] = chr(ord(bitmap[i]) | 128 >> nrdtype % 8)
  71.             continue
  72.             bitmap = dns.rdata._truncate_bitmap(bitmap)
  73.             return cls(rdclass, rdtype, next, bitmap)
  74.  
  75.     from_text = classmethod(from_text)
  76.     
  77.     def to_wire(self, file, compress = None, origin = None):
  78.         self.next.to_wire(file, None, origin)
  79.         file.write(self.bitmap)
  80.  
  81.     
  82.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  83.         (next, cused) = dns.name.from_wire(wire[:current + rdlen], current)
  84.         current += cused
  85.         rdlen -= cused
  86.         bitmap = wire[current:current + rdlen]
  87.         if origin is not None:
  88.             next = next.relativize(origin)
  89.         
  90.         return cls(rdclass, rdtype, next, bitmap)
  91.  
  92.     from_wire = classmethod(from_wire)
  93.     
  94.     def choose_relativity(self, origin = None, relativize = True):
  95.         self.next = self.next.choose_relativity(origin, relativize)
  96.  
  97.     
  98.     def _cmp(self, other):
  99.         v = cmp(self.next, other.next)
  100.         if v == 0:
  101.             v = cmp(self.bitmap, other.bitmap)
  102.         
  103.         return v
  104.  
  105.  
  106.