(merge 3.2) Issue #12451: pydoc: html_getfile() now uses tokenize.open() to

support Python scripts using a encoding different than UTF-8 (read the coding
cookie of the script).
This commit is contained in:
Victor Stinner 2011-07-05 14:31:28 +02:00
commit d7772bc4cb
2 changed files with 5 additions and 1 deletions

View File

@ -2311,7 +2311,7 @@ def _url_handler(url, content_type="text/html"):
def html_getfile(path): def html_getfile(path):
"""Get and display a source file listing safely.""" """Get and display a source file listing safely."""
path = path.replace('%20', ' ') path = path.replace('%20', ' ')
with open(path, 'r') as fp: with tokenize.open(path) as fp:
lines = html.escape(fp.read()) lines = html.escape(fp.read())
body = '<pre>%s</pre>' % lines body = '<pre>%s</pre>' % lines
heading = html.heading( heading = html.heading(

View File

@ -219,6 +219,10 @@ Core and Builtins
Library Library
------- -------
- Issue #12451: pydoc: html_getfile() now uses tokenize.open() to support
Python scripts using a encoding different than UTF-8 (read the coding cookie
of the script).
- Issue #12493: subprocess: Popen.communicate() now also handles EINTR errors - Issue #12493: subprocess: Popen.communicate() now also handles EINTR errors
if the process has only one pipe. if the process has only one pipe.