[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - _Proxy.c:1.1.2.3
Guido van Rossum
guido@python.org
Thu, 18 Apr 2002 12:35:16 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Security
In directory cvs.zope.org:/tmp/cvs-serv8834
Modified Files:
Tag: SecurityProxy-branch
_Proxy.c
Log Message:
Check __repr__ as well. Added a generic function for calling unary
checkers.
=== Zope3/lib/python/Zope/Security/_Proxy.c 1.1.2.2 => 1.1.2.3 ===
/*
+ * Machinery to call the checker.
+ */
+
+typedef PyObject *(*function1)(PyObject *);
+
+static PyObject *
+check1(ProxyObject *self, char *check_method, function1 operation)
+{
+ PyObject *result = NULL;
+ PyObject *object = self->proxy_object;
+ PyObject *checker = self->proxy_checker;
+ PyObject *checked, *value;
+
+ /*
+ * checked = checker.check_method(object)
+ * value = operation(object)
+ * return checker.proxy(value, checked)
+ */
+ checked = PyObject_CallMethod(checker, check_method, "(O)", object);
+ if (checked != NULL) {
+ value = operation(object);
+ if (value != NULL) {
+ result = PyObject_CallMethod(
+ checker, "proxy", "(OO)", value, checked);
+ Py_DECREF(value);
+ }
+ Py_DECREF(checked);
+ }
+ return result;
+}
+
+
+/*
* Slot methods.
*/
@@ -119,34 +152,13 @@
static PyObject *
proxy_str(PyObject *self)
{
- PyObject *result = NULL;
- PyObject *object = Proxy_GetObject(self);
- PyObject *checker = Proxy_GetChecker(self);
- PyObject *checked, *value;
-
- /*
- * checked = checker.check_str(object)
- * value = str(object)
- * return checker.proxy(value, checked)
- */
- checked = PyObject_CallMethod(
- checker, "check_str", "(O)", object);
- if (checked != NULL) {
- value = PyObject_Str(object);
- if (value != NULL) {
- result = PyObject_CallMethod(
- checker, "proxy", "(OO)", value, checked);
- Py_DECREF(value);
- }
- Py_DECREF(checked);
- }
- return result;
+ return check1((ProxyObject *)self, "check_str", PyObject_Str);
}
static PyObject *
-proxy_repr(PyObject *proxy)
+proxy_repr(PyObject *self)
{
- return PyObject_Repr(Proxy_GetObject(proxy));
+ return check1((ProxyObject *)self, "check_repr", PyObject_Repr);
}