gh-69093: Add context manager support to sqlite3.Blob (GH-91562)

This commit is contained in:
Erlend Egeberg Aasland 2022-04-16 06:21:12 +02:00 committed by GitHub
parent 4e661cd691
commit a861756675
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 135 additions and 11 deletions

View file

@ -307,8 +307,51 @@ blob_tell_impl(pysqlite_Blob *self)
}
/*[clinic input]
_sqlite3.Blob.__enter__ as blob_enter
Blob context manager enter.
[clinic start generated code]*/
static PyObject *
blob_enter_impl(pysqlite_Blob *self)
/*[clinic end generated code: output=4fd32484b071a6cd input=fe4842c3c582d5a7]*/
{
if (!check_blob(self)) {
return NULL;
}
return Py_NewRef(self);
}
/*[clinic input]
_sqlite3.Blob.__exit__ as blob_exit
type: object
val: object
tb: object
/
Blob context manager exit.
[clinic start generated code]*/
static PyObject *
blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
PyObject *tb)
/*[clinic end generated code: output=fc86ceeb2b68c7b2 input=575d9ecea205f35f]*/
{
if (!check_blob(self)) {
return NULL;
}
close_blob(self);
Py_RETURN_FALSE;
}
static PyMethodDef blob_methods[] = {
BLOB_CLOSE_METHODDEF
BLOB_ENTER_METHODDEF
BLOB_EXIT_METHODDEF
BLOB_READ_METHODDEF
BLOB_SEEK_METHODDEF
BLOB_TELL_METHODDEF