[Zope-Checkins] CVS: Zope/lib/python/AccessControl - ImplPython.py:1.1.2.2 cAccessControl.c:1.20.2.7

Jim Fulton jim at zope.com
Fri Jan 16 16:04:52 EST 2004


Update of /cvs-repository/Zope/lib/python/AccessControl
In directory cvs.zope.org:/tmp/cvs-serv16799/lib/python/AccessControl

Modified Files:
      Tag: Zope-2_7-branch
	ImplPython.py cAccessControl.c 
Log Message:
Changed the strategy for handling special list and dict methods.

See the doc string for SimpleObjectPolicies.

Changed guarded_getattr to use the new strategy.


=== Zope/lib/python/AccessControl/ImplPython.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/AccessControl/ImplPython.py:1.1.2.1	Thu Jan  8 18:33:43 2004
+++ Zope/lib/python/AccessControl/ImplPython.py	Fri Jan 16 16:04:50 2004
@@ -526,32 +526,22 @@
     if name[:1] != '_':
         # Try to get the attribute normally so that unusual
         # exceptions are caught early.
-        try: v = getattr(inst, name)
+        try:
+            v = getattr(inst, name)
         except AttributeError:
             if default is not _marker:
                 return default
             raise
 
         assertion = Containers(type(inst))
-        if isinstance(assertion, dict):
-            # We got a table that lets us reason about individual
-            # attrs
-            assertion = assertion.get(name)
-            if assertion:
-                # There's an entry, but it may be a function.
-                if callable(assertion):
-                    return assertion(inst, name)
-
-                # Nope, it's boolean
-                return v
-            raise Unauthorized, name
-
-        elif assertion:
-            # So the entry in the outer table is not a dict
-            # It's allowed to be a vetoing function:
+        if assertion:
             if callable(assertion):
-                assertion(name, v)
-            # No veto, so we can return
+                factory = assertion(name, v)
+                if callable(factory):
+                    return factory(inst, name)
+                assert factory == 1
+            else:
+                assert assertion == 1
             return v
 
         validate = SecurityManagement.getSecurityManager().validate


=== Zope/lib/python/AccessControl/cAccessControl.c 1.20.2.6 => 1.20.2.7 ===
--- Zope/lib/python/AccessControl/cAccessControl.c:1.20.2.6	Wed Jan 14 13:58:03 2004
+++ Zope/lib/python/AccessControl/cAccessControl.c	Fri Jan 16 16:04:50 2004
@@ -2114,73 +2114,37 @@
         }
 
       /*
-            assertion = Containers(type(inst))
-            if type(assertion) is DictType:
-                # We got a table that lets us reason about individual
-                # attrs
-                assertion = assertion.get(name)
-                if assertion:
-                    # There's an entry, but it may be a function.
-                    if callable(assertion):
-                        return assertion(inst, name)
-
-                    # Nope, it's boolean
-                    return v
-                raise Unauthorized, name
-            
-            elif assertion:
-                # So the entry in the outer table is not a dict 
-                # It's allowed to be a vetoing function:
-                if callable(assertion):
-                    assertion(name, v)
-                # No veto, so we can return
-                return v
+
+        assertion = Containers(type(inst))
+        if assertion:
+            if callable(assertion):
+                factory = assertion(name, v)
+                if callable(factory):
+                    return factory(inst, name)
+                assert factory == 1
+            assert callable == 1
+            return v
+
       */
       t = PyDict_GetItem(ContainerAssertions, OBJECT(inst->ob_type));
       if (t != NULL)
         {
-          if (PyDict_Check(t))
+          if (PyCallable_Check(t))
             {
-              PyObject *attrv;
-              
-              attrv = PyDict_GetItem(t, name);
-              if (attrv != NULL)
-                {
-                  i=PyObject_IsTrue(attrv);
-                  if (i < 0) goto err;
-                  if (i) 
-                    {
-                      if (attrv->ob_type->tp_call)
-                        {
-                          Py_DECREF(v);
-                          v = callfunction2(attrv, inst, name);
-                          return v;
-                        }
-                      return v;
-                    }
-                }
-              Py_DECREF(v);
-              goto unauth;
-            }
-          
-          i = PyObject_IsTrue(t);
-          if (i < 0) goto err;
-          if (i)
-            {
-              if (t->ob_type->tp_call)
+              PyObject *factory;
+
+              factory = callfunction2(t, name, v);
+              if (factory == NULL) 
+                goto err;
+
+              if (PyCallable_Check(factory))
                 {
-                  PyObject *ignored;
-                  ignored = callfunction2(t, name, v);
-                  if (ignored == NULL)
-                    {
-                      /* veto */
-                      Py_DECREF(v);
-                      return NULL;
-                    }
-                  Py_DECREF(ignored);
+                  Py_DECREF(v);
+                  v = callfunction2(factory, inst, name);
                 }
-              return v;
+              Py_DECREF(factory);
             }
+          return v;
         }
 
       /*
@@ -2212,7 +2176,6 @@
       return NULL;
     }
 
- unauth:
   /* raise Unauthorized, name */
   PyErr_SetObject(Unauthorized, name);
   return NULL;




More information about the Zope-Checkins mailing list