mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-03-11 00:40:39 +01:00
Updated slightly.
This commit is contained in:
parent
1654a35766
commit
e64ce62917
@ -45,8 +45,25 @@ urlRe = re.compile(r"(\w+://[^\])>\s]+)", re.I)
|
|||||||
|
|
||||||
REFUSED = 'Connection refused.'
|
REFUSED = 'Connection refused.'
|
||||||
TIMED_OUT = 'Connection timed out.'
|
TIMED_OUT = 'Connection timed out.'
|
||||||
|
UNKNOWN_HOST = 'Unknown host.'
|
||||||
RESET_BY_PEER = 'Connection reset by peer.'
|
RESET_BY_PEER = 'Connection reset by peer.'
|
||||||
|
|
||||||
|
def strError(e):
|
||||||
|
try:
|
||||||
|
n = e.args[0]
|
||||||
|
except Exception:
|
||||||
|
return str(e)
|
||||||
|
if n == 111:
|
||||||
|
return REFUSED
|
||||||
|
elif n in (110, 10060):
|
||||||
|
return TIMED_OUT
|
||||||
|
elif n == 104:
|
||||||
|
return RESET_BY_PEER
|
||||||
|
elif n == 8:
|
||||||
|
return UNKNOWN_HOST
|
||||||
|
else:
|
||||||
|
return str(e)
|
||||||
|
|
||||||
def getUrlFd(url):
|
def getUrlFd(url):
|
||||||
"""Gets a file-like object for a url."""
|
"""Gets a file-like object for a url."""
|
||||||
try:
|
try:
|
||||||
@ -55,15 +72,10 @@ def getUrlFd(url):
|
|||||||
except socket.timeout, e:
|
except socket.timeout, e:
|
||||||
raise WebError, TIMED_OUT
|
raise WebError, TIMED_OUT
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e.args[0] == 111:
|
raise WebError, strError(e)
|
||||||
raise WebError, REFUSED
|
except urllib2.URLError, e:
|
||||||
elif e.args[0] in (110, 10060):
|
raise WebError, strError(e.reason)
|
||||||
raise WebError, TIMED_OUT
|
except urllib2.HTTPError, e:
|
||||||
elif e.args[0] == 104:
|
|
||||||
raise WebError, RESET_BY_PEER
|
|
||||||
else:
|
|
||||||
raise WebError, str(e)
|
|
||||||
except (urllib2.HTTPError, urllib2.URLError), e:
|
|
||||||
raise WebError, str(e)
|
raise WebError, str(e)
|
||||||
|
|
||||||
def getUrl(url, size=None):
|
def getUrl(url, size=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user