home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1685 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.9 KB  |  82 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.tokenizer as dns
  7.  
  8. class TXTBase(dns.rdata.Rdata):
  9.     __slots__ = [
  10.         'strings']
  11.     
  12.     def __init__(self, rdclass, rdtype, strings):
  13.         super(TXTBase, self).__init__(rdclass, rdtype)
  14.         if isinstance(strings, str):
  15.             strings = [
  16.                 strings]
  17.         
  18.         self.strings = strings[:]
  19.  
  20.     
  21.     def to_text(self, origin = None, relativize = True, **kw):
  22.         txt = ''
  23.         prefix = ''
  24.         for s in self.strings:
  25.             txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
  26.             prefix = ' '
  27.         
  28.         return txt
  29.  
  30.     
  31.     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
  32.         strings = []
  33.         while None:
  34.             (ttype, s) = tok.get()
  35.             if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
  36.                 break
  37.             
  38.             if ttype != dns.tokenizer.QUOTED_STRING and ttype != dns.tokenizer.IDENTIFIER:
  39.                 raise dns.exception.SyntaxError, 'expected a string'
  40.             if len(s) > 255:
  41.                 raise dns.exception.SyntaxError, 'string too long'
  42.             len(s) > 255
  43.             strings.append(s)
  44.             continue
  45.             if len(strings) == 0:
  46.                 raise dns.exception.UnexpectedEnd
  47.             len(strings) == 0
  48.             return cls(rdclass, rdtype, strings)
  49.  
  50.     from_text = classmethod(from_text)
  51.     
  52.     def to_wire(self, file, compress = None, origin = None):
  53.         for s in self.strings:
  54.             l = len(s)
  55.             byte = chr(l)
  56.             file.write(byte)
  57.             file.write(s)
  58.         
  59.  
  60.     
  61.     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
  62.         strings = []
  63.         while rdlen > 0:
  64.             l = ord(wire[current])
  65.             current += 1
  66.             rdlen -= 1
  67.             if l > rdlen:
  68.                 raise dns.exception.FormError
  69.             l > rdlen
  70.             s = wire[current:current + l]
  71.             current += l
  72.             rdlen -= l
  73.             strings.append(s)
  74.         return cls(rdclass, rdtype, strings)
  75.  
  76.     from_wire = classmethod(from_wire)
  77.     
  78.     def _cmp(self, other):
  79.         return cmp(self.strings, other.strings)
  80.  
  81.  
  82.