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:
parent
2cfb6f3aa0
commit
91e08772a6
@ -2580,7 +2580,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(
|
||||||
|
@ -27,6 +27,10 @@ Library
|
|||||||
- Issue #12467: warnings: fix a race condition if a warning is emitted at
|
- Issue #12467: warnings: fix a race condition if a warning is emitted at
|
||||||
shutdown, if globals()['__file__'] is None.
|
shutdown, if globals()['__file__'] is None.
|
||||||
|
|
||||||
|
- 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 #12451: pydoc: importfile() now opens the Python script in binary mode,
|
- Issue #12451: pydoc: importfile() now opens the Python script in binary mode,
|
||||||
instead of text mode using the locale encoding, to avoid encoding issues.
|
instead of text mode using the locale encoding, to avoid encoding issues.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user