[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24684] trunk/blender/source/blender/ python/generic/IDProp.c: idprop.get(key, default=None)
Campbell Barton
ideasman42 at gmail.com
Thu Nov 19 18:04:28 CET 2009
Revision: 24684
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24684
Author: campbellbarton
Date: 2009-11-19 18:04:28 +0100 (Thu, 19 Nov 2009)
Log Message:
-----------
idprop.get(key, default=None)
matching pythons dict.get()
removed checks for a failed PyObject_New(), if python cant make a new object your probably going to crash anyway.
Modified Paths:
--------------
trunk/blender/source/blender/python/generic/IDProp.c
Modified: trunk/blender/source/blender/python/generic/IDProp.c
===================================================================
--- trunk/blender/source/blender/python/generic/IDProp.c 2009-11-19 16:15:22 UTC (rev 24683)
+++ trunk/blender/source/blender/python/generic/IDProp.c 2009-11-19 17:04:28 UTC (rev 24684)
@@ -64,11 +64,6 @@
/*blegh*/
{
BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &IDGroup_Type);
- if (!group) {
- PyErr_SetString( PyExc_RuntimeError, "PyObject_New() failed" );
- return NULL;
- }
-
group->id = id;
group->prop = prop;
return (PyObject*) group;
@@ -76,10 +71,6 @@
case IDP_ARRAY:
{
BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &IDArray_Type);
- if (!array) {
- PyErr_SetString( PyExc_RuntimeError, "PyObject_New() failed" );
- return NULL;
- }
array->id = id;
array->prop = prop;
return (PyObject*) array;
@@ -352,11 +343,6 @@
static PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
{
BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
-
- if (!iter) {
- PyErr_SetString( PyExc_RuntimeError, "PyObject_New() failed" );
- return NULL;
- }
iter->group = self;
iter->mode = IDPROP_ITER_KEYS;
iter->cur = self->prop->data.group.first;
@@ -464,12 +450,6 @@
static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
{
BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
-
- if (!iter) {
- PyErr_SetString( PyExc_RuntimeError, "PyObject_New() failed" );
- return NULL;
- }
-
iter->group = self;
iter->mode = IDPROP_ITER_ITEMS;
iter->cur = self->prop->data.group.first;
@@ -607,6 +587,28 @@
return BPy_IDGroup_MapDataToPy(self->prop);
}
+
+/* Matches python dict.get(key, [default]) */
+PyObject* BPy_IDGroup_Get(BPy_IDProperty *self, PyObject *args)
+{
+ IDProperty *idprop;
+ char *key;
+ PyObject* def = Py_None;
+
+ if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
+ return NULL;
+
+ idprop= IDP_GetPropertyFromGroup(self->prop, key);
+ if (idprop) {
+ PyObject* pyobj = BPy_IDGroup_WrapData(self->id, idprop);
+ if (pyobj)
+ return pyobj;
+ }
+
+ Py_INCREF(def);
+ return def;
+}
+
static struct PyMethodDef BPy_IDGroup_methods[] = {
{"pop", (PyCFunction)BPy_IDGroup_Pop, METH_O,
"pop an item from the group; raises KeyError if the item doesn't exist."},
@@ -620,6 +622,8 @@
"get the items associated with this group."},
{"update", (PyCFunction)BPy_IDGroup_Update, METH_O,
"updates the values in the group with the values of another or a dict."},
+ {"get", (PyCFunction)BPy_IDGroup_Get, METH_VARARGS,
+ "idprop.get(k[,d]) -> idprop[k] if k in idprop, else d. d defaults to None."},
{"convert_to_pyobject", (PyCFunction)BPy_IDGroup_ConvertToPy, METH_NOARGS,
"return a purely python version of the group."},
{0, NULL, 0, NULL}
@@ -709,12 +713,6 @@
PyObject *BPy_Wrap_IDProperty(ID *id, IDProperty *prop, IDProperty *parent)
{
BPy_IDProperty *wrap = PyObject_New(BPy_IDProperty, &IDGroup_Type);
-
- if (!wrap) {
- PyErr_SetString( PyExc_RuntimeError, "PyObject_New() failed" );
- return NULL;
- }
-
wrap->prop = prop;
wrap->parent = parent;
wrap->id = id;
More information about the Bf-blender-cvs
mailing list