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 token = tok.get().unescape()
49 if token.is_eol_or_eof():
50 break
51 if not (token.is_quoted_string() or token.is_identifier()):
52 raise dns.exception.SyntaxError("expected a string")
53 if len(token.value) > 255:
54 raise dns.exception.SyntaxError("string too long")
55 strings.append(token.value)
56 if len(strings) == 0:
57 raise dns.exception.UnexpectedEnd
58 return cls(rdclass, rdtype, strings)
59
60 from_text = classmethod(from_text)
61
62 - def to_wire(self, file, compress = None, origin = None):
63 for s in self.strings:
64 l = len(s)
65 assert l < 256
66 byte = chr(l)
67 file.write(byte)
68 file.write(s)
69
70 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
83
84 from_wire = classmethod(from_wire)
85
86 - def _cmp(self, other):
88