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> | 2021-10-06 17:32:28 +0200 |
commit | 8516219d308f6de5b86abc5aa10089ebf74d4ce8 (patch) | |
tree | 4a132765bcaab0463115f32c3f244beed440831d | |
parent | bpo-43124: Fix smtplib multiple CRLF injection (GH-25987) (GH-28038) (diff) | |
download | pypy-8516219d308f6de5b86abc5aa10089ebf74d4ce8.tar.gz pypy-8516219d308f6de5b86abc5aa10089ebf74d4ce8.tar.bz2 pypy-8516219d308f6de5b86abc5aa10089ebf74d4ce8.zip |
bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28026)gentoo-2.7-7.3.6rc3gentoo-2.7-7.3.6rc2gentoo-2.7-7.3.6
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.""" |