From: Ralf Jung Date: Tue, 11 Nov 2014 10:18:07 +0000 (+0100) Subject: fix for python 3.2 X-Git-Url: https://git.ralfj.de/zonemaker.git/commitdiff_plain/bacbf61b6595b9b8f733ea26be95b1ce45cdfb45?ds=inline fix for python 3.2 --- diff --git a/zone-maker b/zone-maker index 676bf9c..4a02e17 100755 --- a/zone-maker +++ b/zone-maker @@ -4,11 +4,17 @@ from zonemaker.zone import Zone #import typing def load_module(name, path, write_bytecode = False): - import importlib.machinery old_val = sys.dont_write_bytecode sys.dont_write_bytecode = not write_bytecode - module = importlib.machinery.SourceFileLoader(name, path).load_module() - sys.dont_write_bytecode = old_val + module = None + try: + from importlib.machinery import SourceFileLoader + module = SourceFileLoader(name, path).load_module() + except ImportError: + import imp + module = imp.load_source(name, path) + finally: + sys.dont_write_bytecode = old_val return module def make_zone(filename: str) -> None: diff --git a/zonemaker/zone.py b/zonemaker/zone.py index 4da0906..094c0f8 100644 --- a/zonemaker/zone.py +++ b/zonemaker/zone.py @@ -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")