Ticket #1028: feedgenerator_patch.diff

File feedgenerator_patch.diff, 5.4 KB (added by taojian, 6 years ago)
  • feedgenerator.py

     
    5555
    5656class SyndicationFeed(object):
    5757    "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):
    6164        to_unicode = lambda s: force_unicode(s, strings_only=True)
    6265        if categories:
    6366            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()])
    6469        self.feed = {
    6570            'title': to_unicode(title),
    6671            'link': iri_to_uri(link),
    6772            'description': to_unicode(description),
    6873            '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,
    6983            'author_email': to_unicode(author_email),
    7084            'author_name': to_unicode(author_name),
    7185            'author_link': iri_to_uri(author_link),
     
    178192    def write(self, outfile, encoding):
    179193        handler = SimplerXMLGenerator(outfile, encoding)
    180194        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'])
    181198        handler.startElement(u"rss", self.rss_attributes())
    182199        handler.startElement(u"channel", self.root_attributes())
    183200        self.add_root_elements(handler)
     
    198215        handler.addQuickElement(u"title", self.feed['title'])
    199216        handler.addQuickElement(u"link", self.feed['link'])
    200217        handler.addQuickElement(u"description", self.feed['description'])
     218        handler.addQuickElement(u"generator", self.feed['generator'])
    201219        if self.feed['language'] is not None:
    202220            handler.addQuickElement(u"language", self.feed['language'])
    203221        for cat in self.feed['categories']:
     
    207225        handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('utf-8'))
    208226        if self.feed['ttl'] is not None:
    209227            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")
    210249
    211250    def endChannelElement(self, handler):
    212251        handler.endElement(u"channel")
     
    264303    def write(self, outfile, encoding):
    265304        handler = SimplerXMLGenerator(outfile, encoding)
    266305        handler.startDocument()
     306        if self.feed['stylesheet']:
     307            handler.processingInstruction(u"xml-stylesheet",
     308                                      u'type="text/css" href="%s"' % self.feed['stylesheet'])           
    267309        handler.startElement(u'feed', self.root_attributes())
    268310        self.add_root_elements(handler)
    269311        self.write_items(handler)
     
    280322        handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']})
    281323        if self.feed['feed_url'] is not None:
    282324            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'])
    283327        handler.addQuickElement(u"id", self.feed['id'])
    284328        handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('utf-8'))
    285329        if self.feed['author_name'] is not None:
Back to Top