[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - protectClass.py:1.1.2.4
Ken Manheimer
klm@zope.com
Fri, 30 Nov 2001 17:06:59 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv25132
Modified Files:
Tag: Zope-3x-branch
protectClass.py
Log Message:
Shuffled implementation so we can derive for public class.
Specifically, added explicit ._getPermission(), so we can vette the
permission passed in.
=== Zope3/lib/python/Zope/App/Security/protectClass.py 1.1.2.3 => 1.1.2.4 ===
"instances" can then be used. [XXX this needs to be fleshed out.]
-Invalid protection declarations provoke instances of the
-ProtectionDeclarationException class."""
+Invalid protection declarations raise ProtectionDeclarationException
+instances."""
from Zope.Configuration.name import resolve
from Interface.Method import Method
@@ -41,6 +41,20 @@
# So subsequent simple-declaration-style self() calls process instances
self.__empty = 1
+ # ._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, permission=None, interface=None,
method=None, methods=None):
"Protect a specific aspect"
@@ -49,13 +63,10 @@
if not (interface or method or methods):
return
- if permission is None:
- permission = self.__permission
- if permission is None:
- raise ProtectionDeclarationException("No permission specified")
+ permission = self._getPermission(permission)
if interface:
- self.__protectInterface(interface, permission)
+ self.__protectByInterface(interface, permission)
if method:
self.__protectMethod(method, permission)
if methods:
@@ -65,10 +76,7 @@
"Protect instances of the class, as opposed to methods"
self.__empty = 0
- if permission is None:
- permission = self.__permission
- if permission is None:
- raise ProtectionDeclarationException("No permission specified")
+ permission = self._getPermission(permission)
self.__class.__permission__ = permission
def __protectMethod(self, method, permission):
@@ -90,7 +98,7 @@
self.__protectMethod(method.strip(), permission)
- def __protectInterface(self, interface, permission):
+ def __protectByInterface(self, interface, permission):
"Set a permission on methods in an interface."
interface = resolve(interface)
for n, d in interface.namesAndDescriptions():
@@ -101,6 +109,3 @@
"Handle empty/simple declaration."
if self.__empty:
self.instances(self.__permission)
-
-def publicClass(name, interface=None, method=None, methods=None):
- "Declare a class and some of it's methods to be public"