def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
text = tok.get_string()
tok.get_eol()
if len(text) != cls.text_len:
raise dns.exception.SyntaxError(
'Input text must have %s characters' % cls.text_len)
expected_dash_idxs = range(2, cls.byte_len * 3 - 1, 3)
for i in expected_dash_idxs:
if text[i] != '-':
raise dns.exception.SyntaxError('Dash expected at position %s'
% i)
text = text.replace('-', '')
try:
data = binascii.unhexlify(text.encode())
except (ValueError, TypeError) as ex:
raise dns.exception.SyntaxError('Hex decoding error: %s' % str(ex))
return cls(rdclass, rdtype, data)
评论列表
文章目录