mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Prevent direct instantiation of sqlite3.{Statement,Blob}
This commit is contained in:
2
Lib/test/test_sqlite3/test_dbapi.py
vendored
2
Lib/test/test_sqlite3/test_dbapi.py
vendored
@@ -346,8 +346,6 @@ class ModuleTests(unittest.TestCase):
|
||||
sqlite.SQLITE_CONSTRAINT_CHECK)
|
||||
self.assertEqual(exc.sqlite_errorname, "SQLITE_CONSTRAINT_CHECK")
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_disallow_instantiation(self):
|
||||
cx = sqlite.connect(":memory:")
|
||||
check_disallow_instantiation(self, type(cx("select 1")))
|
||||
|
||||
@@ -2036,7 +2036,7 @@ mod _sqlite {
|
||||
}
|
||||
|
||||
#[pyattr]
|
||||
#[pyclass(name, traverse)]
|
||||
#[pyclass(module = "sqlite3", name = "Blob", traverse)]
|
||||
#[derive(Debug, PyPayload)]
|
||||
struct Blob {
|
||||
connection: PyRef<Connection>,
|
||||
@@ -2044,6 +2044,14 @@ mod _sqlite {
|
||||
inner: PyMutex<Option<BlobInner>>,
|
||||
}
|
||||
|
||||
impl Constructor for Blob {
|
||||
type Args = FuncArgs;
|
||||
|
||||
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("cannot create 'sqlite3.Blob' instances"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BlobInner {
|
||||
blob: SqliteBlob,
|
||||
@@ -2056,7 +2064,7 @@ mod _sqlite {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(AsMapping))]
|
||||
#[pyclass(with(AsMapping, Constructor))]
|
||||
impl Blob {
|
||||
#[pymethod]
|
||||
fn close(&self) {
|
||||
@@ -2356,7 +2364,7 @@ mod _sqlite {
|
||||
impl PrepareProtocol {}
|
||||
|
||||
#[pyattr]
|
||||
#[pyclass(name)]
|
||||
#[pyclass(module = "sqlite3", name = "Statement")]
|
||||
#[derive(PyPayload)]
|
||||
struct Statement {
|
||||
st: PyMutex<SqliteStatement>,
|
||||
@@ -2373,7 +2381,15 @@ mod _sqlite {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass()]
|
||||
impl Constructor for Statement {
|
||||
type Args = FuncArgs;
|
||||
|
||||
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("cannot create 'sqlite3.Statement' instances"))
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor))]
|
||||
impl Statement {
|
||||
fn new(
|
||||
connection: &Connection,
|
||||
|
||||
Reference in New Issue
Block a user