summaryrefslogtreecommitdiff
path: root/src/zope/security/management.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/zope/security/management.py')
-rw-r--r--src/zope/security/management.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/zope/security/management.py b/src/zope/security/management.py
index 1acc3d3..2daf0ce 100644
--- a/src/zope/security/management.py
+++ b/src/zope/security/management.py
@@ -52,10 +52,12 @@ moduleProvides(
# ISecurityManagement implementation
#
+
def getSecurityPolicy():
"""Get the system default security policy."""
return _defaultPolicy
+
def setSecurityPolicy(aSecurityPolicy):
"""Set the system default security policy, and return the previous
value.
@@ -78,6 +80,7 @@ def queryInteraction():
"""Return a current interaction, if there is one."""
return getattr(thread_local, 'interaction', None)
+
def getInteraction():
"""Get the current interaction."""
try:
@@ -85,14 +88,16 @@ def getInteraction():
except AttributeError:
raise NoInteraction
+
class ExistingInteraction(ValueError,
- AssertionError, #BBB
- ):
+ AssertionError, # BBB
+ ):
"""
The exception that :func:`newInteraction` will raise if called
during an existing interaction.
"""
+
def newInteraction(*participations):
"""Start a new interaction."""
if queryInteraction() is not None:
@@ -100,6 +105,7 @@ def newInteraction(*participations):
" while another interaction is active.")
thread_local.interaction = getSecurityPolicy()(*participations)
+
def endInteraction():
"""End the current interaction."""
@@ -116,6 +122,7 @@ def endInteraction():
else:
del thread_local.interaction
+
def restoreInteraction():
try:
previous = thread_local.previous_interaction
@@ -127,6 +134,7 @@ def restoreInteraction():
else:
thread_local.interaction = previous
+
def checkPermission(permission, object, interaction=None):
"""Return whether security policy allows permission on object.
@@ -155,9 +163,10 @@ def _clear():
global _defaultPolicy
_defaultPolicy = ParanoidSecurityPolicy
+
try:
from zope.testing.cleanup import addCleanUp
-except ImportError: # pragma: no cover
+except ImportError: # pragma: no cover
pass
else:
addCleanUp(_clear)