Commit be1c7816 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #22924: Scripts gprof2html.py and highlight.py now use html.escape()

instead of deperecated cgi.escape().  Original patch by Raymond Hettinger.
parent c1794bf7
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
"""Transform gprof(1) output into useful HTML.""" """Transform gprof(1) output into useful HTML."""
import re, os, sys, cgi, webbrowser import html
import os
import re
import sys
import webbrowser
header = """\ header = """\
<html> <html>
...@@ -22,7 +26,7 @@ trailer = """\ ...@@ -22,7 +26,7 @@ trailer = """\
def add_escapes(filename): def add_escapes(filename):
with open(filename) as fp: with open(filename) as fp:
for line in fp: for line in fp:
yield cgi.escape(line) yield html.escape(line)
def main(): def main():
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
__author__ = 'Raymond Hettinger' __author__ = 'Raymond Hettinger'
import keyword, tokenize, cgi, re, functools import builtins
try: import functools
import builtins import html as html_module
except ImportError: import keyword
import __builtin__ as builtins import re
import tokenize
#### Analyze Python Source ################################# #### Analyze Python Source #################################
...@@ -101,7 +102,7 @@ def html_highlight(classified_text,opener='<pre class="python">\n', closer='</pr ...@@ -101,7 +102,7 @@ def html_highlight(classified_text,opener='<pre class="python">\n', closer='</pr
for kind, text in classified_text: for kind, text in classified_text:
if kind: if kind:
result.append('<span class="%s">' % kind) result.append('<span class="%s">' % kind)
result.append(cgi.escape(text)) result.append(html_module.escape(text))
if kind: if kind:
result.append('</span>') result.append('</span>')
result.append(closer) result.append(closer)
...@@ -140,7 +141,7 @@ def build_html_page(classified_text, title='python', ...@@ -140,7 +141,7 @@ def build_html_page(classified_text, title='python',
'Create a complete HTML page with colorized source code' 'Create a complete HTML page with colorized source code'
css_str = '\n'.join(['%s %s' % item for item in css.items()]) css_str = '\n'.join(['%s %s' % item for item in css.items()])
result = html_highlight(classified_text) result = html_highlight(classified_text)
title = cgi.escape(title) title = html_module.escape(title)
return html.format(title=title, css=css_str, body=result) return html.format(title=title, css=css_str, body=result)
#### LaTeX Output ########################################## #### LaTeX Output ##########################################
...@@ -193,7 +194,11 @@ def latex_highlight(classified_text, title = 'python', ...@@ -193,7 +194,11 @@ def latex_highlight(classified_text, title = 'python',
if __name__ == '__main__': if __name__ == '__main__':
import sys, argparse, webbrowser, os, textwrap import argparse
import os.path
import sys
import textwrap
import webbrowser
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description = 'Add syntax highlighting to Python source code', description = 'Add syntax highlighting to Python source code',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment