diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-29 05:57:05 -0700 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2022-01-27 08:37:35 +0100 |
commit | f8fb784dfa1d30710c42b676051ba8557599bdaa (patch) | |
tree | 934f652a0ec0631553c2cd836285ad6118cf4123 | |
parent | bpo-43124: Fix smtplib multiple CRLF injection (GH-25987) (GH-28038) (diff) | |
download | pypy-f8fb784dfa1d30710c42b676051ba8557599bdaa.tar.gz pypy-f8fb784dfa1d30710c42b676051ba8557599bdaa.tar.bz2 pypy-f8fb784dfa1d30710c42b676051ba8557599bdaa.zip |
bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28026)gentoo-2.7-7.3.8rc1
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit c9227df5a9d8e958a2324cf0deba8524d1ded26a)
Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
(updated for Python 2.7 by Michał Górny)
-rwxr-xr-x | lib-python/2.7/pydoc.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib-python/2.7/pydoc.py b/lib-python/2.7/pydoc.py index 87b7c2c0d4..5bdf8ebb62 100755 --- a/lib-python/2.7/pydoc.py +++ b/lib-python/2.7/pydoc.py @@ -1425,15 +1425,16 @@ def pipepager(text, cmd): def tempfilepager(text, cmd): """Page through text by invoking a program on a temporary file.""" + import shutil import tempfile - filename = tempfile.mktemp() - file = open(filename, 'w') - file.write(_encode(text)) - file.close() + tempdir = tempfile.mkdtemp() try: + filename = os.path.join(tempdir, 'pydoc.out') + with open(filename, 'w') as file: + file.write(_encode(text)) os.system(cmd + ' "' + filename + '"') finally: - os.unlink(filename) + shutil.rmtree(tempdir) def ttypager(text): """Page through text on a text terminal.""" |