From ad25f17639c92865cfbd355cba917b03fd2e75f4 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 29 May 2013 15:16:23 +0200 Subject: [PATCH] RSS: Add Python 3 support. --- plugins/RSS/plugin.py | 2 +- src/utils/web.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 0f8be9f0c..d05f65a5e 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -262,7 +262,7 @@ class RSS(callbacks.Plugin): try: self.log.debug('Downloading new feed from %u', url) results = feedparser.parse(url) - if 'bozo_exception' in results: + if 'bozo_exception' in results and not results['entries']: raise results['bozo_exception'] except feedparser.sgmllib.SGMLParseError: self.log.exception('Uncaught exception from feedparser:') diff --git a/src/utils/web.py b/src/utils/web.py index da8d6521b..94313c900 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -189,8 +189,15 @@ class HtmlToText(HTMLParser, object): def htmlToText(s, tagReplace=' '): """Turns HTML into text. tagReplace is a string to replace HTML tags with. """ - if sys.version_info[0] >= 3 and isinstance(s, bytes): - s = s.decode() + try: + import chardet + except ImportError: + s = s.decode('utf8') + else: + u = chardet.universaldetector.UniversalDetector() + u.feed(s) + u.close() + s = s.decode(u.result['encoding']) x = HtmlToText(tagReplace) x.feed(s) return x.getText()