mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
This commit is contained in:
parent
e788057a91
commit
b82e17e626
70 changed files with 3565 additions and 1816 deletions
|
|
@ -977,9 +977,13 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
|
|||
}
|
||||
|
||||
if (PyCode_Check(source)) {
|
||||
if (PySys_Audit("exec", "O", source) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"code object passed to eval() may not contain free variables");
|
||||
"code object passed to eval() may not contain free variables");
|
||||
return NULL;
|
||||
}
|
||||
return PyEval_EvalCode(source, globals, locals);
|
||||
|
|
@ -1061,6 +1065,10 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
|||
}
|
||||
|
||||
if (PyCode_Check(source)) {
|
||||
if (PySys_Audit("exec", "O", source) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"code object passed to exec() may not "
|
||||
|
|
@ -1207,7 +1215,14 @@ static PyObject *
|
|||
builtin_id(PyModuleDef *self, PyObject *v)
|
||||
/*[clinic end generated code: output=0aa640785f697f65 input=5a534136419631f4]*/
|
||||
{
|
||||
return PyLong_FromVoidPtr(v);
|
||||
PyObject *id = PyLong_FromVoidPtr(v);
|
||||
|
||||
if (id && PySys_Audit("builtins.id", "O", id) < 0) {
|
||||
Py_DECREF(id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1986,6 +2001,10 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (PySys_Audit("builtins.input", "O", prompt ? prompt : Py_None) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* First of all, flush stderr */
|
||||
tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
|
||||
if (tmp == NULL)
|
||||
|
|
@ -2116,6 +2135,13 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
|||
Py_DECREF(stdin_errors);
|
||||
Py_XDECREF(po);
|
||||
PyMem_FREE(s);
|
||||
|
||||
if (result != NULL) {
|
||||
if (PySys_Audit("builtins.input/result", "O", result) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
_readline_errors:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue