From 3fd5d61361275701fdfa65f62b5221aad4743905 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 11 Aug 2015 13:54:48 +0200 Subject: Add support for CDATA in item description --- afeedprocessor/adescription.py | 21 +++++++++++++++++++++ afeedprocessor/anitemprocessor.py | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 afeedprocessor/adescription.py diff --git a/afeedprocessor/adescription.py b/afeedprocessor/adescription.py new file mode 100644 index 0000000..7bc1aa7 --- /dev/null +++ b/afeedprocessor/adescription.py @@ -0,0 +1,21 @@ +class Description: + def __init__(self, description): + self.tag = 'description' + self.description = description + + def is_cdata(self): + if self.description is None: + return False + + return self.description.startswith('') + + def publish(self, handler): + handler.startElement(self.tag, {}) + + if self.description is not None: + if self.is_cdata(): + handler._write(self.description) + else: + handler.characters(self.description) + + handler.endElement(self.tag) diff --git a/afeedprocessor/anitemprocessor.py b/afeedprocessor/anitemprocessor.py index 3f0eabc..f281e15 100644 --- a/afeedprocessor/anitemprocessor.py +++ b/afeedprocessor/anitemprocessor.py @@ -1,5 +1,7 @@ import PyRSS2Gen +from afeedprocessor.adescription import Description + class ItemProcessor: def get_title(self, title, item): @@ -36,7 +38,7 @@ class ItemProcessor: return PyRSS2Gen.RSSItem( title=self.get_title(item.title, item), link=self.get_link(item.link, item), - description=self.get_description(item.description, item), + description=Description(self.get_description(item.description, item)), author=self.get_author(item.author, item), categories=self.get_categories(item.categories, item), comments=self.get_comments(item.comments, item), -- cgit v1.2.3