From 9337881574f8f9370fecabfeb9a52e4341568cd9 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Mon, 3 Mar 2008 15:08:11 +0000 Subject: [PATCH] Fix some entity handling * fixes handling of numeric entities * fixes unittest for entities. --- rss2maildir.py | 7 +++++-- tests/expected/entities.txt | 2 +- tests/html/entities.html | 2 +- tests/unittests/EntityTests.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rss2maildir.py b/rss2maildir.py index 47ba9dc..9473dd0 100755 --- a/rss2maildir.py +++ b/rss2maildir.py @@ -556,12 +556,15 @@ class HTML2Text(HTMLParser): self.opentags.append(u'p') self.curdata = self.curdata + data.decode("utf-8") + def handle_charref(self, name): + entity = unichr(int(name)) + self.curdata = self.curdata + unicode(entity.encode('utf-8'), \ + "utf-8") + def handle_entityref(self, name): entity = name if HTML2Text.entities.has_key(name): entity = HTML2Text.entities[name] - elif name[0] == "#": - entity = unichr(int(name[1:])) else: entity = "&" + name + ";" diff --git a/tests/expected/entities.txt b/tests/expected/entities.txt index 20e85cd..72d5d3a 100644 --- a/tests/expected/entities.txt +++ b/tests/expected/entities.txt @@ -1 +1 @@ -áÞö +áÞö’ diff --git a/tests/html/entities.html b/tests/html/entities.html index 77fd2ca..6b19183 100644 --- a/tests/html/entities.html +++ b/tests/html/entities.html @@ -1 +1 @@ -

áÞö

+

áÞö’

diff --git a/tests/unittests/EntityTests.py b/tests/unittests/EntityTests.py index b317f4d..3b6ec3d 100755 --- a/tests/unittests/EntityTests.py +++ b/tests/unittests/EntityTests.py @@ -11,7 +11,7 @@ class EntityTests(ParsingTests.ParsingTest): def suite(): suite = unittest.TestSuite() - suite.addTest(SpacingTests("testEntities")) + suite.addTest(EntityTests("testEntities")) return suite if __name__ == "__main__": -- 2.39.5