mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Added getUrlFd, used it in Http.kernel.
This commit is contained in:
parent
4e5e568244
commit
2f1c8415b6
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user