aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-29 05:57:05 -0700
committerMichał Górny <mgorny@gentoo.org>2022-02-20 12:17:54 +0100
commitbcd276afdb6dc0ab177446414cb3e62330e058d4 (patch)
tree330ada624a418e99a08fa5b56c0906f5b0828285
parentbpo-43124: Fix smtplib multiple CRLF injection (GH-25987) (GH-28038) (diff)
downloadpypy-bcd276afdb6dc0ab177446414cb3e62330e058d4.tar.gz
pypy-bcd276afdb6dc0ab177446414cb3e62330e058d4.tar.bz2
pypy-bcd276afdb6dc0ab177446414cb3e62330e058d4.zip
bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28026)gentoo-2.7-7.3.8
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-xlib-python/2.7/pydoc.py11
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."""