bpo-37363: Add audit events for a range of modules (GH-14301)
(cherry picked from commit 60419a7e96577cf783b3b45bf3984f9fb0d7ddff)
Co-authored-by: Steve Dower <steve.dower@python.org>
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index e8b111e..45709cb 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -43,6 +43,7 @@
import shutil as _shutil
import errno as _errno
from random import Random as _Random
+import sys as _sys
import weakref as _weakref
import _thread
_allocate_lock = _thread.allocate_lock
@@ -244,6 +245,7 @@
for seq in range(TMP_MAX):
name = next(names)
file = _os.path.join(dir, pre + name + suf)
+ _sys.audit("tempfile.mkstemp", file)
try:
fd = _os.open(file, flags, 0o600)
except FileExistsError:
@@ -352,6 +354,7 @@
for seq in range(TMP_MAX):
name = next(names)
file = _os.path.join(dir, prefix + name + suffix)
+ _sys.audit("tempfile.mkdtemp", file)
try:
_os.mkdir(file, 0o700)
except FileExistsError:
@@ -546,7 +549,7 @@
_os.close(fd)
raise
-if _os.name != 'posix' or _os.sys.platform == 'cygwin':
+if _os.name != 'posix' or _sys.platform == 'cygwin':
# On non-POSIX and Cygwin systems, assume that we cannot unlink a file
# while it is open.
TemporaryFile = NamedTemporaryFile