mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (GH-25818)
This commit is contained in:
parent
37e0c7850d
commit
c96cc089f6
5 changed files with 17 additions and 13 deletions
|
@ -367,13 +367,14 @@ def test_sqlite3():
|
||||||
print(event, *args)
|
print(event, *args)
|
||||||
|
|
||||||
sys.addaudithook(hook)
|
sys.addaudithook(hook)
|
||||||
cx = sqlite3.connect(":memory:")
|
cx1 = sqlite3.connect(":memory:")
|
||||||
|
cx2 = sqlite3.Connection(":memory:")
|
||||||
|
|
||||||
# Configured without --enable-loadable-sqlite-extensions
|
# Configured without --enable-loadable-sqlite-extensions
|
||||||
if hasattr(sqlite3.Connection, "enable_load_extension"):
|
if hasattr(sqlite3.Connection, "enable_load_extension"):
|
||||||
cx.enable_load_extension(False)
|
cx1.enable_load_extension(False)
|
||||||
try:
|
try:
|
||||||
cx.load_extension("test")
|
cx1.load_extension("test")
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -158,7 +158,7 @@ class AuditTest(unittest.TestCase):
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
print(*events, sep='\n')
|
print(*events, sep='\n')
|
||||||
actual = [ev[0] for ev in events]
|
actual = [ev[0] for ev in events]
|
||||||
expected = ["sqlite3.connect", "sqlite3.connect/handle"]
|
expected = ["sqlite3.connect", "sqlite3.connect/handle"] * 2
|
||||||
|
|
||||||
if hasattr(sqlite3.Connection, "enable_load_extension"):
|
if hasattr(sqlite3.Connection, "enable_load_extension"):
|
||||||
expected += [
|
expected += [
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Creating :class:`sqlite3.Connection` objects now also produces
|
||||||
|
``sqlite3.connect`` and ``sqlite3.connect/handle`` :ref:`auditing events
|
||||||
|
<auditing>`. Previously these events were only produced by
|
||||||
|
:func:`sqlite3.connect` calls. Patch by Erlend E. Aasland.
|
|
@ -86,6 +86,10 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
database = PyBytes_AsString(database_obj);
|
database = PyBytes_AsString(database_obj);
|
||||||
|
|
||||||
self->initialized = 1;
|
self->initialized = 1;
|
||||||
|
@ -179,6 +183,10 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
|
||||||
self->ProgrammingError = pysqlite_ProgrammingError;
|
self->ProgrammingError = pysqlite_ProgrammingError;
|
||||||
self->NotSupportedError = pysqlite_NotSupportedError;
|
self->NotSupportedError = pysqlite_NotSupportedError;
|
||||||
|
|
||||||
|
if (PySys_Audit("sqlite3.connect/handle", "O", self) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,20 +91,11 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
|
||||||
factory = (PyObject*)pysqlite_ConnectionType;
|
factory = (PyObject*)pysqlite_ConnectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = PyObject_Call(factory, args, kwargs);
|
result = PyObject_Call(factory, args, kwargs);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PySys_Audit("sqlite3.connect/handle", "O", self) < 0) {
|
|
||||||
Py_DECREF(result);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue