mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Handled the ugly "timed out" error message.
This commit is contained in:
parent
4db8dfb773
commit
cbb015a56e
@ -42,18 +42,24 @@ class WebError(Exception):
|
|||||||
|
|
||||||
urlRe = re.compile(r"(\w+://[^\])>\s]+)", re.I)
|
urlRe = re.compile(r"(\w+://[^\])>\s]+)", re.I)
|
||||||
|
|
||||||
|
REFUSED = 'Connection refused.'
|
||||||
|
TIMED_OUT = 'Connection timed out.'
|
||||||
|
RESET_BY_PEER = 'Connection reset by peer.'
|
||||||
|
|
||||||
def getUrlFd(url):
|
def getUrlFd(url):
|
||||||
"""Gets a file-like object for a url."""
|
"""Gets a file-like object for a url."""
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen(url)
|
fd = urllib2.urlopen(url)
|
||||||
return fd
|
return fd
|
||||||
|
except socket.timeout, e:
|
||||||
|
raise WebError, TIMED_OUT
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e.args[0] == 111:
|
if e.args[0] == 111:
|
||||||
raise WebError, 'Connection refused.'
|
raise WebError, REFUSED
|
||||||
elif e.args[0] in (110, 10060):
|
elif e.args[0] in (110, 10060):
|
||||||
raise WebError, 'Connection timed out.'
|
raise WebError, TIMED_OUT
|
||||||
elif e.args[0] == 104:
|
elif e.args[0] == 104:
|
||||||
raise WebError, 'Connection reset by peer.'
|
raise WebError, RESET_BY_PEER
|
||||||
else:
|
else:
|
||||||
raise WebError, str(e)
|
raise WebError, str(e)
|
||||||
except (urllib2.HTTPError, urllib2.URLError), e:
|
except (urllib2.HTTPError, urllib2.URLError), e:
|
||||||
|
Loading…
Reference in New Issue
Block a user