[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - metaConfigure.py:1.1.2.26.8.2 protectClass.py:1.1.2.14.2.3 security-meta.zcml:1.1.2.5.2.3 publicClass.py:NONE

Steve Alexander steve@cat-box.net
Mon, 3 Jun 2002 16:01:45 -0400


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

Modified Files:
      Tag: Zope3InWonderland-branch
	metaConfigure.py protectClass.py security-meta.zcml 
Removed Files:
      Tag: Zope3InWonderland-branch
	publicClass.py 
Log Message:
added content directive.


=== Zope3/lib/python/Zope/App/Security/metaConfigure.py 1.1.2.26.8.1 => 1.1.2.26.8.2 ===
 $Id$
 """
-
-
-from protectClass import protectClass
-from publicClass import publicClass
 from PermissionRegistry import permissionRegistry as perm_reg
 from RoleRegistry import roleRegistry as role_reg
 from Zope.Security.SecurityManager import setSecurityPolicy


=== Zope3/lib/python/Zope/App/Security/protectClass.py 1.1.2.14.2.2 => 1.1.2.14.2.3 ===
 """
 
-from Interface.Method import Method
 from Exceptions import UndefinedPermissionError
 from PermissionRegistry import permissionRegistry
 
-from Zope.Configuration.ConfigurationDirectiveInterfaces \
-     import INonEmptyDirective
-from Zope.Configuration.Action import Action
-
 from Zope.Security.Checker import defineChecker, getCheckerForInstancesOf
 from Zope.Security.Checker import Checker, CheckerPublic
 
-class ProtectionDeclarationException(Exception):
-    """Security-protection-specific exceptions."""
-    pass
-
-
-class protectClass:
-
-    __class_implements__ = INonEmptyDirective    
-    
-    def __init__(self, _context, class_, permission=None, interface=None,
-                 names=None, like_unto=None):
-        self.__class = _context.resolve(class_)
-        self.__name = class_
-        self.__permission = permission
-        self.__like_unto = like_unto
-        self.__context = _context
-        self.__r = self.protect(_context, permission, interface, names,
-                                like_unto)
-
-    # ._getPermission() is handy for subclassing with different permission
-    # policy, eg publicClass.
-    def _getPermission(self, permission=None):
-        """Return the permission to use.
-
-        Consider optional permission argument and permission specified on
-        class init."""
-        if permission is None:
-            permission = self.__permission
-        if permission is None:
-            raise ProtectionDeclarationException("No permission specified")
-        else:
-            return permission
-
-    def protect(self, _context, permission=None, interface=None,
-                names=None, like_unto=None):
-        "Protect a specific aspect"
-
-        r = []
-
-        if like_unto:
-            self.__protectLikeUnto(like_unto, r)
-
-        if not (interface or names):
-            return r
-        
-        permission = self._getPermission(permission)
-
-
-        if interface:
-            self.__protectByInterface(interface, permission, r)
-        if names:
-            self.__protectNames(names, permission, r)
-
-        return r
-
-    def __protectName(self, name, permission, r):
-        "Set a permission on a particular name."
-        r.append((
-            ('protectName', self.__class, name),
-            protectName, (self.__class, name, permission)))
-
-    def __protectNames(self, names, permission, r):
-        "Set a permission on a bunch of names."
-
-        if ',' in names:
-            raise TypeError("Names should not contain commas!")
-        
-        for name in names.strip().split():
-            self.__protectName(name.strip(), permission, r)
-
-    def __protectByInterface(self, interface, permission, r):
-        "Set a permission on names in an interface."
-        interface = self.__context.resolve(interface)
-        for n, d in interface.namesAndDescriptions(1):
-            self.__protectName(n, permission, r)
-
-    def __protectLikeUnto(self, like_unto, r):
-        "Set a permission on names in an interface."
-        like_unto = self.__context.resolve(like_unto)
-        r.append(
-            Action(discriminator=('protectLikeUnto', self.__class, object()),
-                   callable=protectLikeUnto,
-                   args=(self.__class, like_unto),
-                   )
-            )
-
-    def __call__(self):
-        "Handle empty/simple declaration."
-        return self.__r
-
-def _checkPermission(permission):
+def checkPermission(permission):
     """Check to make sure that the permission is valid.
     """
-    
     if not permissionRegistry.definedPermission(permission):
         raise UndefinedPermissionError(permission)
 
 def protectName(class_, name, permission):
     "Set a permission on a particular name."
+    
+    checkPermission(permission)
+    
     checker = getCheckerForInstancesOf(class_)
     if checker is None:
         checker = Checker({}.get)


=== Zope3/lib/python/Zope/App/Security/security-meta.zcml 1.1.2.5.2.2 => 1.1.2.5.2.3 ===
                attributes="id title description"
                handler="Zope.App.Security.metaConfigure.defineRole" />
-    <directive name="protectClass"
-               attributes="class permission interface names"
-               handler="Zope.App.Security.protectClass.">
-      <subdirective name="protect"
-                    attributes="permission interface names" />
-      </directive>
-    <directive name="publicClass" attributes="class interface names"
-               handler="Zope.App.Security.publicClass." />
     <directive name="defaultPolicy" attributes="name"
        handler="Zope.App.Security.metaConfigure.defaultPolicy" />
     <directive name="principal" attributes="id title description"

=== Removed File Zope3/lib/python/Zope/App/Security/publicClass.py ===