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

Skip to content

Commit 7a1104d

Browse files
Issue #22924: Scripts gprof2html.py and highlight.py now use html.escape()
instead of deperecated cgi.escape(). Original patch by Raymond Hettinger.
1 parent 6632341 commit 7a1104d

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

Tools/scripts/gprof2html.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
"""Transform gprof(1) output into useful HTML."""
44

5-
import re, os, sys, cgi, webbrowser
5+
import html
6+
import os
7+
import re
8+
import sys
9+
import webbrowser
610

711
header = """\
812
<html>
@@ -22,7 +26,7 @@
2226
def add_escapes(filename):
2327
with open(filename) as fp:
2428
for line in fp:
25-
yield cgi.escape(line)
29+
yield html.escape(line)
2630

2731

2832
def main():

Tools/scripts/highlight.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
__author__ = 'Raymond Hettinger'
55

6-
import keyword, tokenize, cgi, re, functools
7-
try:
8-
import builtins
9-
except ImportError:
10-
import __builtin__ as builtins
6+
import builtins
7+
import functools
8+
import html as html_module
9+
import keyword
10+
import re
11+
import tokenize
1112

1213
#### Analyze Python Source #################################
1314

@@ -101,7 +102,7 @@ def html_highlight(classified_text,opener='<pre class="python">\n', closer='</pr
101102
for kind, text in classified_text:
102103
if kind:
103104
result.append('<span class="%s">' % kind)
104-
result.append(cgi.escape(text))
105+
result.append(html_module.escape(text))
105106
if kind:
106107
result.append('</span>')
107108
result.append(closer)
@@ -140,7 +141,7 @@ def build_html_page(classified_text, title='python',
140141
'Create a complete HTML page with colorized source code'
141142
css_str = '\n'.join(['%s %s' % item for item in css.items()])
142143
result = html_highlight(classified_text)
143-
title = cgi.escape(title)
144+
title = html_module.escape(title)
144145
return html.format(title=title, css=css_str, body=result)
145146

146147
#### LaTeX Output ##########################################
@@ -193,7 +194,11 @@ def latex_highlight(classified_text, title = 'python',
193194

194195

195196
if __name__ == '__main__':
196-
import sys, argparse, webbrowser, os, textwrap
197+
import argparse
198+
import os.path
199+
import sys
200+
import textwrap
201+
import webbrowser
197202

198203
parser = argparse.ArgumentParser(
199204
description = 'Add syntax highlighting to Python source code',

0 commit comments

Comments
 (0)