|
3 | 3 |
|
4 | 4 | __author__ = 'Raymond Hettinger' |
5 | 5 |
|
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 |
11 | 12 |
|
12 | 13 | #### Analyze Python Source ################################# |
13 | 14 |
|
@@ -101,7 +102,7 @@ def html_highlight(classified_text,opener='<pre class="python">\n', closer='</pr |
101 | 102 | for kind, text in classified_text: |
102 | 103 | if kind: |
103 | 104 | result.append('<span class="%s">' % kind) |
104 | | - result.append(cgi.escape(text)) |
| 105 | + result.append(html_module.escape(text)) |
105 | 106 | if kind: |
106 | 107 | result.append('</span>') |
107 | 108 | result.append(closer) |
@@ -140,7 +141,7 @@ def build_html_page(classified_text, title='python', |
140 | 141 | 'Create a complete HTML page with colorized source code' |
141 | 142 | css_str = '\n'.join(['%s %s' % item for item in css.items()]) |
142 | 143 | result = html_highlight(classified_text) |
143 | | - title = cgi.escape(title) |
| 144 | + title = html_module.escape(title) |
144 | 145 | return html.format(title=title, css=css_str, body=result) |
145 | 146 |
|
146 | 147 | #### LaTeX Output ########################################## |
@@ -193,7 +194,11 @@ def latex_highlight(classified_text, title = 'python', |
193 | 194 |
|
194 | 195 |
|
195 | 196 | 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 |
197 | 202 |
|
198 | 203 | parser = argparse.ArgumentParser( |
199 | 204 | description = 'Add syntax highlighting to Python source code', |
|
0 commit comments