189: #line 2036 "mxTools.pak" 190: def proper_acquire(object, name, functor='baseobj'): 191: if hasattr(object, name): 192: return getattr(object,name) 193: return acquire(object, name, functor) 194: 195: def acquire(object, name, functor='baseobj'): 196: if not hasattr(object,functor): 197: raise AttributeError,functor 198: return proper_acquire(getattr(object, functor), name, functor) 199:
1748: #line 2047 "mxTools.pak" 1749: 1750: Py_C_Function( mxTools_acquire, 1751: "acquire(self,name)\n\n" 1752: "Tries to get the attribute name from self.baseobj.\n" 1753: "If this is not defined or None, an AttributeError is\n" 1754: "raised. Otherwise the getattr(self.baseobj,name) is\n" 1755: "returned. Attribute names must not start with an\n" 1756: "underscore (this too raises an AttributeError).\n") 1757: { 1758: PyObject *obj,*baseobj,*name; 1759: PyObject *v; 1760: static PyObject *baseobjstr; 1761: 1762: Py_Get2Args("OO",obj,name); 1763: 1764: Py_Assert(PyString_Check(name), 1765: PyExc_TypeError, 1766: "attribute name must be a string"); 1767: 1768: /* We don't acquire names starting with underscores */ 1769: Py_Assert(PyString_AS_STRING(name)[0] != '_', 1770: PyExc_AttributeError, 1771: PyString_AS_STRING(name)); 1772: 1773: /* Get obj.baseobj */ 1774: if (baseobjstr == NULL) { 1775: baseobjstr = PyString_FromString("baseobj"); 1776: if (!baseobjstr) 1777: goto onError; 1778: } 1779: baseobj = PyObject_GetAttr(obj,baseobjstr); 1780: if (!baseobj || baseobj == Py_None) { 1781: Py_XDECREF(baseobj); 1782: Py_Error(PyExc_AttributeError, 1783: PyString_AS_STRING(name)); 1784: } 1785: 1786: /* Now return getattr(obj.baseobj,name) */ 1787: v = PyObject_GetAttr(baseobj,name); 1788: Py_DECREF(baseobj); 1789: return v; 1790: 1791: onError: 1792: return NULL; 1793: } 1794: