static int Task_setattro(PyTask *self, PyObject * oname, PyObject *v) { #ifndef NDEBUG if (self->m_task == NULL) { PyErr_SetString(PyExc_AssertionError, "NULL task Task.setattr"); return -1; } #endif // NDEBUG char * name = PyString_AsString(oname); if (strcmp(name, "progress") == 0) { if (PyFloat_Check(v)) { self->m_task->progress() = PyFloat_AsDouble(v); } else if (PyInt_Check(v)) { self->m_task->progress() = PyInt_AsLong(v); } else { PyErr_SetString(PyExc_TypeError, "progress must be a number"); return -1; } return 0; } if (strcmp(name, "rate") == 0) { double rate; if (PyFloat_Check(v)) { rate = PyFloat_AsDouble(v); } else if (PyInt_Check(v)) { rate = PyInt_AsLong(v); } else { PyErr_SetString(PyExc_TypeError, "rate must be a number"); return -1; } self->m_task->rate() = rate; return 0; } if (PyWeakref_CheckProxy(v)) { PyErr_SetString(PyExc_TypeError, "don't store proxy objects as attributes"); return -1; } if (PyLocatedEntity_Check(v)) { PyErr_SetString(PyExc_TypeError, "don't store server objects as attributes"); return -1; } // FIXME Something may be required here long term, for task attributes. return PyObject_GenericSetAttr((PyObject*)self, oname, v); }
/* Given the head of an object's list of weak references, extract the * two callback-less refs (ref and proxy). Used to determine if the * shared references exist and to determine the back link for newly * inserted references. */ static void get_basic_refs(PyWeakReference *head, PyWeakReference **refp, PyWeakReference **proxyp) { *refp = NULL; *proxyp = NULL; if (head != NULL && head->wr_callback == NULL) { /* We need to be careful that the "basic refs" aren't subclasses of the main types. That complicates this a little. */ if (PyWeakref_CheckRefExact(head)) { *refp = head; head = head->wr_next; } if (head != NULL && head->wr_callback == NULL && PyWeakref_CheckProxy(head)) { *proxyp = head; /* head = head->wr_next; */ } } }