X-Git-Url: https://git.ralfj.de/zonemaker.git/blobdiff_plain/68f7e70558cf818f97f0bcb0ea80994d4abc5a71..e755148dea6ccfd48ee64670bd2f59f311dde159:/zonemaker/zone.py?ds=inline diff --git a/zonemaker/zone.py b/zonemaker/zone.py index d9c14e9..add2bde 100644 --- a/zonemaker/zone.py +++ b/zonemaker/zone.py @@ -1,5 +1,5 @@ import re, datetime -import typing +#from typing import * second = 1 @@ -13,12 +13,14 @@ REGEX_ipv4 = r'^\d{1,3}(\.\d{1,3}){3}$' REGEX_ipv6 = r'^[a-fA-F0-9]{1,4}(:[a-fA-F0-9]{1,4}){7}$' def check_label(label: str) -> str: + label = str(label) pattern = r'^{0}$'.format(REGEX_label) if re.match(pattern, label): return label raise Exception(label+" is not a valid label") def check_hostname(name: str) -> str: + name = str(name) # check hostname for validity pattern = r'^{0}(\.{0})*\.?$'.format(REGEX_label) if re.match(pattern, name): @@ -26,16 +28,19 @@ def check_hostname(name: str) -> str: raise Exception(name+" is not a valid hostname") def check_hex(data: str) -> str: + data = str(data) if re.match('^[a-fA-F0-9]+$', data): return data raise Exception(data+" is not valid hex data") def check_ipv4(address: str) -> str: + address = str(address) if re.match(REGEX_ipv4, address): return address raise Exception(address+" is not a valid IPv4 address") def check_ipv6(address: str) -> str: + address = str(address) if re.match(REGEX_ipv6, address): return address raise Exception(address+" is not a valid IPv6 address") @@ -253,7 +258,7 @@ class Zone: try: with open(self._serialfile) as f: cur_serial = int(f.read()) - except FileNotFoundError: + except (OSError, IOError): # FileNotFoundError has been added in Python 3.3 pass # increment serial cur_serial += 1