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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import calendar
  5. import struct
  6. import time
  7. import dns.dnssec as dns
  8. import dns.exception as dns
  9. import dns.rdata as dns
  10. import dns.rdatatype as dns
  11.  
  12. class BadSigTime(dns.exception.DNSException):
  13.     pass
  14.  
  15.  
  16. def sigtime_to_posixtime(what):
  17.     if len(what) != 14:
  18.         raise BadSigTime
  19.     len(what) != 14
  20.     year = int(what[0:4])
  21.     month = int(what[4:6])
  22.     day = int(what[6:8])
  23.     hour = int(what[8:10])
  24.     minute = int(what[10:12])
  25.     second = int(what[12:14])
  26.     return calendar.timegm((year, month, day, hour, minute, second, 0, 0, 0))
  27.  
  28.  
  29. def posixtime_to_sigtime(what):
  30.     return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
  31.  
  32.  
  33. class SIGBase(dns.rdata.Rdata):
  34.     __slots__ = [
  35.         'type_covered',
  36.         'algorithm',
  37.         'labels',
  38.         'original_ttl',
  39.         'expiration',
  40.         'inception',
  41.         'key_tag',
  42.         'signer',
  43.         'signature']
  44.     
  45.     def __init__(self, rdclass, rdtype, type_covered, algorithm, labels, original_ttl, expiration, inception, key_tag, signer, signature):
  46.         super(SIGBase, self).__init__(rdclass, rdtype)
  47.         self.type_covered = type_covered
  48.         self.algorithm = algorithm
  49.         self.labels = labels
  50.         self.original_ttl = original_ttl
  51.         self.expiration = expiration
  52.         self.inception = inception
  53.         self.key_tag = key_tag
  54.         self.signer = signer
  55.         self.signature = signature
  56.  
  57.     
  58.     def covers(self):
  59.         return self.type_covered
  60.  
  61.     
  62.     def to_text(self, origin = None, relativize = True, **kw):
  63.         return '%s %d %d %d %s %s %d %s %s' % (dns.rdatatype.to_text(self.type_covered), self.algorithm, self.labels, self.original_ttl, posixtime_to_sigtime(self.expiration), posixtime_to_sigtime(self.inception), self.key_tag, self.signer, dns.rdata._base64ify(self.signature))
  64.  
  65.     
  66.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  67.         type_covered = dns.rdatatype.from_text(tok.get_string())
  68.         algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
  69.         labels = tok.get_int()
  70.         original_ttl = tok.get_ttl()
  71.         expiration = sigtime_to_posixtime(tok.get_string())
  72.         inception = sigtime_to_posixtime(tok.get_string())
  73.         key_tag = tok.get_int()
  74.         signer = tok.get_name()
  75.         signer = signer.choose_relativity(origin, relativize)
  76.         chunks = []
  77.         while None:
  78.             t = tok.get()
  79.             if t[0] == dns.tokenizer.EOL or t[0] == dns.tokenizer.EOF:
  80.                 break
  81.             
  82.             if t[0] != dns.tokenizer.IDENTIFIER:
  83.                 raise dns.exception.SyntaxError
  84.             chunks.append(t[1])
  85.             continue
  86.             b64 = ''.join(chunks)
  87.             signature = b64.decode('base64_codec')
  88.             return cls(rdclass, rdtype, type_covered, algorithm, labels, original_ttl, expiration, inception, key_tag, signer, signature)
  89.  
  90.     from_text = classmethod(from_text)
  91.     
  92.     def to_wire(self, file, compress = None, origin = None):
  93.         header = struct.pack('!HBBIIIH', self.type_covered, self.algorithm, self.labels, self.original_ttl, self.expiration, self.inception, self.key_tag)
  94.         file.write(header)
  95.         self.signer.to_wire(file, None, origin)
  96.         file.write(self.signature)
  97.  
  98.     
  99.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  100.         header = struct.unpack('!HBBIIIH', wire[current:current + 18])
  101.         current += 18
  102.         rdlen -= 18
  103.         (signer, cused) = dns.name.from_wire(wire[:current + rdlen], current)
  104.         current += cused
  105.         rdlen -= cused
  106.         if origin is not None:
  107.             signer = signer.relativize(origin)
  108.         
  109.         signature = wire[current:current + rdlen]
  110.         return cls(rdclass, rdtype, header[0], header[1], header[2], header[3], header[4], header[5], header[6], signer, signature)
  111.  
  112.     from_wire = classmethod(from_wire)
  113.     
  114.     def choose_relativity(self, origin = None, relativize = True):
  115.         self.signer = self.signer.choose_relativity(origin, relativize)
  116.  
  117.     
  118.     def _cmp(self, other):
  119.         hs = struct.pack('!HBBIIIH', self.type_covered, self.algorithm, self.labels, self.original_ttl, self.expiration, self.inception, self.key_tag)
  120.         ho = struct.pack('!HBBIIIH', other.type_covered, other.algorithm, other.labels, other.original_ttl, other.expiration, other.inception, other.key_tag)
  121.         v = cmp(hs, ho)
  122.         if v == 0:
  123.             v = cmp(self.signer, other.signer)
  124.             if v == 0:
  125.                 v = cmp(self.signature, other.signature)
  126.             
  127.         
  128.         return v
  129.  
  130.  
  131.