summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@monkeypox.org>2009-12-27 15:53:48 -0800
committerR. Tyler Ballance <tyler@monkeypox.org>2009-12-27 15:55:52 -0800
commit142b8343f9d7ac3b0f32419a120be2856d2251e8 (patch)
tree9ca172dce80fe12c3fc0028ab31ec4e91ab13cbe
parent0c35ef91d0a2940b4bf88638e33fe2c498401d6d (diff)
downloadpython-cheetah-142b8343f9d7ac3b0f32419a120be2856d2251e8.tar.gz
Since functions are properly objects in Python 3, need to start detecting them differently for auto-calling
-rw-r--r--cheetah/c/_namemapper.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/cheetah/c/_namemapper.c b/cheetah/c/_namemapper.c
index 4295c24..a41571b 100644
--- a/cheetah/c/_namemapper.c
+++ b/cheetah/c/_namemapper.c
@@ -81,22 +81,31 @@ static int isInstanceOrClass(PyObject *nextVal) {
}
#endif
- if(PyObject_HasAttrString(nextVal, "__class__")) {
- /* new style classes or instances */
- if(PyType_Check(nextVal) || PyObject_HasAttrString(nextVal, "mro")) {
- return 1;
- }
- if(PyObject_HasAttrString(nextVal, "im_func")
- || PyObject_HasAttrString(nextVal, "func_code")
- || PyObject_HasAttrString(nextVal, "__self__")) {
- /* method, func, or builtin func */
- return 0;
- }
- if ((!PyObject_HasAttrString(nextVal, "mro")) && PyObject_HasAttrString(nextVal, "__init__")) {
- /* instance */
- return 1;
- }
+ if (!PyObject_HasAttrString(nextVal, "__class__")) {
+ return 0;
}
+
+ /* new style classes or instances */
+ if (PyType_Check(nextVal) || PyObject_HasAttrString(nextVal, "mro")) {
+ return 1;
+ }
+
+ if (strncmp(nextVal->ob_type->tp_name, "function", 9) == 0)
+ return 0;
+
+ /* method, func, or builtin func */
+ if (PyObject_HasAttrString(nextVal, "im_func")
+ || PyObject_HasAttrString(nextVal, "func_code")
+ || PyObject_HasAttrString(nextVal, "__self__")) {
+ return 0;
+ }
+
+ /* instance */
+ if ((!PyObject_HasAttrString(nextVal, "mro")) &&
+ PyObject_HasAttrString(nextVal, "__init__")) {
+ return 1;
+ }
+
return 0;
}
@@ -154,10 +163,7 @@ static PyObject *PyNamemapper_valueForKey(PyObject *obj, char *key)
return theValue;
}
-static PyObject *
-PyNamemapper_valueForName(PyObject *obj, char *nameChunks[],
- int numChunks,
- int executeCallables)
+static PyObject *PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], int numChunks, int executeCallables)
{
int i;
char *currentKey;
@@ -196,14 +202,12 @@ PyNamemapper_valueForName(PyObject *obj, char *nameChunks[],
Py_DECREF(currentVal);
}
- if (executeCallables && PyCallable_Check(nextVal) && (!isInstanceOrClass(nextVal)) ) {
- //if (executeCallables && PyCallable_Check(nextVal) && (!PyInstance_Check(nextVal))
- //&& (!PyClass_Check(nextVal)) && (!PyType_Check(nextVal)) ) {
+ if (executeCallables && PyCallable_Check(nextVal) &&
+ (isInstanceOrClass(nextVal) == 0) ) {
if (!(currentVal = PyObject_CallObject(nextVal, NULL))) {
Py_DECREF(nextVal);
return NULL;
}
-
Py_DECREF(nextVal);
} else {
currentVal = nextVal;