diff options
author | 2019-05-23 08:45:22 -0700 | |
---|---|---|
committer | 2019-05-23 08:45:22 -0700 | |
commit | b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184 (patch) | |
tree | 5370a2a075707cb0b37ce135cad6ffe23da424c4 /Python/fileutils.c | |
parent | bpo-36797: Reduce levels of indirection in outdated distutils docs (#13462) (diff) | |
download | cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.gz cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.bz2 cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.zip |
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r-- | Python/fileutils.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index dfad48edb81..178e2f1268f 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1262,6 +1262,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) #endif if (gil_held) { + if (PySys_Audit("open", "sOi", pathname, Py_None, flags) < 0) { + return -1; + } + do { Py_BEGIN_ALLOW_THREADS fd = open(pathname, flags); @@ -1331,6 +1335,9 @@ FILE * _Py_wfopen(const wchar_t *path, const wchar_t *mode) { FILE *f; + if (PySys_Audit("open", "uui", path, mode, 0) < 0) { + return NULL; + } #ifndef MS_WINDOWS char *cpath; char cmode[10]; @@ -1366,6 +1373,10 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode) FILE* _Py_fopen(const char *pathname, const char *mode) { + if (PySys_Audit("open", "ssi", pathname, mode, 0) < 0) { + return NULL; + } + FILE *f = fopen(pathname, mode); if (f == NULL) return NULL; @@ -1401,6 +1412,9 @@ _Py_fopen_obj(PyObject *path, const char *mode) assert(PyGILState_Check()); + if (PySys_Audit("open", "Osi", path, mode, 0) < 0) { + return NULL; + } if (!PyUnicode_Check(path)) { PyErr_Format(PyExc_TypeError, "str file path expected under Windows, got %R", @@ -1434,6 +1448,10 @@ _Py_fopen_obj(PyObject *path, const char *mode) return NULL; path_bytes = PyBytes_AS_STRING(bytes); + if (PySys_Audit("open", "Osi", path, mode, 0) < 0) { + return NULL; + } + do { Py_BEGIN_ALLOW_THREADS f = fopen(path_bytes, mode); |