Support of different types of content
Now the content element now supports the type attribute and the content is encoded accordingly: - text and html are escaped - xhtml is surrounded with a div and then included as XML - XML is directly included - base64 support was *not* added. Please file a bug if you need it
This commit is contained in:
parent
30b61940b7
commit
8b18122cfd
1 changed files with 22 additions and 2 deletions
|
@ -95,10 +95,28 @@ class FeedEntry(object):
|
||||||
|
|
||||||
if self.__atom_content:
|
if self.__atom_content:
|
||||||
content = etree.SubElement(entry, 'content')
|
content = etree.SubElement(entry, 'content')
|
||||||
|
type = self.__atom_content.get('type')
|
||||||
if self.__atom_content.get('src'):
|
if self.__atom_content.get('src'):
|
||||||
content.attrib['src'] = self.__atom_content['src']
|
content.attrib['src'] = self.__atom_content['src']
|
||||||
elif self.__atom_content.get('content'):
|
elif self.__atom_content.get('content'):
|
||||||
content.text = self.__atom_content.get('content')
|
# Surround xhtml with a div tag, parse it and embed it
|
||||||
|
if type == 'xhtml':
|
||||||
|
content.append(etree.fromstring('''<div
|
||||||
|
xmlns="http://www.w3.org/1999/xhtml">%s</div>''' % \
|
||||||
|
self.__atom_content.get('content')))
|
||||||
|
# Parse XML and embed it
|
||||||
|
elif type.endswith('/xml') or type.endswith('+xml'):
|
||||||
|
content.append(etree.fromstring(self.__atom_content['content']))
|
||||||
|
# Emed the text in escaped form
|
||||||
|
elif not type or type.startswith('text') or type == 'html':
|
||||||
|
content.text = self.__atom_content.get('content')
|
||||||
|
# Everything else should be included base64 encoded
|
||||||
|
else:
|
||||||
|
raise ValueError('base64 encoded content is not supported at the moment.'
|
||||||
|
+ 'If you are interested , please file a bug report.')
|
||||||
|
# Add type description of the content
|
||||||
|
if type:
|
||||||
|
content.attrib['type'] = type
|
||||||
|
|
||||||
for l in self.__atom_link or []:
|
for l in self.__atom_link or []:
|
||||||
link = etree.SubElement(entry, 'link', href=l['href'])
|
link = etree.SubElement(entry, 'link', href=l['href'])
|
||||||
|
@ -311,7 +329,7 @@ class FeedEntry(object):
|
||||||
return self.__atom_author
|
return self.__atom_author
|
||||||
|
|
||||||
|
|
||||||
def content(self, content=None, src=None):
|
def content(self, content=None, src=None, type=None):
|
||||||
'''Get or set the cntent of the entry which contains or links to the
|
'''Get or set the cntent of the entry which contains or links to the
|
||||||
complete content of the entry. Content must be provided for ATOM entries
|
complete content of the entry. Content must be provided for ATOM entries
|
||||||
if there is no alternate link, and should be provided if there is no
|
if there is no alternate link, and should be provided if there is no
|
||||||
|
@ -326,6 +344,8 @@ class FeedEntry(object):
|
||||||
self.__atom_content = {'src':src}
|
self.__atom_content = {'src':src}
|
||||||
elif not content is None:
|
elif not content is None:
|
||||||
self.__atom_content = {'content':content}
|
self.__atom_content = {'content':content}
|
||||||
|
if not type is None:
|
||||||
|
self.__atom_content['type'] = type
|
||||||
self.__rss_description = content
|
self.__rss_description = content
|
||||||
return self.__atom_content
|
return self.__atom_content
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue