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

Skip to content

Commit 91e0877

Browse files
author
Victor Stinner
committed
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).
1 parent 2cfb6f3 commit 91e0877

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ def bltinlink(name):
25802580
def html_getfile(path):
25812581
"""Get and display a source file listing safely."""
25822582
path = path.replace('%20', ' ')
2583-
with open(path, 'r') as fp:
2583+
with tokenize.open(path) as fp:
25842584
lines = html.escape(fp.read())
25852585
body = '<pre>%s</pre>' % lines
25862586
heading = html.heading(

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Library
2727
- Issue #12467: warnings: fix a race condition if a warning is emitted at
2828
shutdown, if globals()['__file__'] is None.
2929

30+
- Issue #12451: pydoc: html_getfile() now uses tokenize.open() to support
31+
Python scripts using a encoding different than UTF-8 (read the coding cookie
32+
of the script).
33+
3034
- Issue #12451: pydoc: importfile() now opens the Python script in binary mode,
3135
instead of text mode using the locale encoding, to avoid encoding issues.
3236

0 commit comments

Comments
 (0)