134: #line 1610 "mxTools.pak" 135: def findattr(object_list,attrname): 136: for object in object_list: 137: if hasattr(object, attrname): 138: return getattr(object, attrname) 139: raise AttributeError,attrname 140:
1383: #line 1617 "mxTools.pak" 1384: 1385: Py_C_Function( mxTools_findattr, 1386: "findattr(objectlist,attrname)\n\n" 1387: "Returns the first attribute with name attrname found\n" 1388: "among the objects in the list.") 1389: { 1390: PyObject *list; 1391: PyObject *name; 1392: register int i; 1393: int length; 1394: 1395: Py_Get2Args("OO",list,name); 1396: 1397: length = PySequence_Length(list); 1398: if (length < 0) 1399: Py_Error(PyExc_TypeError, 1400: "first argument must be a sequence"); 1401: 1402: Py_Assert(PyString_Check(name), 1403: PyExc_TypeError, 1404: "second argument must be a string"); 1405: 1406: for(i = 0; i < length; i++) { 1407: PyObject *v; 1408: PyObject *w; 1409: 1410: v = PySequence_GetItem(list,i); 1411: if (!v) 1412: goto onError; 1413: 1414: w = PyObject_GetAttr(v,name); 1415: if (w) 1416: return w; 1417: else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) 1418: goto onError; 1419: else 1420: PyErr_Clear(); 1421: } 1422: Py_Error(PyExc_AttributeError, 1423: PyString_AS_STRING(name)); 1424: onError: 1425: return NULL; 1426: } 1427: