summaryrefslogtreecommitdiff
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-08-28 00:53:59 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-08-28 00:53:59 +0200
commite5883d6d95989121670eca012dd5bde1721747e7 (patch)
tree0a3d97e7d4c3fd6e7381ae9357a236333315f08d /Lib/tempfile.py
parent8ccecb68f7c8ca1e6e4cdde3a3a8114c737d43ae (diff)
downloadcpython-e5883d6d95989121670eca012dd5bde1721747e7.tar.gz
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(), os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py26
1 files changed, 2 insertions, 24 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index df7328984a..1eff59cca4 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -35,33 +35,12 @@ import errno as _errno
from random import Random as _Random
try:
- import fcntl as _fcntl
-except ImportError:
- def _set_cloexec(fd):
- pass
-else:
- def _set_cloexec(fd):
- try:
- flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
- except OSError:
- pass
- else:
- # flags read successfully, modify
- flags |= _fcntl.FD_CLOEXEC
- _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)
-
-
-try:
import _thread
except ImportError:
import _dummy_thread as _thread
_allocate_lock = _thread.allocate_lock
_text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL
-if hasattr(_os, 'O_CLOEXEC'):
- _text_openflags |= _os.O_CLOEXEC
-if hasattr(_os, 'O_NOINHERIT'):
- _text_openflags |= _os.O_NOINHERIT
if hasattr(_os, 'O_NOFOLLOW'):
_text_openflags |= _os.O_NOFOLLOW
@@ -90,8 +69,8 @@ else:
# Fallback. All we need is something that raises OSError if the
# file doesn't exist.
def _stat(fn):
- f = open(fn)
- f.close()
+ fd = _os.open(fn, _os.O_RDONLY)
+ os.close(fd)
def _exists(fn):
try:
@@ -217,7 +196,6 @@ def _mkstemp_inner(dir, pre, suf, flags):
file = _os.path.join(dir, pre + name + suf)
try:
fd = _os.open(file, flags, 0o600)
- _set_cloexec(fd)
return (fd, _os.path.abspath(file))
except FileExistsError:
continue # try again