static PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value) { IDProperty *idprop; PyObject *pyform; const char *name = _PyUnicode_AsString(value); if (!name) { PyErr_Format(PyExc_TypeError, "pop expected at least a string argument, not %.200s", Py_TYPE(value)->tp_name); return NULL; } idprop = IDP_GetPropertyFromGroup(self->prop, name); if (idprop) { pyform = BPy_IDGroup_MapDataToPy(idprop); if (!pyform) { /* ok something bad happened with the pyobject, * so don't remove the prop from the group. if pyform is * NULL, then it already should have raised an exception.*/ return NULL; } IDP_RemoveFromGroup(self->prop, idprop); return pyform; } PyErr_SetString(PyExc_KeyError, "item not in group"); return NULL; }
static PyObject *BPy_IDGroup_pop(BPy_IDProperty *self, PyObject *args) { IDProperty *idprop; PyObject *pyform; char *key; PyObject *def = NULL; if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { return NULL; } idprop = IDP_GetPropertyFromGroup(self->prop, key); if (idprop == NULL) { if (def == NULL) { PyErr_SetString(PyExc_KeyError, "item not in group"); return NULL; } return Py_INCREF_RET(def); } pyform = BPy_IDGroup_MapDataToPy(idprop); if (pyform == NULL) { /* ok something bad happened with the pyobject, * so don't remove the prop from the group. if pyform is * NULL, then it already should have raised an exception.*/ return NULL; } IDP_RemoveFromGroup(self->prop, idprop); return pyform; }