mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +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.
|
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:
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user