From cf6eac40639ef64fe07a83abd313dab06a45a1e1 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 3 Jul 2012 00:12:27 -0700 Subject: [PATCH] Minor cleanups --- Tools/scripts/README | 2 +- Tools/scripts/{pycolorize.py => highlight.py} | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) rename Tools/scripts/{pycolorize.py => highlight.py} (87%) diff --git a/Tools/scripts/README b/Tools/scripts/README index 84b888f19d7..d65d1fd474d 100644 --- a/Tools/scripts/README +++ b/Tools/scripts/README @@ -28,6 +28,7 @@ ftpmirror.py FTP mirror script 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 @@ pdeps.py Print dependencies between Python modules 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 similarity index 87% rename from Tools/scripts/pycolorize.py rename to Tools/scripts/highlight.py index 7a177b925aa..85ce0919a26 100755 --- a/Tools/scripts/pycolorize.py +++ b/Tools/scripts/highlight.py @@ -21,7 +21,7 @@ def escape_range(lines, start, end): 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 @@ def colorize(source): 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 @@ if __name__ == '__main__': 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: