Skip to content

Commit

Permalink
Merge c6c7165 into 1b301f6
Browse files Browse the repository at this point in the history
  • Loading branch information
lkiesow committed Aug 12, 2018
2 parents 1b301f6 + c6c7165 commit e98a084
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions feedgen/entry.py
Expand Up @@ -173,6 +173,15 @@ def atom_entry(self, extensions=True):
rights = etree.SubElement(entry, 'rights')
rights.text = self.__atom_rights

if self.__atom_source:
source = etree.SubElement(entry, 'source')
if self.__atom_source.get('title'):
source_title = etree.SubElement(source, 'title')
source_title.text = self.__atom_source['title']
if self.__atom_source.get('link'):
etree.SubElement(source, 'link',
href=self.__atom_source['link'])

if extensions:
for ext in self.__extensions.values() or []:
if ext.get('atom'):
Expand Down Expand Up @@ -233,6 +242,10 @@ def rss_entry(self, extensions=True):
if self.__rss_pubDate:
pubDate = etree.SubElement(entry, 'pubDate')
pubDate.text = formatRFC2822(self.__rss_pubDate)
if self.__rss_source:
source = etree.SubElement(entry, 'source',
url=self.__rss_source['url'])
source.text = self.__rss_source['title']

if extensions:
for ext in self.__extensions.values() or []:
Expand Down Expand Up @@ -614,6 +627,22 @@ def comments(self, comments=None):
self.__rss_comments = comments
return self.__rss_comments

def source(self, url=None, title=None):
'''Get or set the source for the current feed entry.
Note that ATOM feeds support a lot more sub elements than title and URL
(which is what RSS supports) but these are currently not supported.
Patches are welcome.
:param url: Link to the source.
:param title: Title of the linked resource
:returns: Source element as dictionaries.
'''
if url is not None and title is not None:
self.__rss_source = {'url': url, 'title': title}
self.__atom_source = {'link': url, 'title': title}
return self.__rss_source

def enclosure(self, url=None, length=None, type=None):
'''Get or set the value of enclosure which describes a media object
that is attached to the item. This is a RSS only value which is
Expand Down
3 changes: 3 additions & 0 deletions tests/test_entry.py
Expand Up @@ -91,6 +91,9 @@ def test_TestEntryItems(self):
assert fe.pubDate().year == 2017
fe.rights('asdfx')
assert fe.rights() == 'asdfx'
source = fe.source(url='https://example.com', title='Test')
assert source.get('title') == 'Test'
assert source.get('url') == 'https://example.com'
fe.comments('asdfx')
assert fe.comments() == 'asdfx'
fe.enclosure(url='http://lkiesow.de', type='text/plain', length='1')
Expand Down

0 comments on commit e98a084

Please sign in to comment.