diff --git a/plugins/Http.py b/plugins/Http.py index 94dcd6a17..2977b144d 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -311,7 +311,7 @@ class Http(callbacks.Privmsg): Returns information about the current version of the Linux kernel. """ - fd = urllib2.urlopen('http://www.kernel.org/kdist/finger_banner') + fd = webutils.getUrlFd('http://www.kernel.org/kdist/finger_banner') for line in fd: (name, version) = line.split(':') if 'latest stable' in name: diff --git a/src/webutils.py b/src/webutils.py index b43b30362..628fd79a6 100644 --- a/src/webutils.py +++ b/src/webutils.py @@ -39,10 +39,10 @@ import urllib2 class WebException(Exception): pass -def getUrl(url, size=None): - """Gets a page. Returns a string that is the page gotten.""" +def getUrlFd(url): try: fd = urllib2.urlopen(url) + return fd except socket.error, e: if e.args[0] == 111: raise WebException, 'Connection refused.' @@ -52,6 +52,10 @@ def getUrl(url, size=None): raise WebException, str(e) except (urllib2.HTTPError, urllib2.URLError), e: raise WebException, str(e) + +def getUrl(url, size=None): + """Gets a page. Returns a string that is the page gotten.""" + fd = getUrlFd(url) if size is None: text = fd.read() else: