diff options
author | Pacien TRAN-GIRARD | 2015-08-11 13:54:48 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-08-11 13:54:48 +0200 |
commit | 3fd5d61361275701fdfa65f62b5221aad4743905 (patch) | |
tree | f99acdb0fa76ca3965285226c6ed5b245a1e0295 | |
parent | ab3a2646acd4f085c892c0c93cc4beffa7901190 (diff) | |
download | afeedprocessor-3fd5d61361275701fdfa65f62b5221aad4743905.tar.gz |
Add support for CDATA in item description
-rw-r--r-- | afeedprocessor/adescription.py | 21 | ||||
-rw-r--r-- | afeedprocessor/anitemprocessor.py | 4 |
2 files changed, 24 insertions, 1 deletions
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 @@ | |||
1 | class Description: | ||
2 | def __init__(self, description): | ||
3 | self.tag = 'description' | ||
4 | self.description = description | ||
5 | |||
6 | def is_cdata(self): | ||
7 | if self.description is None: | ||
8 | return False | ||
9 | |||
10 | return self.description.startswith('<![CDATA[') and self.description.endswith(']]>') | ||
11 | |||
12 | def publish(self, handler): | ||
13 | handler.startElement(self.tag, {}) | ||
14 | |||
15 | if self.description is not None: | ||
16 | if self.is_cdata(): | ||
17 | handler._write(self.description) | ||
18 | else: | ||
19 | handler.characters(self.description) | ||
20 | |||
21 | 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 @@ | |||
1 | import PyRSS2Gen | 1 | import PyRSS2Gen |
2 | 2 | ||
3 | from afeedprocessor.adescription import Description | ||
4 | |||
3 | 5 | ||
4 | class ItemProcessor: | 6 | class ItemProcessor: |
5 | def get_title(self, title, item): | 7 | def get_title(self, title, item): |
@@ -36,7 +38,7 @@ class ItemProcessor: | |||
36 | return PyRSS2Gen.RSSItem( | 38 | return PyRSS2Gen.RSSItem( |
37 | title=self.get_title(item.title, item), | 39 | title=self.get_title(item.title, item), |
38 | link=self.get_link(item.link, item), | 40 | link=self.get_link(item.link, item), |
39 | description=self.get_description(item.description, item), | 41 | description=Description(self.get_description(item.description, item)), |
40 | author=self.get_author(item.author, item), | 42 | author=self.get_author(item.author, item), |
41 | categories=self.get_categories(item.categories, item), | 43 | categories=self.get_categories(item.categories, item), |
42 | comments=self.get_comments(item.comments, item), | 44 | comments=self.get_comments(item.comments, item), |