]> granicus.if.org Git - python/commitdiff
Issue #22924: Scripts gprof2html.py and highlight.py now use html.escape()
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 1 Dec 2014 08:50:33 +0000 (10:50 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 1 Dec 2014 08:50:33 +0000 (10:50 +0200)
instead of deperecated cgi.escape().  Original patch by Raymond Hettinger.

Tools/scripts/gprof2html.py
Tools/scripts/highlight.py

index ad828358c1484bbb1faea3e9e3d8ca2d7c1b0fd4..4ca705c3c61cf66e73e456fae48ef524b8753568 100755 (executable)
@@ -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 @@ trailer = """\
 def add_escapes(filename):
     with open(filename) as fp:
         for line in fp:
-            yield cgi.escape(line)
+            yield html.escape(line)
 
 
 def main():
index aff5caebdf63540c7c8a3b8fdfbd735382072572..66ad868ec3fe488a1d7cc5d39fc42b82c407db7f 100755 (executable)
@@ -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 @@ def html_highlight(classified_text,opener='<pre class="python">\n', closer='</pr
     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 @@ def build_html_page(classified_text, title='python',
     '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 @@ def latex_highlight(classified_text, title = 'python',
 
 
 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',