home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1681 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.8 KB  |  135 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.dnssec as dns
  7. import dns.rdata as dns
  8. _flags_from_text = {
  9.     'NOCONF': (16384, 49152),
  10.     'NOAUTH': (32768, 49152),
  11.     'NOKEY': (49152, 49152),
  12.     'FLAG2': (8192, 8192),
  13.     'EXTEND': (4096, 4096),
  14.     'FLAG4': (2048, 2048),
  15.     'FLAG5': (1024, 1024),
  16.     'USER': (0, 768),
  17.     'ZONE': (256, 768),
  18.     'HOST': (512, 768),
  19.     'NTYP3': (768, 768),
  20.     'FLAG8': (128, 128),
  21.     'FLAG9': (64, 64),
  22.     'FLAG10': (32, 32),
  23.     'FLAG11': (16, 16),
  24.     'SIG0': (0, 15),
  25.     'SIG1': (1, 15),
  26.     'SIG2': (2, 15),
  27.     'SIG3': (3, 15),
  28.     'SIG4': (4, 15),
  29.     'SIG5': (5, 15),
  30.     'SIG6': (6, 15),
  31.     'SIG7': (7, 15),
  32.     'SIG8': (8, 15),
  33.     'SIG9': (9, 15),
  34.     'SIG10': (10, 15),
  35.     'SIG11': (11, 15),
  36.     'SIG12': (12, 15),
  37.     'SIG13': (13, 15),
  38.     'SIG14': (14, 15),
  39.     'SIG15': (15, 15) }
  40. _protocol_from_text = {
  41.     'NONE': 0,
  42.     'TLS': 1,
  43.     'EMAIL': 2,
  44.     'DNSSEC': 3,
  45.     'IPSEC': 4,
  46.     'ALL': 255 }
  47.  
  48. class KEYBase(dns.rdata.Rdata):
  49.     __slots__ = [
  50.         'flags',
  51.         'protocol',
  52.         'algorithm',
  53.         'key']
  54.     
  55.     def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
  56.         super(KEYBase, self).__init__(rdclass, rdtype)
  57.         self.flags = flags
  58.         self.protocol = protocol
  59.         self.algorithm = algorithm
  60.         self.key = key
  61.  
  62.     
  63.     def to_text(self, origin = None, relativize = True, **kw):
  64.         return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm, dns.rdata._base64ify(self.key))
  65.  
  66.     
  67.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  68.         flags = tok.get_string()
  69.         if flags.isdigit():
  70.             flags = int(flags)
  71.         else:
  72.             flag_names = flags.split('|')
  73.             flags = 0
  74.             for flag in flag_names:
  75.                 v = _flags_from_text.get(flag)
  76.                 if v is None:
  77.                     raise dns.exception.SyntaxError, 'unknown flag %s' % flag
  78.                 v is None
  79.                 flags &= ~v[1]
  80.                 flags |= v[0]
  81.             
  82.         protocol = tok.get_string()
  83.         if protocol.isdigit():
  84.             protocol = int(protocol)
  85.         else:
  86.             protocol = _protocol_from_text.get(protocol)
  87.             if protocol is None:
  88.                 raise dns.exception.SyntaxError, 'unknown protocol %s' % protocol
  89.             protocol is None
  90.         algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
  91.         chunks = []
  92.         while None:
  93.             t = tok.get()
  94.             if t[0] == dns.tokenizer.EOL or t[0] == dns.tokenizer.EOF:
  95.                 break
  96.             
  97.             if t[0] != dns.tokenizer.IDENTIFIER:
  98.                 raise dns.exception.SyntaxError
  99.             chunks.append(t[1])
  100.             continue
  101.             b64 = ''.join(chunks)
  102.             key = b64.decode('base64_codec')
  103.             return cls(rdclass, rdtype, flags, protocol, algorithm, key)
  104.  
  105.     from_text = classmethod(from_text)
  106.     
  107.     def to_wire(self, file, compress = None, origin = None):
  108.         header = struct.pack('!HBB', self.flags, self.protocol, self.algorithm)
  109.         file.write(header)
  110.         file.write(self.key)
  111.  
  112.     
  113.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  114.         if rdlen < 4:
  115.             raise dns.exception.FormError
  116.         rdlen < 4
  117.         header = struct.unpack('!HBB', wire[current:current + 4])
  118.         current += 4
  119.         rdlen -= 4
  120.         key = wire[current:current + rdlen]
  121.         return cls(rdclass, rdtype, header[0], header[1], header[2], key)
  122.  
  123.     from_wire = classmethod(from_wire)
  124.     
  125.     def _cmp(self, other):
  126.         hs = struct.pack('!HBB', self.flags, self.protocol, self.algorithm)
  127.         ho = struct.pack('!HBB', other.flags, other.protocol, other.algorithm)
  128.         v = cmp(hs, ho)
  129.         if v == 0:
  130.             v = cmp(self.key, other.key)
  131.         
  132.         return v
  133.  
  134.  
  135.