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. 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: for line in fd:
(name, version) = line.split(':') (name, version) = line.split(':')
if 'latest stable' in name: if 'latest stable' in name:

View File

@ -39,10 +39,10 @@ import urllib2
class WebException(Exception): class WebException(Exception):
pass pass
def getUrl(url, size=None): def getUrlFd(url):
"""Gets a page. Returns a string that is the page gotten."""
try: try:
fd = urllib2.urlopen(url) fd = urllib2.urlopen(url)
return fd
except socket.error, e: except socket.error, e:
if e.args[0] == 111: if e.args[0] == 111:
raise WebException, 'Connection refused.' raise WebException, 'Connection refused.'
@ -52,6 +52,10 @@ def getUrl(url, size=None):
raise WebException, str(e) raise WebException, str(e)
except (urllib2.HTTPError, urllib2.URLError), e: except (urllib2.HTTPError, urllib2.URLError), e:
raise WebException, str(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: if size is None:
text = fd.read() text = fd.read()
else: else: