Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf6eac4

Browse files
committed
Minor cleanups
1 parent ecea0fb commit cf6eac4

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

Tools/scripts/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ftpmirror.py FTP mirror script
2828
google.py Open a webbrowser with Google
2929
gprof2html.py Transform gprof(1) output into useful HTML
3030
h2py.py Translate #define's into Python assignments
31+
highlight.py Python syntax highlighting with HTML output
3132
idle3 Main program to start IDLE
3233
ifdef.py Remove #if(n)def groups from C sources
3334
lfcr.py Change LF line endings to CRLF (Unix to Windows)
@@ -47,7 +48,6 @@ pdeps.py Print dependencies between Python modules
4748
pickle2db.py Load a pickle generated by db2pickle.py to a database
4849
pindent.py Indent Python code, giving block-closing comments
4950
ptags.py Create vi tags file for Python modules
50-
pycolorize.py Python syntax highlighting with HTML output
5151
pydoc3 Python documentation browser
5252
pysource.py Find Python source files
5353
redemo.py Basic regular expression demonstration facility
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def escape_range(lines, start, end):
2121

2222
def colorize(source):
2323
'Convert Python source code to an HTML fragment with colorized markup'
24-
lines = source.splitlines(True)
24+
lines = source.splitlines(keepends=True)
2525
lines.append('')
2626
readline = functools.partial(next, iter(lines), '')
2727
kind = tok_str = ''
@@ -31,7 +31,7 @@ def colorize(source):
3131
for tok in tokenize.generate_tokens(readline):
3232
prev_tok_type, prev_tok_str = tok_type, tok_str
3333
tok_type, tok_str, (srow, scol), (erow, ecol), logical_lineno = tok
34-
kind, prev_kind = '', kind
34+
kind = ''
3535
if tok_type == tokenize.COMMENT:
3636
kind = 'comment'
3737
elif tok_type == tokenize.OP and tok_str[:1] not in '{}[](),.:;':
@@ -102,22 +102,22 @@ def build_page(source, title='python', css=default_css, html=default_html):
102102
import sys, argparse, webbrowser, os
103103

104104
parser = argparse.ArgumentParser(
105-
description = 'Convert Python source code to colorized HTML')
106-
parser.add_argument('sourcefile', metavar = 'SOURCEFILE', nargs = 1,
105+
description = 'Convert Python source code to colorized HTML')
106+
parser.add_argument('sourcefile', metavar = 'SOURCEFILE',
107107
help = 'File containing Python sourcecode')
108108
parser.add_argument('-b', '--browser', action = 'store_true',
109109
help = 'launch a browser to show results')
110-
parser.add_argument('-s', '--standalone', action = 'store_true',
111-
help = 'show a standalone snippet rather than a complete webpage')
110+
parser.add_argument('-s', '--section', action = 'store_true',
111+
help = 'show an HTML section rather than a complete webpage')
112112
args = parser.parse_args()
113-
if args.browser and args.standalone:
114-
parser.error('The -s/--standalone option is incompatible with '
113+
if args.browser and args.section:
114+
parser.error('The -s/--section option is incompatible with '
115115
'the -b/--browser option')
116116

117-
sourcefile = args.sourcefile[0]
117+
sourcefile = args.sourcefile
118118
with open(sourcefile) as f:
119119
page = f.read()
120-
html = colorize(page) if args.standalone else build_page(page, title=sourcefile)
120+
html = colorize(page) if args.section else build_page(page, title=sourcefile)
121121
if args.browser:
122122
htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html'
123123
with open(htmlfile, 'w') as f:

0 commit comments

Comments
 (0)