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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cStringIO
  5. import struct
  6. import dns.exception as dns
  7. import dns.dnssec as dns
  8. import dns.rdata as dns
  9. import dns.tokenizer as dns
  10. _ctype_by_value = {
  11.     1: 'PKIX',
  12.     2: 'SPKI',
  13.     3: 'PGP',
  14.     253: 'URI',
  15.     254: 'OID' }
  16. _ctype_by_name = {
  17.     'PKIX': 1,
  18.     'SPKI': 2,
  19.     'PGP': 3,
  20.     'URI': 253,
  21.     'OID': 254 }
  22.  
  23. def _ctype_from_text(what):
  24.     v = _ctype_by_name.get(what)
  25.     if v is not None:
  26.         return v
  27.     return int(what)
  28.  
  29.  
  30. def _ctype_to_text(what):
  31.     v = _ctype_by_value.get(what)
  32.     if v is not None:
  33.         return v
  34.     return str(what)
  35.  
  36.  
  37. class CERT(dns.rdata.Rdata):
  38.     __slots__ = [
  39.         'certificate_type',
  40.         'key_tag',
  41.         'algorithm',
  42.         'certificate']
  43.     
  44.     def __init__(self, rdclass, rdtype, certificate_type, key_tag, algorithm, certificate):
  45.         super(CERT, self).__init__(rdclass, rdtype)
  46.         self.certificate_type = certificate_type
  47.         self.key_tag = key_tag
  48.         self.algorithm = algorithm
  49.         self.certificate = certificate
  50.  
  51.     
  52.     def to_text(self, origin = None, relativize = True, **kw):
  53.         certificate_type = _ctype_to_text(self.certificate_type)
  54.         return '%s %d %s %s' % (certificate_type, self.key_tag, dns.dnssec.algorithm_to_text(self.algorithm), dns.rdata._base64ify(self.certificate))
  55.  
  56.     
  57.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  58.         certificate_type = _ctype_from_text(tok.get_string())
  59.         key_tag = tok.get_uint16()
  60.         algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
  61.         if algorithm < 0 or algorithm > 255:
  62.             raise dns.exception.SyntaxError, 'bad algorithm type'
  63.         algorithm > 255
  64.         chunks = []
  65.         while None:
  66.             t = tok.get()
  67.             if t[0] == dns.tokenizer.EOL or t[0] == dns.tokenizer.EOF:
  68.                 break
  69.             
  70.             if t[0] != dns.tokenizer.IDENTIFIER:
  71.                 raise dns.exception.SyntaxError
  72.             chunks.append(t[1])
  73.             continue
  74.             b64 = ''.join(chunks)
  75.             certificate = b64.decode('base64_codec')
  76.             return cls(rdclass, rdtype, certificate_type, key_tag, algorithm, certificate)
  77.  
  78.     from_text = classmethod(from_text)
  79.     
  80.     def to_wire(self, file, compress = None, origin = None):
  81.         prefix = struct.pack('!HHB', self.certificate_type, self.key_tag, self.algorithm)
  82.         file.write(prefix)
  83.         file.write(self.certificate)
  84.  
  85.     
  86.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  87.         prefix = wire[current:current + 5]
  88.         current += 5
  89.         rdlen -= 5
  90.         if rdlen < 0:
  91.             raise dns.exception.FormError
  92.         rdlen < 0
  93.         (certificate_type, key_tag, algorithm) = struct.unpack('!HHB', prefix)
  94.         certificate = wire[current:current + rdlen]
  95.         return cls(rdclass, rdtype, certificate_type, key_tag, algorithm, certificate)
  96.  
  97.     from_wire = classmethod(from_wire)
  98.     
  99.     def _cmp(self, other):
  100.         f = cStringIO.StringIO()
  101.         self.to_wire(f)
  102.         wire1 = f.getvalue()
  103.         f.seek(0)
  104.         f.truncate()
  105.         other.to_wire(f)
  106.         wire2 = f.getvalue()
  107.         f.close()
  108.         return cmp(wire1, wire2)
  109.  
  110.  
  111.