mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28025)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit c9227df5a9
)
Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
This commit is contained in:
parent
330aabbbbe
commit
45409518c1
2 changed files with 9 additions and 6 deletions
13
Lib/pydoc.py
13
Lib/pydoc.py
|
@ -1617,13 +1617,14 @@ def pipepager(text, cmd):
|
|||
def tempfilepager(text, cmd):
|
||||
"""Page through text by invoking a program on a temporary file."""
|
||||
import tempfile
|
||||
filename = tempfile.mktemp()
|
||||
with open(filename, 'w', errors='backslashreplace') as file:
|
||||
file.write(text)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
filename = os.path.join(tempdir, 'pydoc.out')
|
||||
with open(filename, 'w', errors='backslashreplace',
|
||||
encoding=os.device_encoding(0) if
|
||||
sys.platform == 'win32' else None
|
||||
) as file:
|
||||
file.write(text)
|
||||
os.system(cmd + ' "' + filename + '"')
|
||||
finally:
|
||||
os.unlink(filename)
|
||||
|
||||
def _escape_stdout(text):
|
||||
# Escape non-encodable characters to avoid encoding errors later
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue