[Zope3-checkins] CVS: Zope3/src/zope/context - wrapper.h:1.8 wrapper.c:1.26

Albertas Agejevas alga@codeworks.lt
Thu, 17 Jul 2003 10:00:09 -0400


Update of /cvs-repository/Zope3/src/zope/context
In directory cvs.zope.org:/tmp/cvs-serv27026/zope/context

Modified Files:
	wrapper.h wrapper.c 
Log Message:
Added a function to get to the descriptors without resolving them.


=== Zope3/src/zope/context/wrapper.h 1.7 => 1.8 ===
--- Zope3/src/zope/context/wrapper.h:1.7	Sat Jun  7 09:13:39 2003
+++ Zope3/src/zope/context/wrapper.h	Thu Jul 17 10:00:03 2003
@@ -34,6 +34,7 @@
     PyObject *(*getdictcreate)(PyObject *wrapper);
     int (*setobject)(PyObject *wrapper, PyObject *object);
     int (*setcontext)(PyObject *wrapper, PyObject *context);
+    PyObject *(*getdescriptor)(PyObject *obj, PyObject *name);
 } WrapperInterface;
 
 
@@ -90,7 +91,8 @@
         (_wrapper_api->setobject((wrapper), (object)))
 #define Wrapper_SetContext(wrapper, context) \
         (_wrapper_api->setcontext((wrapper), (context)))
-
+#define Wrapper_GetDescriptor(obj, name) \
+        (_wrapper_api->getdescriptor((obj), (name)))
 #endif
 
 #endif


=== Zope3/src/zope/context/wrapper.c 1.25 => 1.26 ===
--- Zope3/src/zope/context/wrapper.c:1.25	Sun Jul 13 09:45:23 2003
+++ Zope3/src/zope/context/wrapper.c	Thu Jul 17 10:00:03 2003
@@ -1206,6 +1206,18 @@
 }
 
 static PyObject *
+api_getdescriptor(PyObject *obj, PyObject *name) {
+    PyObject *res;
+    if (obj == NULL || name == NULL)
+	return missing_wrapper("getdescriptor");
+    res = _PyType_Lookup(obj->ob_type, name);
+    if (res == NULL)
+	res = Py_None;
+    Py_INCREF(res);
+    return res;
+}
+
+static PyObject *
 api_getobject(PyObject *wrapper)
 {
     if (wrapper == NULL)
@@ -1351,7 +1363,8 @@
     api_getdict,
     api_getdictcreate,
     api_setobject,
-    api_setcontext
+    api_setcontext,
+    api_getdescriptor
 };
 
 static char
@@ -1519,6 +1532,23 @@
 }
 
 static char
+getdescriptor__doc__[] =
+"getdescriptor(obj, name)\n"
+"\n"
+"get descriptor from obj's class.";
+static PyObject *
+wrapper_getdescriptor(PyObject *unused, PyObject *args)
+{
+    PyObject *obj;
+    PyObject *name;
+
+    if (PyArg_UnpackTuple(args, "getdescriptor", 2, 2, &obj, &name)) {
+        return api_getdescriptor(obj, name);
+    }
+    return NULL;
+}
+
+static char
 setcontext__doc__[] =
 "setcontext(wrapper, context)\n"
 "\n"
@@ -1560,6 +1590,8 @@
      setobject__doc__},
     {"setcontext",      wrapper_setcontext,      METH_VARARGS,
      setcontext__doc__},
+    {"getdescriptor",   wrapper_getdescriptor, METH_VARARGS,
+     getdescriptor__doc__},
     {NULL, NULL, 0, NULL}
 };