From: Adam Sampson Date: Mon, 15 Sep 2014 22:09:29 +0000 (+0100) Subject: Be more flexible when looking for "timed out" exceptions. X-Git-Tag: v2.20~1 X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=39af00f498ac98ed06c7080214d2106ad016ddc5;p=rawdog%2F.git Be more flexible when looking for "timed out" exceptions. Debian sid's current Python package produces slightly different exceptions from stock Python, which caused this check to fail. I've moved the check out to a function, which'll now match anything with "timeout", "time out" or "timed out" in it. --- diff --git a/NEWS b/NEWS index 870215e..a578f84 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,11 @@ Add a test for the maxage option (suggested by joelmo). Add a rule to style.css to scale down large images. +When looking for SSL timeout exceptions, match any form of "timeout", +"time out" or "timed out" in the message. This makes rawdog detect SSL +connection timeouts correctly with Debian's Python 2.7.8 package +(reported by David Suárez). + - rawdog 2.19 Make test-rawdog not depend on having a host it can test connection diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 9947def..fe1bc23 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -325,6 +325,25 @@ def ensure_unicode(value, encoding): else: return value +timeout_re = re.compile(r'timed? ?out', re.I) +def is_timeout_exception(exc): + """Return True if the given exception object suggests that a timeout + occurred, else return False.""" + + # Since urlopen throws away the original exception object, + # we have to look at the stringified form to tell if it was a timeout. + # (We're in reasonable company here, since test_ssl.py in the Python + # distribution does the same thing!) + # + # The message we're looking for is something like: + # Stock Python 2.7.7 and 2.7.8: + # + # Debian python 2.7.3-4+deb7u1: + # + # Debian python 2.7.8-1: + # + return (timeout_re.search(str(exc)) is not None) + class BasicAuthProcessor(urllib2.BaseHandler): """urllib2 handler that does HTTP basic authentication or proxy authentication with a fixed username and password. @@ -516,7 +535,7 @@ class Feed: if got_urlerror or got_timeout: # urllib2 reported an error when fetching the feed. # Check to see if it was a timeout. - if not (got_timeout or str(bozo_exception).endswith("timed out>")): + if not (got_timeout or is_timeout_exception(bozo_exception)): errors.append("Error while fetching feed:") errors.append(str(bozo_exception)) errors.append("")