feed: Add herror to _SOCKET_ERRORS and remove reason handing
authorW. Trevor King <wking@tremily.us>
Thu, 21 Mar 2013 15:07:57 +0000 (11:07 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 21 Mar 2013 15:07:57 +0000 (11:07 -0400)
We don't log the reason, so trying to extract it just gives room for
errors to creep in.  Luckily, we'll be able to drop the whole
_SOCKET_ERRORS thing when we move to Python >= 3.3, because following
PEP 3151 the socket errors became subclasses of OSError.

Reported-by: Matt Bordignon <matthew@bordignons.net>
Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/feed.py

index e5f962da272a77f84d4cf96fff52a6aac8cd6204..23b914ad6147712d56100f34b8fa8d94ff26e73c 100644 (file)
@@ -55,7 +55,7 @@ from . import util as _util
 _feedparser.USER_AGENT = 'rss2email/{} +{}'.format(__version__, __url__)
 _urllib_request.install_opener(_urllib_request.build_opener())
 _SOCKET_ERRORS = []
-for e in ['error', 'gaierror']:
+for e in ['error', 'herror', 'gaierror']:
     if hasattr(_socket, e):
         _SOCKET_ERRORS.append(getattr(_socket, e))
 del e  # cleanup namespace
@@ -363,16 +363,10 @@ class Feed (object):
         if isinstance(exc, _socket.timeout):
             _LOG.error('timed out: {}'.format(self))
             warned = True
-        elif isinstance(exc, _SOCKET_ERRORS):
-            reason = exc.args[1]
+        elif isinstance(exc, OSError):
             _LOG.error('{}: {}'.format(exc, self))
             warned = True
-        elif (hasattr(exc, 'reason') and
-              isinstance(exc.reason, _urllib_error.URLError)):
-            if isinstance(exc.reason, _SOCKET_ERRORS):
-                reason = exc.reason.args[1]
-            else:
-                reason = exc.reason
+        elif isinstance(exc, _SOCKET_ERRORS):
             _LOG.error('{}: {}'.format(exc, self))
             warned = True
         elif isinstance(exc, _feedparser.zlib.error):