[Python-checkins] cpython: Minor cleanups

raymond.hettinger python-checkins at python.org
Tue Jul 3 09:12:50 CEST 2012


http://hg.python.org/cpython/rev/4d320cd4c6fe
changeset: 77928:4d320cd4c6fe
parent: 77920:2367ec12da2d
user: Raymond Hettinger <python at rcn.com>
date: Tue Jul 03 00:12:27 2012 -0700
summary:
 Minor cleanups
files:
 Tools/scripts/README | 2 +-
 Tools/scripts/pycolorize.py | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/Tools/scripts/README b/Tools/scripts/README
--- a/Tools/scripts/README
+++ b/Tools/scripts/README
@@ -28,6 +28,7 @@
 google.py Open a webbrowser with Google
 gprof2html.py Transform gprof(1) output into useful HTML
 h2py.py Translate #define's into Python assignments
+highlight.py Python syntax highlighting with HTML output
 idle3 Main program to start IDLE
 ifdef.py Remove #if(n)def groups from C sources
 lfcr.py Change LF line endings to CRLF (Unix to Windows)
@@ -47,7 +48,6 @@
 pickle2db.py Load a pickle generated by db2pickle.py to a database
 pindent.py Indent Python code, giving block-closing comments
 ptags.py Create vi tags file for Python modules
-pycolorize.py Python syntax highlighting with HTML output
 pydoc3 Python documentation browser
 pysource.py Find Python source files
 redemo.py Basic regular expression demonstration facility
diff --git a/Tools/scripts/pycolorize.py b/Tools/scripts/highlight.py
rename from Tools/scripts/pycolorize.py
rename to Tools/scripts/highlight.py
--- a/Tools/scripts/pycolorize.py
+++ b/Tools/scripts/highlight.py
@@ -21,7 +21,7 @@
 
 def colorize(source):
 'Convert Python source code to an HTML fragment with colorized markup'
- lines = source.splitlines(True)
+ lines = source.splitlines(keepends=True)
 lines.append('')
 readline = functools.partial(next, iter(lines), '')
 kind = tok_str = ''
@@ -31,7 +31,7 @@
 for tok in tokenize.generate_tokens(readline):
 prev_tok_type, prev_tok_str = tok_type, tok_str
 tok_type, tok_str, (srow, scol), (erow, ecol), logical_lineno = tok
- kind, prev_kind = '', kind
+ kind = ''
 if tok_type == tokenize.COMMENT:
 kind = 'comment'
 elif tok_type == tokenize.OP and tok_str[:1] not in '{}[](),.:;':
@@ -102,22 +102,22 @@
 import sys, argparse, webbrowser, os
 
 parser = argparse.ArgumentParser(
- description = 'Convert Python source code to colorized HTML')
- parser.add_argument('sourcefile', metavar = 'SOURCEFILE', nargs = 1,
+ description = 'Convert Python source code to colorized HTML')
+ parser.add_argument('sourcefile', metavar = 'SOURCEFILE',
 help = 'File containing Python sourcecode')
 parser.add_argument('-b', '--browser', action = 'store_true',
 help = 'launch a browser to show results')
- parser.add_argument('-s', '--standalone', action = 'store_true',
- help = 'show a standalone snippet rather than a complete webpage')
+ parser.add_argument('-s', '--section', action = 'store_true',
+ help = 'show an HTML section rather than a complete webpage')
 args = parser.parse_args()
- if args.browser and args.standalone:
- parser.error('The -s/--standalone option is incompatible with '
+ if args.browser and args.section:
+ parser.error('The -s/--section option is incompatible with '
 'the -b/--browser option')
 
- sourcefile = args.sourcefile[0]
+ sourcefile = args.sourcefile
 with open(sourcefile) as f:
 page = f.read()
- html = colorize(page) if args.standalone else build_page(page, title=sourcefile)
+ html = colorize(page) if args.section 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

AltStyle によって変換されたページ (->オリジナル) /