mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Close #19282: Native context management in dbm
This commit is contained in:
parent
eb8ea265ba
commit
c610aba1ed
8 changed files with 101 additions and 16 deletions
|
@ -313,6 +313,21 @@ dbm_setdefault(dbmobject *dp, PyObject *args)
|
|||
return defvalue;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
dbm__enter__(PyObject *self, PyObject *args)
|
||||
{
|
||||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
dbm__exit__(PyObject *self, PyObject *args)
|
||||
{
|
||||
_Py_IDENTIFIER(close);
|
||||
return _PyObject_CallMethodId(self, &PyId_close, NULL);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef dbm_methods[] = {
|
||||
{"close", (PyCFunction)dbm__close, METH_NOARGS,
|
||||
"close()\nClose the database."},
|
||||
|
@ -325,6 +340,8 @@ static PyMethodDef dbm_methods[] = {
|
|||
"setdefault(key[, default]) -> value\n"
|
||||
"Return the value for key if present, otherwise default. If key\n"
|
||||
"is not in the database, it is inserted with default as the value."},
|
||||
{"__enter__", dbm__enter__, METH_NOARGS, NULL},
|
||||
{"__exit__", dbm__exit__, METH_VARARGS, NULL},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue