[Python-checkins] cpython (3.4): Issue #22924: Scripts gprof2html.py and highlight.py now use html.escape()
serhiy.storchaka
python-checkins at python.org
Mon Dec 1 09:54:00 CET 2014
https://hg.python.org/cpython/rev/f5eb62bdcb1a
changeset: 93671:f5eb62bdcb1a
branch: 3.4
parent: 93665:d1f7c3f45ffe
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Dec 01 10:50:33 2014 +0200
summary:
Issue #22924: Scripts gprof2html.py and highlight.py now use html.escape()
instead of deperecated cgi.escape(). Original patch by Raymond Hettinger.
files:
Tools/scripts/gprof2html.py | 8 ++++++--
Tools/scripts/highlight.py | 21 +++++++++++++--------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/Tools/scripts/gprof2html.py b/Tools/scripts/gprof2html.py
--- a/Tools/scripts/gprof2html.py
+++ b/Tools/scripts/gprof2html.py
@@ -2,7 +2,11 @@
"""Transform gprof(1) output into useful HTML."""
-import re, os, sys, cgi, webbrowser
+import html
+import os
+import re
+import sys
+import webbrowser
header = """\
<html>
@@ -22,7 +26,7 @@
def add_escapes(filename):
with open(filename) as fp:
for line in fp:
- yield cgi.escape(line)
+ yield html.escape(line)
def main():
diff --git a/Tools/scripts/highlight.py b/Tools/scripts/highlight.py
--- a/Tools/scripts/highlight.py
+++ b/Tools/scripts/highlight.py
@@ -3,11 +3,12 @@
__author__ = 'Raymond Hettinger'
-import keyword, tokenize, cgi, re, functools
-try:
- import builtins
-except ImportError:
- import __builtin__ as builtins
+import builtins
+import functools
+import html as html_module
+import keyword
+import re
+import tokenize
#### Analyze Python Source #################################
@@ -101,7 +102,7 @@
for kind, text in classified_text:
if kind:
result.append('<span class="%s">' % kind)
- result.append(cgi.escape(text))
+ result.append(html_module.escape(text))
if kind:
result.append('</span>')
result.append(closer)
@@ -140,7 +141,7 @@
'Create a complete HTML page with colorized source code'
css_str = '\n'.join(['%s %s' % item for item in css.items()])
result = html_highlight(classified_text)
- title = cgi.escape(title)
+ title = html_module.escape(title)
return html.format(title=title, css=css_str, body=result)
#### LaTeX Output ##########################################
@@ -193,7 +194,11 @@
if __name__ == '__main__':
- import sys, argparse, webbrowser, os, textwrap
+ import argparse
+ import os.path
+ import sys
+ import textwrap
+ import webbrowser
parser = argparse.ArgumentParser(
description = 'Add syntax highlighting to Python source code',
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list