[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/Grants - AnnotationRolePermissionManager.py:1.2 LocalSecurityMap.py:1.3

Florent Guillaume fg@nuxeo.com
Mon, 24 Jun 2002 07:17:58 -0400


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

Modified Files:
	AnnotationRolePermissionManager.py LocalSecurityMap.py 
Log Message:
Use PersistentMapping to store Local Security Map as annotations.

Also, that's not a 3-dimensional but a basic 2-dimensional array :)

(This kind of array is probably useful for other stuff and could be factored
out elsewhere.)


=== Zope3/lib/python/Zope/App/Security/Grants/AnnotationRolePermissionManager.py 1.1 => 1.2 ===
 from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
 from Zope.App.Security.IRolePermissionManager import IRolePermissionManager
-from Zope.App.Security.Grants.LocalSecurityMap import LocalSecurityMap
+from Zope.App.Security.Grants.PersistentLocalSecurityMap import \
+     PersistentLocalSecurityMap
 from Zope.App.Security.Settings import Allow, Deny, Unset
 
 annotation_key = 'Zope.App.Security.AnnotationRolePermissionManager'
@@ -105,7 +106,7 @@
             return annotations[annotation_key]
         except KeyError:
             if create:
-                rp = annotations[annotation_key] = LocalSecurityMap()
+                rp = annotations[annotation_key] = PersistentLocalSecurityMap()
                 return rp
         return None
 


=== Zope3/lib/python/Zope/App/Security/Grants/LocalSecurityMap.py 1.2 => 1.3 ===
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
-""" Generic three dimensional array type """
+""" Generic two-dimensional array type """
 
 from Zope.App.Security.Grants.ILocalSecurityMap import ILocalSecurityMap
 
@@ -26,11 +26,16 @@
         self._byrow = {}
         self._bycol = {}
 
+    def _empty_mapping(self):
+        return {}
+
     def addCell(self, rowentry, colentry, value):
-        row = self._byrow.setdefault(rowentry, {})
+        # setdefault may get expensive if an empty mapping is
+        # expensive to create, for PersistentMapping for instance.
+        row = self._byrow.setdefault(rowentry, self._empty_mapping())
         row[colentry] = value
 
-        col = self._bycol.setdefault(colentry, {})
+        col = self._bycol.setdefault(colentry, self._empty_mapping())
         col[rowentry] = value
 
     def delCell(self, rowentry, colentry):