9 # check hostname for validity
10 label = r'[a-zA-Z90-9]([a-zA-Z90-9-]{0,61}[a-zA-Z90-9])?' # must not start or end with hyphen
11 pattern = r'^{0}(\.{0})*\.?'.format(label)
13 if re.match(pattern, name):
15 raise Exception(name+" is not a valid hostname")
18 def __init__(self, IPv4 = None, IPv6 = None):
19 self._IPv4 = None if IPv4 is None else ipaddress.IPv4Address(IPv4)
20 self._IPv6 = None if IPv6 is None else ipaddress.IPv6Address(IPv6)
23 return Address(IPv4 = self._IPv4)
26 return Address(IPv6 = self._IPv6)
29 def __init__(self, address = None, MX = None, TCP = None, UDP = None):
30 self._address = address
33 def __init__(self, SRV = None, TLSA=None):
38 def __init__(self, name):
42 def __init__(self, NS, DS = None):
46 def __init__(self, name, mail, NS,
47 secondary_refresh, secondary_retry, secondary_discard,
48 NX_TTL = None, A_TTL = None, other_TTL = None,
50 self._name = hostname(name)
51 assert mail.endswith('.'), "Mail must be absolute, end with a dot"
52 atpos = mail.find('@')
53 assert atpos >= 0 and atpos < mail.find('.'), "Mail must contain an @ before the first dot"
54 self._mail = hostname(mail.replace('@', '.', 1))
55 self._NS = list(map(hostname, NS))
57 self._secondary_refresh = secondary_refresh
58 self._secondary_retry = secondary_retry
59 self._secondary_discard = secondary_discard
61 assert other_TTL is not None
62 self._NX_TTL = other_TTL if NX_TTL is None else NX_TTL
63 self._A_TTL = other_TTL if A_TTL is None else A_TTL
64 self._other_TTL = other_TTL
66 def write(self, file):
67 raise NotImplementedError()