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