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

Guido van Rossum guido@python.org
Mon, 13 May 2002 14:00:05 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	_Proxy.c 
Log Message:
Add implementations for sq_item and sq_ass_item -- these may be called
by PySequence_{Get,Set}Item and it will fail if these don't exist,
even if the mapping getitem/setitem are defined.


=== Zope3/lib/python/Zope/Security/_Proxy.c 1.1.4.1 => 1.1.4.2 ===
 /*
  * Sequence methods.
- * (If you have mapping getitem/setitem, sequence getitem/setitem
- * never get called.)
  */
 
 static int
@@ -533,6 +531,37 @@
 	return -1;
 }
 
+/* sq_item and sq_ass_item may be called by PySequece_{Get,Set}Item(). */
+staticforward PyObject *proxy_getitem(PyObject *, PyObject *);
+staticforward int proxy_setitem(PyObject *, PyObject *, PyObject *);
+
+static PyObject *
+proxy_igetitem(PyObject *self, int i)
+{
+	PyObject *key = PyInt_FromLong(i);
+	PyObject *res = NULL;
+
+	if (key != NULL) {
+		res = proxy_getitem(self, key);
+		Py_DECREF(key);
+	}
+	return res;
+}
+
+
+static int
+proxy_isetitem(PyObject *self, int i, PyObject *value)
+{
+	PyObject *key = PyInt_FromLong(i);
+	int res = -1;
+
+	if (key != NULL) {
+		res = proxy_setitem(self, key, value);
+		Py_DECREF(key);
+	}
+	return res;
+}
+
 static PyObject *
 proxy_slice(PyObject *self, int start, int end)
 {
@@ -659,9 +688,9 @@
 	proxy_length,				/* sq_length */
 	0,					/* sq_concat */
 	0,					/* sq_repeat */
-	0,					/* sq_item */
+	proxy_igetitem,				/* sq_item */
 	proxy_slice,				/* sq_slice */
-	0,					/* sq_ass_item */
+	proxy_isetitem,				/* sq_ass_item */
 	proxy_ass_slice,				/* sq_ass_slice */
 	proxy_contains,				/* sq_contains */
 };