Web tool raise more IRCException

This commit is contained in:
nemunaire 2015-07-05 13:09:18 +02:00
parent 000c67e45e
commit 787a5fd3da
3 changed files with 8 additions and 15 deletions

View File

@ -14,7 +14,7 @@ def isup(url):
o = urllib.parse.urlparse("http://" + url) o = urllib.parse.urlparse("http://" + url)
if o.netloc != "": if o.netloc != "":
isup = getJSON("http://isitup.org/%s.json" % 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 isup["response_time"]
return None return None

View File

@ -24,11 +24,10 @@ class Message(Abstract):
"""Class storing hook information, specialized for a generic Message""" """Class storing hook information, specialized for a generic Message"""
def __init__(self, call, name=None, data=None, regexp=None, def __init__(self, call, name=None, regexp=None, channels=list(),
channels=list(), server=None, mtimes=-1, end_call=None): server=None, **kargs):
Abstract.__init__(self, call=call, data=data, Abstract.__init__(self, call=call, **kargs)
end_call=end_call, mtimes=mtimes)
self.name = name self.name = name
self.regexp = regexp self.regexp = regexp

View File

@ -83,7 +83,7 @@ def getURLContent(url, timeout=15):
elif o.scheme is None or o.scheme == "": elif o.scheme is None or o.scheme == "":
conn = http.client.HTTPConnection(o.hostname, port=80, timeout=timeout) conn = http.client.HTTPConnection(o.hostname, port=80, timeout=timeout)
else: else:
return None raise IRCException("Invalid URL")
import socket import socket
try: try:
@ -94,14 +94,8 @@ def getURLContent(url, timeout=15):
else: else:
conn.request("GET", o.path, None, {"User-agent": conn.request("GET", o.path, None, {"User-agent":
"Nemubot v%s" % __version__}) "Nemubot v%s" % __version__})
except socket.timeout: except OSError as e:
return None raise IRCException(e.strerror)
except OSError: # [Errno 113] No route to host
return None
except socket.gaierror:
print ("<tools.web> Unable to receive page %s on %s from %s."
% (o.path, o.netloc, url))
return None
try: try:
res = conn.getresponse() res = conn.getresponse()
@ -109,7 +103,7 @@ def getURLContent(url, timeout=15):
cntype = res.getheader("Content-Type") cntype = res.getheader("Content-Type")
if size > 524288 or (cntype is not None and cntype[:4] != "text" and cntype[:4] != "appl"): 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) data = res.read(size)