Commits

Kirill Simonov  committed 58ad6b1

Support for Python 3.

  • Participants
  • Parent commits 5b9aa4c

Comments (0)

Files changed (7)

 You need to manually update your HTML templates to add a link to the RSS
 feed::
 
-      <link rel="alternate"
-            type="application/rss+xml"
-            title="Elvensense News"
-            href="/index.rss" />
+    <link rel="alternate"
+          type="application/rss+xml"
+          title="Elvensense News"
+          href="/index.rss" />
 
 
 Reference

File demo/_templates/layout.html

   {{ super() }}
   <link rel="alternate"
         type="application/rss+xml"
-        title="Elvensense News"
+        title="Elvënsense News"
         href="/index.rss" />
 {% endblock %}
 

File demo/conf.py

 extensions = ['sphinxcontrib.newsfeed']
 
 # Standard configuration.
-project = u'Elvensense'
+project = u'Elvënsense'
 master_doc = 'index'
 html_theme = 'sphinxdoc'
 highlight_language = 'rest'

File demo/index.rst

-Elvensense News
+Elvënsense News
 ===============
 
 This is a small demo for ``sphinxcontrib-newsfeed`` extension.
 
 .. feed::
    :rss: index.rss
-   :title: Elvensense News
+   :title: Elvënsense News
    :link: http://example.com/
 
    release

File demo/release.rst

-Elvensense 96 is released
+Elvënsense 96 is released
 =========================
 
 .. feed-entry::
    :date: 2012-12-31
 
-We are proud to announce a new release of **Elvensense**.
+We are proud to announce a new release of **Elvënsense**.
 
 .. cut::
 

File demo/welcome.rst

 .. feed-entry::
    :date: 2012-01-01
 
-Welcome to the news feed of **Elvensense**.  Here we will post
+Welcome to the news feed of **Elvënsense**.  Here we will post
 release announcements and other project news.
 

File sphinxcontrib/newsfeed.py

 #
 
 
+from __future__ import unicode_literals
 from docutils import nodes
 from docutils.parsers.rst import Directive, directives
 from sphinx import addnodes
 from sphinx.util import docname_join
-import os.path, datetime, collections
+import sys, os.path, datetime, collections
 
 
 class FeedDirective(Directive):
         subnode = feed()
         subnode['entries'] = includefiles
         subnode['rss'] = self.options.get('rss')
-        subnode['title'] = unicode(self.options.get('title', ''))
-        subnode['link'] = unicode(self.options.get('link', ''))
-        subnode['description'] = unicode(self.options.get('description', ''))
+        subnode['title'] = self.options.get('title', '')
+        subnode['link'] = self.options.get('link', '')
+        subnode['description'] = self.options.get('description', '')
         output.append(subnode)
         return output
 
             return [doc.reporter.error("invalid date `%s`" % date,
                                        lineno=self.lineno)]
         meta_node = entrymeta(classes=['feed-meta'])
-        meta_node += nodes.Text(u'Published')
+        meta_node += nodes.Text('Published')
         if author:
-            meta_node += nodes.Text(u' by ')
+            meta_node += nodes.Text(' by ')
             author_node = nodes.emphasis(classes=['feed-author'])
             author_node += nodes.Text(author)
             meta_node += author_node
         if date:
-            meta_node += nodes.Text(u' on ')
+            meta_node += nodes.Text(' on ')
             date_node = nodes.emphasis(classes=['feed-date'])
             if not date.time():
                 date_node += nodes.Text(date.date())
                 ref_node += title[0]
                 title_node += ref_node
                 section_node += title_node
-                rss_item_title = unicode(title[0])
+                rss_item_title = "%s" % title[0]
                 rss_item_link = rss_link+app.builder.get_target_uri(docname)
                 rss_item_description = nodes.compound()
                 for subnode in entry[0]:
                         ref_node['refuri'] = \
                                 app.builder.get_relative_uri(fromdocname, docname)
                         ref_node['refuri'] += '#' + section_node['ids'][0]
-                        ref_node += nodes.Text(u'Read more\u2026')
+                        ref_node += nodes.Text('Read more\u2026')
                         para_node += ref_node
                         section_node += para_node
                         break
 
 
 def format_text(text):
-    if isinstance(text, unicode):
-        text = text.encode('utf-8')
     return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
 
 
 
 
 def write_rss(rss_feed, stream):
-    stream.write('''<?xml version="1.0" encoding="utf-8"?>\n''')
-    stream.write('''<rss version="2.0">\n''')
-    stream.write('''  <channel>\n''')
-    stream.write('''    <title>%s</title>\n'''
+    lines = []
+    lines.append('''<?xml version="1.0" encoding="utf-8"?>\n''')
+    lines.append('''<rss version="2.0">\n''')
+    lines.append('''  <channel>\n''')
+    lines.append('''    <title>%s</title>\n'''
             % format_text(rss_feed.title))
-    stream.write('''    <link>%s</link>\n'''
+    lines.append('''    <link>%s</link>\n'''
             % format_text(rss_feed.link))
-    stream.write('''    <description>%s</description>\n'''
+    lines.append('''    <description>%s</description>\n'''
             % format_text(rss_feed.description))
-    stream.write('''    <lastBuildDate>%s</lastBuildDate>\n'''
+    lines.append('''    <lastBuildDate>%s</lastBuildDate>\n'''
             % format_date(rss_feed.date))
-    stream.write('''    <generator>sphinxcontrib-newsfeed</generator>\n''')
+    lines.append('''    <generator>sphinxcontrib-newsfeed</generator>\n''')
     for item in rss_feed.items:
-        stream.write('''    <item>\n''')
-        stream.write('''      <title>%s</title>\n'''
+        lines.append('''    <item>\n''')
+        lines.append('''      <title>%s</title>\n'''
                 % format_text(item.title))
-        stream.write('''      <link>%s</link>\n'''
+        lines.append('''      <link>%s</link>\n'''
                 % format_text(item.link))
-        stream.write('''      <description>%s</description>\n'''
+        lines.append('''      <description>%s</description>\n'''
                 % format_text(item.description))
-        stream.write('''      <guid>%s</guid>\n'''
+        lines.append('''      <guid>%s</guid>\n'''
                 % format_text(item.link))
-        stream.write('''      <pubDate>%s</pubDate>\n'''
+        lines.append('''      <pubDate>%s</pubDate>\n'''
                 % format_date(item.date))
-        stream.write('''    </item>\n''')
-    stream.write('''  </channel>\n''')
-    stream.write('''</rss>\n''')
+        lines.append('''    </item>\n''')
+    lines.append('''  </channel>\n''')
+    lines.append('''</rss>\n''')
+    for line in lines:
+        stream.write(line.encode('utf-8'))
 
 
 def setup(app):
                  html=(visit_entrycut, None))
     app.add_node(disqus,
                  html=(visit_disqus, None))
-    app.connect('doctree-resolved', process_feed)
+    app.connect(str('doctree-resolved'), process_feed)