Package turbogears :: Package feed :: Module feed

Source Code for Module turbogears.feed.feed

 1  """The 'turbogears.feed' package is deprecated in TurboGears >= 1.1. 
 2   
 3  It will be REMOVED in TurboGears >= 1.5! 
 4   
 5  Please use the TurboFeeds extension <http://python.org/pypi/TurboFeeds> instead. 
 6   
 7  """ 
 8  import time 
 9  from warnings import warn 
10   
11  import cherrypy 
12  import turbogears 
13   
14   
15 -class FeedController(turbogears.controllers.Controller):
16 """ Object for generating feeds in multiple formats """ 17
18 - def __init__(self, default="atom1.0"):
19 warnings.warn(__doc__, DeprecationWarning) 20 self.default = default 21 self.formats = ["atom1.0", "atom0.3", "rss2.0"]
22
23 - def date_to_3339(self, date):
24 date = date.strftime("%Y-%m-%dT%H:%M:%SZ") 25 return date
26
27 - def date_to_822(self, date):
28 date = date.strftime("%a, %d %b %Y %H:%M:%S GMT") 29 return date
30
31 - def depr_entrys(self, feed):
32 if "entrys" in feed: 33 warn("You should use 'entries' instead of 'entrys'", 34 DeprecationWarning, 3) 35 feed['entries'] = feed['entrys'] 36 del feed['entrys']
37
38 - def format_dates(self, feed, format):
39 if format == 822: 40 convert_date = self.date_to_822 41 else: 42 convert_date = self.date_to_3339 43 if feed.has_key('updated'): 44 feed["updated"] = convert_date(feed["updated"]) 45 self.depr_entrys(feed) 46 for entry in feed['entries']: 47 if entry.has_key('updated'): 48 entry["updated"] = convert_date(entry["updated"]) 49 if entry.has_key('published'): 50 entry["published"] = convert_date(entry["published"]) 51 return feed
52
53 - def index(self, **kwargs):
54 turbogears.redirect("%s" % self.default, kwargs)
55 index = turbogears.expose()(index) 56
57 - def atom1_0(self, **kwargs):
58 feed = self.get_feed_data(**kwargs) 59 self.format_dates(feed, 3339) 60 feed["href"] = turbogears.url("/") + "atom1.0" 61 self.depr_entrys(feed) 62 return feed
63 atom1_0 = turbogears.expose(template="kid:turbogears.feed.atom1_0", 64 format="xml", content_type="application/atom+xml")(atom1_0) 65
66 - def atom0_3(self, **kwargs):
67 feed = self.get_feed_data(**kwargs) 68 self.format_dates(feed, 3339) 69 feed["href"] = turbogears.url("/") + "atom0.3" 70 self.depr_entrys(feed) 71 return feed
72 atom0_3 = turbogears.expose(template="kid:turbogears.feed.atom0_3", 73 format="xml", content_type="application/atom+xml")(atom0_3) 74
75 - def rss2_0(self, **kwargs):
76 feed = self.get_feed_data(**kwargs) 77 self.format_dates(feed, 822) 78 self.depr_entrys(feed) 79 return feed
80 rss2_0 = turbogears.expose(template="kid:turbogears.feed.rss2_0", 81 format="xml", content_type="application/rss+xml")(rss2_0)
82