Web tool raise more IRCException
This commit is contained in:
parent
000c67e45e
commit
787a5fd3da
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 ("<tools.web> 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user