1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import dns.exception
17 import dns.rdata
18 import dns.rdatatype
19 import dns.name
20
21 -class NXT(dns.rdata.Rdata):
22 """NXT record
23
24 @ivar next: the next name
25 @type next: dns.name.Name object
26 @ivar bitmap: the type bitmap
27 @type bitmap: string
28 @see: RFC 2535"""
29
30 __slots__ = ['next', 'bitmap']
31
32 - def __init__(self, rdclass, rdtype, next, bitmap):
36
37 - def to_text(self, origin=None, relativize=True, **kw):
38 next = self.next.choose_relativity(origin, relativize)
39 bits = []
40 for i in xrange(0, len(self.bitmap)):
41 byte = ord(self.bitmap[i])
42 for j in xrange(0, 8):
43 if byte & (0x80 >> j):
44 bits.append(dns.rdatatype.to_text(i * 8 + j))
45 text = ' '.join(bits)
46 return '%s %s' % (next, text)
47
48 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
49 next = tok.get_name()
50 next = next.choose_relativity(origin, relativize)
51 bitmap = ['\x00', '\x00', '\x00', '\x00',
52 '\x00', '\x00', '\x00', '\x00',
53 '\x00', '\x00', '\x00', '\x00',
54 '\x00', '\x00', '\x00', '\x00' ]
55 while 1:
56 token = tok.get().unescape()
57 if token.is_eol_or_eof():
58 break
59 if token.value.isdigit():
60 nrdtype = int(token.value)
61 else:
62 nrdtype = dns.rdatatype.from_text(token.value)
63 if nrdtype == 0:
64 raise dns.exception.SyntaxError("NXT with bit 0")
65 if nrdtype > 127:
66 raise dns.exception.SyntaxError("NXT with bit > 127")
67 i = nrdtype // 8
68 bitmap[i] = chr(ord(bitmap[i]) | (0x80 >> (nrdtype % 8)))
69 bitmap = dns.rdata._truncate_bitmap(bitmap)
70 return cls(rdclass, rdtype, next, bitmap)
71
72 from_text = classmethod(from_text)
73
74 - def to_wire(self, file, compress = None, origin = None):
77
80
81 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
89
90 from_wire = classmethod(from_wire)
91
94
95 - def _cmp(self, other):
100