[Python-checkins] cpython: Set title to the source filename

raymond.hettinger python-checkins at python.org
Sun Jul 1 08:19:40 CEST 2012


http://hg.python.org/cpython/rev/21ca7f56e12c
changeset:   77903:21ca7f56e12c
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jun 30 23:19:30 2012 -0700
summary:
  Set title to the source filename

files:
  Tools/scripts/pycolorize.py |  11 ++++++-----
  1 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/Tools/scripts/pycolorize.py b/Tools/scripts/pycolorize.py
--- a/Tools/scripts/pycolorize.py
+++ b/Tools/scripts/pycolorize.py
@@ -2,7 +2,7 @@
 'Convert Python source code to HTML with colorized markup'
 
 __all__ = ['colorize', 'build_page', 'default_css', 'default_html']
-__author__  = 'Raymond Hettinger'
+__author__ = 'Raymond Hettinger'
 
 import keyword, tokenize, cgi, functools
 
@@ -71,7 +71,7 @@
 <html>
 <head>
 <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
-<title> Python Code </title>
+<title> %s </title>
 <style type="text/css">
 %s
 </style>
@@ -82,11 +82,12 @@
 </html>
 '''
 
-def build_page(source, html=default_html, css=default_css):
+def build_page(source, title='python', css=default_css, html=default_html):
     'Create a complete HTML page with colorized Python source code'
     css_str = '\n'.join(['%s %s' % item for item in css.items()])
     result = colorize(source)
-    return html % (css_str, result)
+    title = cgi.escape(title)
+    return html % (title, css_str, result)
 
 
 if __name__ == '__main__':
@@ -108,7 +109,7 @@
     sourcefile = args.sourcefile[0]
     with open(sourcefile) as f:
         page = f.read()
-    html = colorize(page) if args.standalone else build_page(page)
+    html = colorize(page) if args.standalone else build_page(page, title=sourcefile)
     if args.browser:
         htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html'
         with open(htmlfile, 'w') as f:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list