[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - _Proxy.c:1.1.2.11

Guido van Rossum guido@python.org
Thu, 18 Apr 2002 16:38:23 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Security
In directory cvs.zope.org:/tmp/cvs-serv9239

Modified Files:
      Tag: SecurityProxy-branch
	_Proxy.c 
Log Message:
Add the remaining operations, except for numeric ops,
and whatever was missing from Fred's original wrapper module.

=== Zope3/lib/python/Zope/Security/_Proxy.c 1.1.2.10 => 1.1.2.11 ===
 proxy_iter(PyObject *self)
 {
-	/* XXX check_iter */
-	return PyObject_GetIter(Proxy_GetObject(self));
+	PyObject *result = NULL;
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__iter__", object)) {
+		result = PyObject_GetIter(object);
+		if (result != NULL)
+			result = PyObject_CallMethod(
+				checker, "proxy", "(N)", result);
+	}
+	return result;
+}
+
+static PyObject *
+proxy_iternext(PyObject *self)
+{
+	PyObject *result = NULL;
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "next", object)) {
+		result = PyIter_Next(object);
+		if (result != NULL)
+			result = PyObject_CallMethod(
+				checker, "proxy", "(N)", result);
+	}
+	return result;
 }
 
 static PyObject *
@@ -191,17 +216,25 @@
 }
 
 static int
-proxy_compare(PyObject *proxy, PyObject *v)
+proxy_compare(PyObject *self, PyObject *other)
 {
-	/* XXX check_compare */
-	return PyObject_Compare(Proxy_GetObject(proxy), v);
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__cmp__", object))
+		return PyObject_Compare(object, other);
+	return -1;
 }
 
 static long
 proxy_hash(PyObject *self)
 {
-	/* XXX check_hash */
-	return PyObject_Hash(Proxy_GetObject(self));
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__hash__", object))
+		return PyObject_Hash(object);
+	return -1;
 }
 
 static PyObject *
@@ -228,8 +261,12 @@
 static int
 proxy_nonzero(PyObject *self)
 {
-	/* XXX check_nonzero */
-	return PyObject_IsTrue(Proxy_GetObject(self));
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__nonzero__", object))
+		return PyObject_IsTrue(object);
+	return -1;
 }
 
 /*
@@ -241,29 +278,50 @@
 static int
 proxy_length(PyObject *self)
 {
-	/* XXX check_len */
-	return PyObject_Length(Proxy_GetObject(self));
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__nonzero__", object))
+		return PyObject_Length(object);
+	return -1;
 }
 
 static PyObject *
 proxy_slice(PyObject *self, int start, int end)
 {
-	/* XXX check_getslice */
-	return PySequence_GetSlice(Proxy_GetObject(self), start, end);
+	PyObject *result = NULL;
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__getslice__", object)) {
+		result = PySequence_GetSlice(object, start, end);
+		if (result != NULL)
+			result = PyObject_CallMethod(
+				checker, "proxy", "(N)", result);
+	}
+	return result;
 }
 
 static int
 proxy_ass_slice(PyObject *self, int i, int j, PyObject *value)
 {
-	/* XXX check_setslice */
-	return PySequence_SetSlice(Proxy_GetObject(self), i, j, value);
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__setslice__", object))
+		return PySequence_SetSlice(object, i, j, value);
+	return -1;
 }
 
 static int
 proxy_contains(PyObject *self, PyObject *value)
 {
-	/* XXX check_contains */
-	return PySequence_Contains(Proxy_GetObject(self), value);
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+
+	if (check(checker, "__contains__", object))
+		return PySequence_Contains(object, value);
+	return -1;
 }
 
 /*
@@ -365,7 +423,7 @@
 	proxy_richcompare,			/* tp_richcompare */
 	0,					/* tp_weaklistoffset */
 	proxy_iter,				/* tp_iter */
-	0,					/* tp_iternext */
+	proxy_iternext,				/* tp_iternext */
 	0,					/* tp_methods */
 	0,					/* tp_members */
 	0,					/* tp_getset */