summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-07-09 08:25:46 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-07-09 08:25:46 (GMT)
commit6dc9f0eca7ac25519b4dd54de48d0ba1af56344f (patch)
tree1c613effe972c4102ca7330398350404608366b5
parenta945ad1a12727780b8f24a95153d6dfcd8c544de (diff)
parent848245a0782b4f2b8142f1fa25cca08123e7f247 (diff)
downloadcpython-6dc9f0eca7ac25519b4dd54de48d0ba1af56344f.zip
cpython-6dc9f0eca7ac25519b4dd54de48d0ba1af56344f.tar.gz
cpython-6dc9f0eca7ac25519b4dd54de48d0ba1af56344f.tar.bz2
Merged upstream changes.
-rwxr-xr-xTools/scripts/highlight.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Tools/scripts/highlight.py b/Tools/scripts/highlight.py
index ef010e8..ebf96b7 100755
--- a/Tools/scripts/highlight.py
+++ b/Tools/scripts/highlight.py
@@ -10,7 +10,7 @@ import keyword, tokenize, cgi, functools
def is_builtin(s):
'Return True if s is the name of a builtin'
- return s in vars(__builtins__)
+ return hasattr(__builtins__, s)
def combine_range(lines, start, end):
'Join content from a range of lines between start and end'
@@ -161,6 +161,8 @@ if __name__ == '__main__':
help = 'build a complete html webpage')
parser.add_argument('-s', '--section', action = 'store_true',
help = 'show an HTML section rather than a complete webpage')
+ parser.add_argument('-v', '--verbose', action = 'store_true',
+ help = 'display categorized text to stderr')
args = parser.parse_args()
if args.section and (args.browser or args.complete):
@@ -172,6 +174,12 @@ if __name__ == '__main__':
source = f.read()
classified_text = analyze_python(source)
+ if args.verbose:
+ classified_text = list(classified_text)
+ for line_upto_token, kind, line_thru_token in classified_text:
+ sys.stderr.write('%15s: %r\n' % ('leadin', line_upto_token))
+ sys.stderr.write('%15s: %r\n\n' % (kind, line_thru_token))
+
if args.complete or args.browser:
encoded = build_html_page(classified_text, title=sourcefile)
elif args.section: