Commit 39dda3fa authored by Alexandre's avatar Alexandre
Browse files

Catch custom raised exceptions

parent 40f90ff5
......@@ -169,6 +169,10 @@ def validate_hostname(hostname, cert):
return False
class CustomException(Exception):
pass
class RequestDoT:
def __init__(self, qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=use_edns, want_dnssec=want_dnssec)
......@@ -253,7 +257,7 @@ class Connection:
if not dot and not is_valid_url(url):
error("DoH requires a valid HTTPS URL, not \"%s\"" % server)
if forceIPv4 and forceIPv6:
raise Exception("Force IPv4 *or* IPv6 but not both")
raise CustomException("Force IPv4 *or* IPv6 but not both")
self.server = server
self.servername = servername
if self.servername is not None:
......@@ -270,11 +274,11 @@ class Connection:
def check_ip_address(self, addr):
(is_addr, self.family) = is_valid_ip_address(addr)
if not is_addr and not self.dot:
raise Exception("%s is not IPv4 and not IPv6" % addr)
raise CustomException("%s is not IPv4 and not IPv6" % addr)
if forceIPv4 and self.family == 6:
raise Exception("You cannot force IPv4 with a litteral IPv6 address (%s)" % addr)
raise CustomException("You cannot force IPv4 with a litteral IPv6 address (%s)" % addr)
elif forceIPv6 and self.family == 4:
raise Exception("You cannot force IPv6 with a litteral IPv4 address (%s)" % addr)
raise CustomException("You cannot force IPv6 with a litteral IPv4 address (%s)" % addr)
if forceIPv4 or self.family == 4:
self.family = socket.AF_INET
self.repraddress = addr
......@@ -603,6 +607,8 @@ except TimeoutError:
error("timeout")
except ConnectionRefusedError:
error("Connection to server refused")
except CustomException as e:
error(e)
if ifile is not None:
input = open(ifile)
for i in range (0, tests):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment