1.1 --- a/MoinShare.py Mon Mar 31 23:56:56 2014 +0200
1.2 +++ b/MoinShare.py Tue Apr 01 22:17:37 2014 +0200
1.3 @@ -182,7 +182,7 @@
1.4 class FeedContentTypeError(FeedError):
1.5 pass
1.6
1.7 -# Feed retrieval from URLs.
1.8 +# Update retrieval from URLs.
1.9
1.10 def getUpdates(request, feed_url, max_entries, show_content):
1.11
1.12 @@ -197,7 +197,10 @@
1.13 returned.
1.14 """
1.15
1.16 - feed_updates = []
1.17 + # Prevent local file access.
1.18 +
1.19 + if feed_url.startswith("file:"):
1.20 + raise FeedMissingError
1.21
1.22 # Obtain the resource, using a cached version if appropriate.
1.23
1.24 @@ -208,11 +211,34 @@
1.25
1.26 # Interpret the cached feed.
1.27
1.28 - feed = StringIO(data)
1.29 - _url, content_type, _encoding, _metadata = getCachedResourceMetadata(feed)
1.30 + f = StringIO(data)
1.31 + try:
1.32 + _url, content_type, _encoding, _metadata = getCachedResourceMetadata(f)
1.33 +
1.34 + if content_type in ("application/atom+xml", "application/rss+xml", "application/xml"):
1.35 + return getUpdatesFromFeed(f, max_entries, show_content)
1.36 + else:
1.37 + raise FeedContentTypeError
1.38 +
1.39 + finally:
1.40 + f.close()
1.41 +
1.42 +# Update retrieval from feeds.
1.43
1.44 - if content_type not in ("application/atom+xml", "application/rss+xml", "application/xml"):
1.45 - raise FeedContentTypeError
1.46 +def getUpdatesFromFeed(feed, max_entries, show_content):
1.47 +
1.48 + """
1.49 + Retrieve from 'feed' up to the given number 'max_entries' of update entries.
1.50 + The 'show_content' parameter can indicate that a "summary" is to be obtained
1.51 + for each update, that the "content" of each update is to be obtained
1.52 + (falling back to a summary if no content is provided), or no content
1.53 + (indicated by a false value) is to be obtained.
1.54 +
1.55 + A tuple of the form ((feed_type, channel_title, channel_link), updates) is
1.56 + returned.
1.57 + """
1.58 +
1.59 + feed_updates = []
1.60
1.61 try:
1.62 # Parse each node from the feed.