[Zope3-checkins]
SVN: Zope3/branches/mgedmin-security/src/zope/security/
Implemented IInteractionManagement.
Marius Gedminas
marius at pov.lt
Wed May 12 14:48:08 EDT 2004
Log message for revision 24599:
Implemented IInteractionManagement.
-=-
Modified: Zope3/branches/mgedmin-security/src/zope/security/interfaces.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/security/interfaces.py 2004-05-12 18:33:45 UTC (rev 24598)
+++ Zope3/branches/mgedmin-security/src/zope/security/interfaces.py 2004-05-12 18:48:08 UTC (rev 24599)
@@ -187,7 +187,7 @@
"""
-class ISecurityPolicy(Interface):
+class ISecurityPolicy(Interface): # XXX: will change
def checkPermission(permission, object, context):
"""Return whether security context allows permission on object.
Modified: Zope3/branches/mgedmin-security/src/zope/security/management.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/security/management.py 2004-05-12 18:33:45 UTC (rev 24598)
+++ Zope3/branches/mgedmin-security/src/zope/security/management.py 2004-05-12 18:48:08 UTC (rev 24599)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Default 'ISecurityManagement' implementation
+"""Default 'ISecurityManagement' and 'IInteractionManagement' implementation
$Id: management.py,v 1.5 2004/02/20 20:42:12 srichter Exp $
"""
@@ -22,12 +22,16 @@
from zope.interface import moduleProvides
from zope.security.interfaces import ISecurityManagement
from zope.security.interfaces import ISecurityManagementSetup
+from zope.security.interfaces import IInteractionManagement
from zope.security.manager import SecurityManager
from zope.security.manager import setSecurityPolicy as _setSecurityPolicy
from zope.security.manager import getSecurityPolicy as _getSecurityPolicy
from zope.security.context import SecurityContext
+from zope.testing.cleanup import addCleanUp
+from zope.thread import thread_globals
-moduleProvides(ISecurityManagement, ISecurityManagementSetup)
+moduleProvides(ISecurityManagement, ISecurityManagementSetup,
+ IInteractionManagement)
try:
import thread
@@ -94,3 +98,38 @@
It should never, for example, be called during a web request.
"""
return _setSecurityPolicy(aSecurityPolicy)
+
+
+#
+# IInteractionManagement implementation
+#
+
+def getInteraction(_thread=None):
+ """Get the current interaction."""
+ return thread_globals(_thread).interaction
+
+def newInteraction(participation=None, _thread=None, _policy=None):
+ """Start a new interaction."""
+ if getInteraction(_thread) is not None:
+ stack = getInteraction(_thread)._newInteraction_called_from
+ raise AssertionError("newInteraction called"
+ " while another interaction is active:\n%s"
+ % "".join(traceback.format_list(stack)))
+ interaction = _defaultPolicy.createInteraction(participation)
+ interaction._newInteraction_called_from = traceback.extract_stack()
+ thread_globals(_thread).interaction = interaction
+
+def endInteraction(_thread=None):
+ """End the current interaction."""
+ if getInteraction(_thread=_thread) is None:
+ raise AssertionError("endInteraction called"
+ " without an active interaction")
+ thread_globals(_thread).interaction = None
+
+
+def _cleanUp():
+ thread_globals().interaction = None
+
+addCleanUp(_cleanUp)
+
+
Modified: Zope3/branches/mgedmin-security/src/zope/security/tests/test_management.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/security/tests/test_management.py 2004-05-12 18:33:45 UTC (rev 24598)
+++ Zope3/branches/mgedmin-security/src/zope/security/tests/test_management.py 2004-05-12 18:48:08 UTC (rev 24599)
@@ -32,9 +32,11 @@
from zope.security.interfaces import ISecurityManagement
from zope.security.interfaces \
import ISecurityManagementSetup
+ from zope.security.interfaces import IInteractionManagement
verifyObject(ISecurityManagementSetup, management)
verifyObject(ISecurityManagement, management)
+ verifyObject(IInteractionManagement, management)
def test_ISecurityManagementSetup(self):
More information about the Zope3-Checkins
mailing list