X-Git-Url: https://git.ralfj.de/zonemaker.git/blobdiff_plain/81b4573994bcaef18aae462cfbf7c5cf542db0ca..c10d6915434773f5b9bc9784b73d18cdc8cf3389:/zonemaker/zone.py diff --git a/zonemaker/zone.py b/zonemaker/zone.py index 435b039..f8390a4 100644 --- a/zonemaker/zone.py +++ b/zonemaker/zone.py @@ -1,11 +1,14 @@ -import ipaddress, re +import re +from ipaddress import IPv4Address, IPv6Address +from typing import List, Dict, Any + second = 1 minute = 60*second hour = 60*minute day = 24*hour -def hostname(name): +def hostname(name: str) -> str: # check hostname for validity label = r'[a-zA-Z90-9]([a-zA-Z90-9-]{0,61}[a-zA-Z90-9])?' # must not start or end with hyphen pattern = r'^{0}(\.{0})*\.?'.format(label) @@ -15,9 +18,9 @@ def hostname(name): raise Exception(name+" is not a valid hostname") class Address: - def __init__(self, IPv4 = None, IPv6 = None): - self._IPv4 = None if IPv4 is None else ipaddress.IPv4Address(IPv4) - self._IPv6 = None if IPv6 is None else ipaddress.IPv6Address(IPv6) + def __init__(self, IPv4: str = None, IPv6: str = None) -> None: + self._IPv4 = None if IPv4 is None else IPv4Address(IPv4) + self._IPv6 = None if IPv6 is None else IPv6Address(IPv6) def IPv4(self): return Address(IPv4 = self._IPv4) @@ -26,27 +29,28 @@ class Address: return Address(IPv6 = self._IPv6) class Name: - def __init__(self, address = None, MX = None, TCP = None, UDP = None): + def __init__(self, address: Address = None, MX: List = None, + TCP: Dict[int, Any] = None, UDP: Dict[int, Any] = None) -> None: self._address = address class Service: - def __init__(self, SRV = None, TLSA=None): + def __init__(self, SRV: str = None, TLSA: str=None) -> None: self._SRV = SRV self._TLSA = TLSA class CName: - def __init__(self, name): + def __init__(self, name: str) -> None: self._name = name class Delegation(): - def __init__(self, NS, DS = None): + def __init__(self, NS: str, DS: str = None) -> None: pass class Zone: - def __init__(self, name, mail, NS, - secondary_refresh, secondary_retry, secondary_discard, - NX_TTL = None, A_TTL = None, other_TTL = None, - domains = []): + def __init__(self, name: str, mail: str, NS: List[str], + secondary_refresh: int, secondary_retry: int, secondary_discard: int, + NX_TTL: int = None, A_TTL: int = None, other_TTL: int = None, + domains: Dict[str, Any] = {}) -> None: self._name = hostname(name) if not mail.endswith('.'): raise Exception("Mail must be absolute, end with a dot") atpos = mail.find('@')