Commits

Eric Knibbe committed cb9ef7c Draft

updates for Python 3 & docutils 0.10

Comments (0)

Files changed (2)

python/restview/src/restview/default.css

 
 /* System messages (aka errors) */
 
+div.system-messages h1 {
+    color: red;
+}
 div.system-message {
     border-left: 3px double red;
     margin-left: 19px;
     padding-bottom: 10px;
     color: red;
 }
-div.system-messages h1 {
-    color: red;
-}
 div.system-message p.system-message-title {
     margin-top: 0;
     font-weight: bold;

python/restview/src/restview/restviewhttp.py

 import os
 import re
 import sys
+import time
 import socket
 import optparse
 import threading
 except ImportError:
     import socketserver as SocketServer
 
-import cgi
+try:
+    from html import escape
+except ImportError:
+    from cgi import escape
 
 try:
     from urllib import unquote
 
 from docutils import core
 from docutils.writers import html4css1
-import time
 
 try:
     import pygments
 
 
 __version__ = "1.3.0dev"
+last_atime = 0
 
 
 class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     """HTTP request handler that renders ReStructuredText on the fly."""
 
     server_version = "restviewhttp/" + __version__
-    last_atime = 0
 
     def do_GET(self):
         content = self.do_GET_or_HEAD()
             self.wfile.write(content)
 
     def do_HEAD(self):
-        content = self.do_GET_or_HEAD()
+        self.do_GET_or_HEAD()
 
     def do_GET_or_HEAD(self):
         self.path = unquote(self.path)
                         self.send_header("Cache-Control", "no-cache, no-store, max-age=0")
                         self.end_headers()
                         self.server.renderer.root_mtime = os.stat(self.translate_path()).st_mtime
-                    except Exception, e:
+                    except Exception as e:
                         self.log_error('%s (client closed "%s" before acknowledgement)', e, self.path)
                     finally:
                         return
             try:
                 self.send_response(204)
                 self.end_headers()
-            except Exception, e:
+            except Exception as e:
                 self.log_error('%s (client closed "%s" before cancellation)', e, self.path)
             finally:
                 return
         return html
 
     def render_dir_listing(self, title, files):
-        files = ''.join([FILE_TEMPLATE.replace('$href', cgi.escape(href))
-                                      .replace('$file', cgi.escape(fn))
+        files = ''.join([FILE_TEMPLATE.replace('$href', escape(href))
+                                      .replace('$file', escape(fn))
                          for href, fn in files])
-        return (DIR_TEMPLATE.replace('$title', cgi.escape(title))
+        return (DIR_TEMPLATE.replace('$title', escape(title))
                             .replace('$files', files))
 
 
                                   'embed_stylesheet': True}
         else:
             settings_overrides = {}
-
+        settings_overrides['syntax_highlight'] = 'short'
         if self.strict:
             settings_overrides['halt_level'] = 1
 
         return self.get_markup(writer.output)
 
     def render_exception(self, title, error, source):
-        html = (ERROR_TEMPLATE.replace('$title', cgi.escape(title))
-                              .replace('$error', cgi.escape(error))
-                              .replace('$source', cgi.escape(source)))
+        html = (ERROR_TEMPLATE.replace('$title', escape(title))
+                              .replace('$error', escape(error))
+                              .replace('$source', escape(source)))
         return self.get_markup(html)
 
     def get_markup(self, markup):
             return markup.replace('</body>', AJAX_STR + '</body>')
         else:
             return markup.replace('</title>',
-                                  ' -e "' + cgi.escape(self.command) + '"</title>')
+                                  ' -e "' + escape(self.command) + '"</title>')
 
 
 class SyntaxHighlightingHTMLTranslator(html4css1.HTMLTranslator):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.