[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - _Proxy.c:1.1.2.6
Guido van Rossum
guido@python.org
Thu, 18 Apr 2002 14:27:19 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Security
In directory cvs.zope.org:/tmp/cvs-serv12232
Modified Files:
Tag: SecurityProxy-branch
_Proxy.c
Log Message:
Add and test check_{get,set}item().
=== Zope3/lib/python/Zope/Security/_Proxy.c 1.1.2.5 => 1.1.2.6 ===
}
-
-static int
-proxy_setattr(PyObject *proxy, PyObject *name, PyObject *value)
-{
- return PyObject_SetAttr(Proxy_GetObject(proxy), name, value);
-}
-
static int
proxy_compare(PyObject *proxy, PyObject *v)
{
@@ -249,14 +242,49 @@
*/
static PyObject *
-proxy_getitem(PyObject *proxy, PyObject *v) {
- return PyObject_GetItem(Proxy_GetObject(proxy), v);
+proxy_getitem(PyObject *self, PyObject *key)
+{
+ PyObject *result = NULL;
+ PyObject *object = Proxy_GetObject(self);
+ PyObject *checker = Proxy_GetChecker(self);
+ PyObject *checked, *value;
+
+ /*
+ * checked = checker.check_getitem(object, key)
+ * value = object[key]
+ * return checker.proxy(value, checked)
+ */
+ checked = PyObject_CallMethod(
+ checker, "check_getitem", "(OO)", object, key);
+ if (checked != NULL) {
+ value = PyObject_GetItem(object, key);
+ if (value != NULL) {
+ result = PyObject_CallMethod(
+ checker, "proxy", "(OO)", value, checked);
+ Py_DECREF(value);
+ }
+ Py_DECREF(checked);
+ }
+ return result;
}
static int
proxy_setitem(PyObject *self, PyObject *key, PyObject *value)
{
- return PyObject_SetItem(Proxy_GetObject(self), key, value);
+ PyObject *object = Proxy_GetObject(self);
+ PyObject *checker = Proxy_GetChecker(self);
+ PyObject *checked;
+
+ /*
+ * checked = checker.check_setitem(object, key)
+ * object[key] = value
+ */
+ checked = PyObject_CallMethod(
+ checker, "check_setitem", "(OO)", object, key);
+ if (checked == NULL)
+ return -1;
+ Py_DECREF(checked);
+ return PyObject_SetItem(object, key, value);
}
/*