From 14dc0c0201ad69c5d2ff15dea7b68d34c9ad3566 Mon Sep 17 00:00:00 2001 From: James Vega Date: Thu, 7 Jul 2005 14:13:53 +0000 Subject: [PATCH] plugins/RSS: If the feed supplies an encoding, encode the headlines with it. --- plugins/RSS/plugin.py | 6 +++++- plugins/RSS/test.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 00103c4dc..b3e66a012 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -256,9 +256,13 @@ class RSS(callbacks.Plugin): def getHeadlines(self, feed): headlines = [] + if 'encoding' in feed: + conv = lambda s: s.encode(feed['encoding'], 'replace') + else: + conv = lambda s: s for d in feed['items']: if 'title' in d: - title = utils.web.htmlToText(d['title']).strip() + title = conv(utils.web.htmlToText(d['title']).strip()) link = d.get('link') if link: headlines.append((title, link)) diff --git a/plugins/RSS/test.py b/plugins/RSS/test.py index 4cb73c759..7f3b8c435 100644 --- a/plugins/RSS/test.py +++ b/plugins/RSS/test.py @@ -75,6 +75,10 @@ class RSSTestCase(ChannelPluginTestCase): self.assertError('advogato') self.assertError('rss advogato') + def testNonAsciiFeeds(self): + self.assertNotError('rss http://www.heise.de/newsticker/heise.rdf') + self.assertNotError('rss http://www.golem.de/rss.php?feed=ATOM0.3') + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: