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

@ -162,4 +162,55 @@ blob_tell(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
{
return blob_tell_impl(self);
}
/*[clinic end generated code: output=d3a02b127f2cfa58 input=a9049054013a1b77]*/
PyDoc_STRVAR(blob_enter__doc__,
"__enter__($self, /)\n"
"--\n"
"\n"
"Blob context manager enter.");
#define BLOB_ENTER_METHODDEF \
{"__enter__", (PyCFunction)blob_enter, METH_NOARGS, blob_enter__doc__},
static PyObject *
blob_enter_impl(pysqlite_Blob *self);
static PyObject *
blob_enter(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
{
return blob_enter_impl(self);
}
PyDoc_STRVAR(blob_exit__doc__,
"__exit__($self, type, val, tb, /)\n"
"--\n"
"\n"
"Blob context manager exit.");
#define BLOB_EXIT_METHODDEF \
{"__exit__", (PyCFunction)(void(*)(void))blob_exit, METH_FASTCALL, blob_exit__doc__},
static PyObject *
blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
PyObject *tb);
static PyObject *
blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *type;
PyObject *val;
PyObject *tb;
if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
goto exit;
}
type = args[0];
val = args[1];
tb = args[2];
return_value = blob_exit_impl(self, type, val, tb);
exit:
return return_value;
}
/*[clinic end generated code: output=ca2400862c18dadb input=a9049054013a1b77]*/