diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2022-04-16 06:21:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-15 21:21:12 -0700 |
commit | a8617566759a07c67d14c9b6ed663e32d3b3f5e7 (patch) | |
tree | 531993ba1515ca7050375c7d840579423dcc4d7f /Modules/_sqlite/blob.c | |
parent | 4e661cd69164318c1f871faa476c68a04092ddc4 (diff) | |
download | cpython-a8617566759a07c67d14c9b6ed663e32d3b3f5e7.tar.gz cpython-a8617566759a07c67d14c9b6ed663e32d3b3f5e7.zip |
gh-69093: Add context manager support to sqlite3.Blob (GH-91562)
Diffstat (limited to 'Modules/_sqlite/blob.c')
-rw-r--r-- | Modules/_sqlite/blob.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Modules/_sqlite/blob.c b/Modules/_sqlite/blob.c index c4f8be45b2f..3f766302d62 100644 --- a/Modules/_sqlite/blob.c +++ b/Modules/_sqlite/blob.c @@ -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 |