diff options
author | Raymond Hettinger <python@rcn.com> | 2012-07-03 07:12:27 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2012-07-03 07:12:27 (GMT) |
commit | cf6eac40639ef64fe07a83abd313dab06a45a1e1 (patch) | |
tree | 39786a6a47386343e075ad281b04594c4f7184e9 /Tools | |
parent | ecea0fb1739d4a85a235cee6013747742d9e9acb (diff) | |
download | cpython-cf6eac40639ef64fe07a83abd313dab06a45a1e1.zip cpython-cf6eac40639ef64fe07a83abd313dab06a45a1e1.tar.gz cpython-cf6eac40639ef64fe07a83abd313dab06a45a1e1.tar.bz2 |
Minor cleanups
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/scripts/README | 2 | ||||
-rwxr-xr-x | Tools/scripts/highlight.py (renamed from Tools/scripts/pycolorize.py) | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/Tools/scripts/README b/Tools/scripts/README index 84b888f..d65d1fd 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 index 7a177b9..85ce091 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: |