When we hit an exception trying to unwind any redirects, just print
the exception and leave the link with its original value.
This commit also alphabetizes the standard library imports, and splits
off the local import following PEP 8's suggested groupings [1].
[1]: http://legacy.python.org/dev/peps/pep-0008/#imports
Signed-off-by: W. Trevor King <wking@tremily.us>
This hook finds and uses the real url behind redirects.
"""
-import urllib
+import logging
import re
+import urllib
+
import rss2email
+
+LOG = _logging.getLogger(__name__)
+
+
def process(feed, parsed, entry, guid, message):
# decode message
encoding = message.get_charsets()[0]
request = urllib.request.Request(link)
request.add_header('User-agent', rss2email.feed._USER_AGENT)
direct_link = urllib.request.urlopen(request).geturl()
- except:
+ except Exception as e:
+ LOG.warning('could not follow redirect for {}: {}'.format(
+ linke, e))
continue
content = re.sub(re.escape(link), direct_link, content, re.MULTILINE)