From 355486c83d638596b2e5dce31089791a566b16dc Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Thu, 20 Apr 2006 17:51:58 +0000 Subject: [PATCH] Replaced constant_getAttr() with constant_getAttro(), and added extra code so that the .keys(), .items() and .values() methods worked. --- source/blender/python/api2_2x/constant.c | 38 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/source/blender/python/api2_2x/constant.c b/source/blender/python/api2_2x/constant.c index f28af8efad6..55b9d9c41a6 100644 --- a/source/blender/python/api2_2x/constant.c +++ b/source/blender/python/api2_2x/constant.c @@ -122,6 +122,13 @@ static PyObject *constant_getAttr(BPy_constant * self, char *name) if(!strcmp(name, "__members__")) return PyDict_Keys(self->dict); + if(!strcmp(name, "__methods__")) { + PyObject *value = PyString_FromString ( name ); + v = PyObject_GenericGetAttr( (PyObject *)self, value ); + Py_DECREF( value); + return v; + } + v = PyDict_GetItemString(self->dict, name); if(v) { return EXPP_incr_ret(v); /* was a borrowed ref */ @@ -132,6 +139,31 @@ static PyObject *constant_getAttr(BPy_constant * self, char *name) return (EXPP_ReturnPyObjError(PyExc_RuntimeError, "constant object lacks a dictionary")); } + +static PyObject *constant_getAttro(BPy_constant * self, PyObject *value) +{ + if(self->dict) { + PyObject *v; + char *name = PyString_AS_STRING( value ); + + if(!strcmp(name, "__members__")) + return PyDict_Keys(self->dict); + +#if 0 + if(!strcmp(name, "__methods__") || !strcmp(name, "__dict__")) { + return PyObject_GenericGetAttr( (PyObject *)self, value ); + } +#endif + + v = PyDict_GetItemString(self->dict, name); + if(v) { + return EXPP_incr_ret(v); /* was a borrowed ref */ + } + return PyObject_GenericGetAttr( (PyObject *)self, value ); + } + return (EXPP_ReturnPyObjError(PyExc_RuntimeError, + "constant object lacks a dictionary")); +} //------------------------tp_repr static PyObject *constant_repr(BPy_constant * self) { @@ -180,7 +212,8 @@ PyTypeObject constant_Type = { 0, //tp_itemsize (destructor)constant_dealloc, //tp_dealloc 0, //tp_print - (getattrfunc)constant_getAttr, //tp_getattr + // (getattrfunc)constant_getAttr, //tp_getattr + 0, //tp_getattr 0, //tp_setattr 0, //tp_compare (reprfunc) constant_repr, //tp_repr @@ -190,7 +223,7 @@ PyTypeObject constant_Type = { 0, //tp_hash 0, //tp_call 0, //tp_str - 0, //tp_getattro + (getattrofunc)constant_getAttro, //tp_getattro 0, //tp_setattro 0, //tp_as_buffer Py_TPFLAGS_DEFAULT, //tp_flags @@ -230,6 +263,7 @@ PyObject *PyConstant_New(void) //Inserts a key:value pair into the constant and then returns 0/1 int PyConstant_Insert(BPy_constant *self, char *name, PyObject *value) { + PyType_Ready( &constant_Type ); return EXPP_dict_set_item_str(self->dict, name, value); } //This is a helper function for generating constants......