From cbb015a56ef66119ef47f323b3e23be9131a9f3c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 15 Jan 2004 11:32:25 +0000 Subject: [PATCH] Handled the ugly "timed out" error message. --- src/webutils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/webutils.py b/src/webutils.py index 230f7770e..3398c1573 100644 --- a/src/webutils.py +++ b/src/webutils.py @@ -42,18 +42,24 @@ class WebError(Exception): 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): """Gets a file-like object for a url.""" try: fd = urllib2.urlopen(url) return fd + except socket.timeout, e: + raise WebError, TIMED_OUT except socket.error, e: if e.args[0] == 111: - raise WebError, 'Connection refused.' + raise WebError, REFUSED elif e.args[0] in (110, 10060): - raise WebError, 'Connection timed out.' + raise WebError, TIMED_OUT elif e.args[0] == 104: - raise WebError, 'Connection reset by peer.' + raise WebError, RESET_BY_PEER else: raise WebError, str(e) except (urllib2.HTTPError, urllib2.URLError), e: