mirror of
https://github.com/python/cpython.git
synced 2025-10-20 00:13:47 +00:00
gh-138310: Adds sys.audit event for import_module (#138311)
* Updates sys.audit calls for imports to include import_module * Adds unit tests for existing and new functionality
This commit is contained in:
parent
7257b24140
commit
2fd43a1ffe
8 changed files with 98 additions and 27 deletions
|
@ -3681,33 +3681,6 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
|||
|
||||
PyTime_t t1 = 0, accumulated_copy = accumulated;
|
||||
|
||||
PyObject *sys_path, *sys_meta_path, *sys_path_hooks;
|
||||
if (PySys_GetOptionalAttrString("path", &sys_path) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PySys_GetOptionalAttrString("meta_path", &sys_meta_path) < 0) {
|
||||
Py_XDECREF(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
if (PySys_GetOptionalAttrString("path_hooks", &sys_path_hooks) < 0) {
|
||||
Py_XDECREF(sys_meta_path);
|
||||
Py_XDECREF(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
if (_PySys_Audit(tstate, "import", "OOOOO",
|
||||
abs_name, Py_None, sys_path ? sys_path : Py_None,
|
||||
sys_meta_path ? sys_meta_path : Py_None,
|
||||
sys_path_hooks ? sys_path_hooks : Py_None) < 0) {
|
||||
Py_XDECREF(sys_path_hooks);
|
||||
Py_XDECREF(sys_meta_path);
|
||||
Py_XDECREF(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
Py_XDECREF(sys_path_hooks);
|
||||
Py_XDECREF(sys_meta_path);
|
||||
Py_XDECREF(sys_path);
|
||||
|
||||
|
||||
/* XOptions is initialized after first some imports.
|
||||
* So we can't have negative cache before completed initialization.
|
||||
* Anyway, importlib._find_and_load is much slower than
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue