[Zodb-checkins] CVS: Zope/lib/Components/ExtensionClass/src - Acquisition.c:1.52.8.2
Jim Fulton
jim@zope.com
Thu, 25 Oct 2001 12:35:15 -0400
Update of /cvs-repository/Zope/lib/Components/ExtensionClass/src
In directory cvs.zope.org:/tmp/cvs-serv28851/lib/Components/ExtensionClass/src
Modified Files:
Tag: ComponentArchitecture-branch
Acquisition.c
Log Message:
Various changes (in progress) to reflect tutorial.
Checking in to sync with Shane.
=== Zope/lib/Components/ExtensionClass/src/Acquisition.c 1.52.8.1 => 1.52.8.2 ===
/* ---------------------------------------------------------------- */
+static PyObject *
+newWrapper(PyObject *obj, PyObject *container, PyTypeObject *Wrappertype);
static PyObject *
__of__(PyObject *inst, PyObject *parent)
{
PyObject *r, *t;
- UNLESS(r=PyObject_GetAttr(inst, py__of__)) return NULL;
- UNLESS(t=PyTuple_New(1)) goto err;
- PyTuple_SET_ITEM(t,0,parent);
- ASSIGN(r,PyObject_CallObject(r,t));
- PyTuple_SET_ITEM(t,0,NULL);
- Py_DECREF(t);
-
+ r=PyObject_GetAttr(inst, py__of__);
+ if (r)
+ {
+ UNLESS(t=PyTuple_New(1)) goto err;
+ PyTuple_SET_ITEM(t,0,parent);
+ ASSIGN(r,PyObject_CallObject(r,t));
+ PyTuple_SET_ITEM(t,0,NULL);
+ Py_DECREF(t);
+ }
+ else
+ {
+ PyErr_Clear();
+ if (isWrapper(inst))
+ /* We have a wrapper that wraps something that has no __of__. */
+ r=newWrapper(inst, parent, inst->ob_type);
+ else
+ {
+ Py_INCREF(inst);
+ return inst;
+ }
+ }
+
if (r
&& r->ob_refcnt==1
&& isWrapper(r)
@@ -1601,6 +1618,16 @@
}
+static PyObject *
+module_binder(PyObject *ignored, PyObject *args)
+{
+ if (PyArg_ParseTuple(args, "O", &ignored))
+ ignored = PyObject_GetAttr(ignored, py__of__);
+ else
+ ignored = 0;
+ return ignored;
+}
+
static struct PyMethodDef methods[] = {
{"aq_acquire", (PyCFunction)module_aq_acquire, METH_VARARGS|METH_KEYWORDS,
"aq_acquire(ob, name [, filter, extra, explicit]) -- "
@@ -1612,6 +1639,9 @@
},
{"aq_base", (PyCFunction)module_aq_base, METH_VARARGS,
"aq_base(ob) -- Get the object unwrapped"},
+ {"binder", (PyCFunction)module_binder, METH_VARARGS,
+ "binder(ob) -- Get a callable that, when passed a context,"
+ " will wrap the object in the context."},
{"aq_parent", (PyCFunction)module_aq_parent, METH_VARARGS,
"aq_parent(ob) -- Get the parent of an object"},
{"aq_self", (PyCFunction)module_aq_self, METH_VARARGS,