[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security - Proxy.py:1.1.2.8 _Proxy.c:1.1.2.2

Guido van Rossum guido@python.org
Thu, 18 Apr 2002 12:24:13 -0400


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

Modified Files:
      Tag: SecurityProxy-branch
	Proxy.py _Proxy.c 
Log Message:
Wrap __str__.  Strings and unicode are rocks.

=== Zope3/lib/python/Zope/Security/Proxy.py 1.1.2.7 => 1.1.2.8 ===
     elif isinstance(obj, float):
         return obj
+    elif isinstance(obj, str):
+        return obj
+    elif isinstance(obj, unicode):
+        return obj
     elif isinstance(obj, _Proxy):
         return obj
     elif isinstance(obj, types.ClassType) and issubclass(obj, Exception):


=== Zope3/lib/python/Zope/Security/_Proxy.c 1.1.2.1 => 1.1.2.2 ===
+
 #include <Python.h>
 
 typedef struct {
@@ -84,15 +86,15 @@
 static PyObject *
 proxy_getattro(PyObject *self, PyObject *name)
 {
-	PyObject *object, *checker, *checked, *value;
 	PyObject *result = NULL;
+	PyObject *object = Proxy_GetObject(self);
+	PyObject *checker = Proxy_GetChecker(self);
+	PyObject *checked, *value;
 
-	object = Proxy_GetObject(self);
-	checker = Proxy_GetChecker(self);
 	/*
 	 * checked = checker.check_getattr(object, name)
 	 * value = getattr(object, name)
-	 * return checker.checkValue(value, checked)
+	 * return checker.proxy(value, checked)
 	 */
 	checked = PyObject_CallMethod(
 		checker, "check_getattr", "(OO)", object, name);
@@ -115,8 +117,30 @@
 }
 
 static PyObject *
-proxy_str(PyObject *proxy) {
-	return PyObject_Str(Proxy_GetObject(proxy));
+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;
 }
 
 static PyObject *