Added getUrlFd, used it in Http.kernel.

This commit is contained in:
Jeremy Fincher 2003-12-02 11:10:31 +00:00
parent 4e5e568244
commit 2f1c8415b6
2 changed files with 7 additions and 3 deletions

View File

@ -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:

View File

@ -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: