(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).
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index ad6d7c7..ffb4f89 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -2311,7 +2311,7 @@
def html_getfile(path):
"""Get and display a source file listing safely."""
path = path.replace('%20', ' ')
- with open(path, 'r') as fp:
+ with tokenize.open(path) as fp:
lines = html.escape(fp.read())
body = '<pre>%s</pre>' % lines
heading = html.heading(
diff --git a/Misc/NEWS b/Misc/NEWS
index 5d1530a..4f41fb1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -219,6 +219,10 @@
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
if the process has only one pipe.