#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:
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):
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")