diff --git a/modules/networking/isup.py b/modules/networking/isup.py index f20276c..3b68a7f 100644 --- a/modules/networking/isup.py +++ b/modules/networking/isup.py @@ -14,7 +14,7 @@ def isup(url): o = urllib.parse.urlparse("http://" + url) if o.netloc != "": isup = getJSON("http://isitup.org/%s.json" % o.netloc) - if "status_code" in isup and isup["status_code"] == 1: + if isup is not None and "status_code" in isup and isup["status_code"] == 1: return isup["response_time"] return None diff --git a/nemubot/hooks/message.py b/nemubot/hooks/message.py index 65a2c0f..0844358 100644 --- a/nemubot/hooks/message.py +++ b/nemubot/hooks/message.py @@ -24,11 +24,10 @@ class Message(Abstract): """Class storing hook information, specialized for a generic Message""" - def __init__(self, call, name=None, data=None, regexp=None, - channels=list(), server=None, mtimes=-1, end_call=None): + def __init__(self, call, name=None, regexp=None, channels=list(), + server=None, **kargs): - Abstract.__init__(self, call=call, data=data, - end_call=end_call, mtimes=mtimes) + Abstract.__init__(self, call=call, **kargs) self.name = name self.regexp = regexp diff --git a/nemubot/tools/web.py b/nemubot/tools/web.py index 4f02289..23ae713 100644 --- a/nemubot/tools/web.py +++ b/nemubot/tools/web.py @@ -83,7 +83,7 @@ def getURLContent(url, timeout=15): elif o.scheme is None or o.scheme == "": conn = http.client.HTTPConnection(o.hostname, port=80, timeout=timeout) else: - return None + raise IRCException("Invalid URL") import socket try: @@ -94,14 +94,8 @@ def getURLContent(url, timeout=15): else: conn.request("GET", o.path, None, {"User-agent": "Nemubot v%s" % __version__}) - except socket.timeout: - return None - except OSError: # [Errno 113] No route to host - return None - except socket.gaierror: - print (" Unable to receive page %s on %s from %s." - % (o.path, o.netloc, url)) - return None + except OSError as e: + raise IRCException(e.strerror) try: res = conn.getresponse() @@ -109,7 +103,7 @@ def getURLContent(url, timeout=15): cntype = res.getheader("Content-Type") if size > 524288 or (cntype is not None and cntype[:4] != "text" and cntype[:4] != "appl"): - return None + raise IRCException("Content too large to be retrieved") data = res.read(size)