Ticket #1028: feedgenerator_patch.diff
File feedgenerator_patch.diff, 5.4 KB (added by , 16 years ago) |
---|
-
feedgenerator.py
55 55 56 56 class SyndicationFeed(object): 57 57 "Base class for all syndication feeds. Subclasses should provide write()" 58 def __init__(self, title, link, description, language=None, author_email=None, 59 author_name=None, author_link=None, subtitle=None, categories=None, 60 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs): 58 def __init__(self, title, link, description, language=None, managing_editor=None, 59 webmaster=None, stylesheet=None, generator=None, image=None, 60 cloud=None, skip_hours=None, skip_days=None, author_email=None, 61 author_name=None, author_link=None, subtitle=None, categories=None, 62 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, 63 icon=None, **kwargs): 61 64 to_unicode = lambda s: force_unicode(s, strings_only=True) 62 65 if categories: 63 66 categories = [force_unicode(c) for c in categories] 67 if cloud: 68 cloud = dict([(force_unicode(k),force_unicode(v)) for k,v in cloud.items()]) 64 69 self.feed = { 65 70 'title': to_unicode(title), 66 71 'link': iri_to_uri(link), 67 72 'description': to_unicode(description), 68 73 'language': to_unicode(language), 74 'managing_editor': to_unicode(managing_editor), 75 'webmaster': to_unicode(webmaster), 76 'stylesheet': to_unicode(stylesheet), 77 'generator': to_unicode(generator), 78 'image': image, 79 'icon': icon, 80 'cloud': cloud, 81 'skip_hours': skip_hours, 82 'skip_days': skip_days, 69 83 'author_email': to_unicode(author_email), 70 84 'author_name': to_unicode(author_name), 71 85 'author_link': iri_to_uri(author_link), … … 178 192 def write(self, outfile, encoding): 179 193 handler = SimplerXMLGenerator(outfile, encoding) 180 194 handler.startDocument() 195 if self.feed['stylesheet'] is not None: 196 handler.processingInstruction(u"xml-stylesheet", 197 u'type="text/css" href="%s"' % self.feed['stylesheet']) 181 198 handler.startElement(u"rss", self.rss_attributes()) 182 199 handler.startElement(u"channel", self.root_attributes()) 183 200 self.add_root_elements(handler) … … 198 215 handler.addQuickElement(u"title", self.feed['title']) 199 216 handler.addQuickElement(u"link", self.feed['link']) 200 217 handler.addQuickElement(u"description", self.feed['description']) 218 handler.addQuickElement(u"generator", self.feed['generator']) 201 219 if self.feed['language'] is not None: 202 220 handler.addQuickElement(u"language", self.feed['language']) 203 221 for cat in self.feed['categories']: … … 207 225 handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('utf-8')) 208 226 if self.feed['ttl'] is not None: 209 227 handler.addQuickElement(u"ttl", self.feed['ttl']) 228 if self.feed['managing_editor'] is not None: 229 handler.addQuickElement(u"managingEditor", self.feed['managing_editor']) 230 if self.feed['webmaster'] is not None: 231 handler.addQuickElement(u"webMaster", self.feed['webmaster']) 232 if self.feed['image'] is not None: 233 handler.startElement(u"image", {}) 234 for k,v in self.feed['image'].items(): 235 handler.addQuickElement(force_unicode(k), force_unicode(v)) 236 handler.endElement(u"image") 237 if self.feed['cloud'] is not None: 238 handler.addQuickElement(u"cloud", attrs=self.feed['cloud']) 239 if self.feed['skip_hours'] is not None: 240 handler.startElement(u"skipHours", {}) 241 for h in self.feed['skip_hours']: 242 handler.addQuickElement(u"hour", force_unicode(h)) 243 handler.endElement(u"skipHours") 244 if self.feed['skip_days'] is not None: 245 handler.startElement(u"skipDays", {}) 246 for d in self.feed['skip_days']: 247 handler.addQuickElement(u"day", d) 248 handler.endElement(u"skipDays") 210 249 211 250 def endChannelElement(self, handler): 212 251 handler.endElement(u"channel") … … 264 303 def write(self, outfile, encoding): 265 304 handler = SimplerXMLGenerator(outfile, encoding) 266 305 handler.startDocument() 306 if self.feed['stylesheet']: 307 handler.processingInstruction(u"xml-stylesheet", 308 u'type="text/css" href="%s"' % self.feed['stylesheet']) 267 309 handler.startElement(u'feed', self.root_attributes()) 268 310 self.add_root_elements(handler) 269 311 self.write_items(handler) … … 280 322 handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']}) 281 323 if self.feed['feed_url'] is not None: 282 324 handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']}) 325 if self.feed['icon'] is not None: 326 handler.addQuickElement(u"icon",self.feed['icon']) 283 327 handler.addQuickElement(u"id", self.feed['id']) 284 328 handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('utf-8')) 285 329 if self.feed['author_name'] is not None: