1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import binascii
18
19 import dns.rdata
20
21
22 -class EUIBase(dns.rdata.Rdata):
23
24 """EUIxx record
25
26 @ivar fingerprint: xx-bit Extended Unique Identifier (EUI-xx)
27 @type fingerprint: string
28 @see: rfc7043.txt"""
29
30 __slots__ = ['eui']
31
32
33
34
35 - def __init__(self, rdclass, rdtype, eui):
41
42 - def to_text(self, origin=None, relativize=True, **kw):
43 return dns.rdata._hexify(self.eui, chunksize=2).replace(' ', '-')
44
45 @classmethod
46 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
47 text = tok.get_string()
48 tok.get_eol()
49 if len(text) != cls.text_len:
50 raise dns.exception.SyntaxError(
51 'Input text must have %s characters' % cls.text_len)
52 expected_dash_idxs = range(2, cls.byte_len * 3 - 1, 3)
53 for i in expected_dash_idxs:
54 if text[i] != '-':
55 raise dns.exception.SyntaxError('Dash expected at position %s'
56 % i)
57 text = text.replace('-', '')
58 try:
59 data = binascii.unhexlify(text.encode())
60 except (ValueError, TypeError) as ex:
61 raise dns.exception.SyntaxError('Hex decoding error: %s' % str(ex))
62 return cls(rdclass, rdtype, data)
63
64 - def to_wire(self, file, compress=None, origin=None):
66
67 @classmethod
68 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
71