[Zope3-checkins] CVS: Zope3/src/zope/security - manager.py:1.4
Steve Alexander
steve@cat-box.net
Mon, 2 Jun 2003 10:34:49 -0400
Update of /cvs-repository/Zope3/src/zope/security
In directory cvs.zope.org:/tmp/cvs-serv16524/src/zope/security
Modified Files:
manager.py
Log Message:
Reformatting.
Changed __implements__ to implements(...)
=== Zope3/src/zope/security/manager.py 1.3 => 1.4 ===
--- Zope3/src/zope/security/manager.py:1.3 Thu Mar 13 13:49:16 2003
+++ Zope3/src/zope/security/manager.py Mon Jun 2 10:34:49 2003
@@ -15,7 +15,7 @@
$Id$
"""
-
+from zope.interface import implements
from zope.security.simplepolicies import ParanoidSecurityPolicy
MAX_STACK_SIZE = 100
@@ -31,11 +31,10 @@
def setSecurityPolicy(aSecurityPolicy):
- """
- Set the system default security policy.
+ """Set the system default security policy.
- This method should only be caused by system startup code. It should
- never, for example, be called during a web request.
+ This method should only be caused by system startup code. It should never,
+ for example, be called during a web request.
"""
global _defaultPolicy
@@ -46,19 +45,17 @@
from zope.security.interfaces import ISecurityManager
class SecurityManager:
+ """A security manager provides methods for checking access and managing
+ executable context and policies.
"""
- A security manager provides methods for checking access and managing
- executable context and policies.
- """
- __implements__ = ISecurityManager
+ implements(ISecurityManager)
def __init__(self, context):
self._context = context
self._policy = None
def _getPolicy(self):
- """
- Find current policy, or default.
+ """Find current policy, or default.
"""
policy = self._policy
if policy is None:
@@ -69,37 +66,34 @@
# ISecurityManager implementation
#
def getPrincipal(self):
- """
- Return the authenticated user.
+ """Return the authenticated user.
- This is equivalent to something like::
+ This is equivalent to something like::
- REQUEST['AUTHENTICATED_USER']
+ REQUEST['AUTHENTICATED_USER']
- but is a bit cleaner, especially if 'REQUEST' isn't handy.
+ but is a bit cleaner, especially if 'REQUEST' isn't handy.
"""
return self._context.user
def checkPermission(self, permission, object):
- """
- Check whether the security context allows the given
- permission on the given object. Return a boolean value.
+ """Check whether the security context allows the given
+ permission on the given object. Return a boolean value.
- Arguments:
+ Arguments:
permission -- A permission name
object -- The object being accessed according to the permission
"""
- return self._getPolicy().checkPermission(permission, object
- , self._context)
+ return self._getPolicy().checkPermission(permission, object,
+ self._context)
def pushExecutable(self, anExecutableObject):
+ """Push an ExecutableObject onto the manager's stack, and
+ activate its custom security policy, if any.
"""
- Push an ExecutableObject onto the manager's stack, and
- activate its custom security policy, if any.
- """
- stack=self._context.stack
+ stack = self._context.stack
if len(stack) >= MAX_STACK_SIZE:
raise SystemError, 'Excessive recursion'
@@ -113,11 +107,10 @@
self._policy = p
def popExecutable(self, anExecutableObject):
+ """Pop the topmost ExecutableObject from the stack, deactivating
+ any custom security policy it might have installed.
"""
- Pop the topmost ExecutableObject from the stack, deactivating
- any custom security policy it might have installed.
- """
- stack=self._context.stack
+ stack = self._context.stack
if not stack:
return
@@ -130,7 +123,7 @@
indexes = range(len(stack))
indexes.reverse()
for i in indexes:
- top=stack[i]
+ top = stack[i]
if top is anExecutableObject:
del stack[i:]
break
@@ -138,24 +131,21 @@
return
if stack:
-
top = stack[-1]
p = getattr(top, '_customSecurityPolicy', None)
if p is not None:
- p=p()
- self._policy=p
-
+ p = p()
+ self._policy = p
else:
- self._policy=None
+ self._policy = None
def calledByExecutable(self):
- """
- Return a boolean indicating whether the current request has
- invoked any IExecutableObjects.
+ """Return a boolean indicating whether the current request has
+ invoked any IExecutableObjects.
- This can be used to determine if an object was called
- (more or less) directly from a URL, or if it was called by
- through-the-web provided code.
+ This can be used to determine if an object was called (more or less)
+ directly from a URL, or if it was called by through-the-web provided
+ code.
"""
return len(self._context.stack)