1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """TXT-like base class."""
17
18 import dns.exception
19 import dns.rdata
20 import dns.tokenizer
21
23 """Base class for rdata that is like a TXT record
24
25 @ivar strings: the text strings
26 @type strings: list of string
27 @see: RFC 1035"""
28
29 __slots__ = ['strings']
30
31 - def __init__(self, rdclass, rdtype, strings):
36
37 - def to_text(self, origin=None, relativize=True, **kw):
38 txt = ''
39 prefix = ''
40 for s in self.strings:
41 txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
42 prefix = ' '
43 return txt
44
45 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
46 strings = []
47 while 1:
48 (ttype, s) = tok.get()
49 if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
50 break
51 if ttype != dns.tokenizer.QUOTED_STRING and \
52 ttype != dns.tokenizer.IDENTIFIER:
53 raise dns.exception.SyntaxError, "expected a string"
54 if len(s) > 255:
55 raise dns.exception.SyntaxError, "string too long"
56 strings.append(s)
57 if len(strings) == 0:
58 raise dns.exception.UnexpectedEnd
59 return cls(rdclass, rdtype, strings)
60
61 from_text = classmethod(from_text)
62
63 - def to_wire(self, file, compress = None, origin = None):
64 for s in self.strings:
65 l = len(s)
66 assert l < 256
67 byte = chr(l)
68 file.write(byte)
69 file.write(s)
70
71 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
84
85 from_wire = classmethod(from_wire)
86
87 - def _cmp(self, other):
89