Commit b8153d8e authored by Brian Lloyd's avatar Brian Lloyd

fix & document setImplementation semantics

parent adacd32f
...@@ -31,12 +31,18 @@ def getImplementationName(): ...@@ -31,12 +31,18 @@ def getImplementationName():
def setImplementation(name): def setImplementation(name):
"""Select the policy implementation to use. """Select the policy implementation to use. The 'name' must be either
'PYTHON' or 'C'. NOTE: this function is intended to be called
'name' must be either 'PYTHON' or 'C'. exactly once, so that the Zope config file can dictate the policy
implementation to be used. Subsequent calls to this function will
have no effect!!
""" """
import sys import sys
global _implementation_name global _implementation_name
global _implementation_set
if _implementation_set:
return
name = name.upper() name = name.upper()
if name == _implementation_name: if name == _implementation_name:
...@@ -57,8 +63,10 @@ def setImplementation(name): ...@@ -57,8 +63,10 @@ def setImplementation(name):
if hasattr(mod, "initialize"): if hasattr(mod, "initialize"):
mod.initialize(impl) mod.initialize(impl)
_implementation_set = 1
_implementation_name = None _implementation_name = None
_implementation_set = 0
_policy_names = { _policy_names = {
"AccessControl": ("setDefaultBehaviors", "AccessControl": ("setDefaultBehaviors",
......
...@@ -37,17 +37,27 @@ class AccessControlImplementationTest(unittest.TestCase): ...@@ -37,17 +37,27 @@ class AccessControlImplementationTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
setImplementation(self.original) setImplementation(self.original)
def test_setImplemenationC(self): ## Note - this test is disabled because the intent for 2.7 was *not*
setImplementation("C") ## to support the ability to arbitrarily switch the security policy
name = getImplementationName() ## at any time (which would currently be nearly impossible to do in
if self.have_cAccessControl: ## a way that would be sane for 3rd party apps that may already have
self.assertEqual(name, "C") ## imported parts of the security machinery), but just to make sure
else: ## that the config file could be used to initially set the implementation
self.assertEqual(name, "PYTHON") ## to be used. The policy setting is 'initialize once' - setImplementation
## should not be called either by user code or unit tests, as the
## effects are officially undefined.
## def test_setImplemenationC(self):
## setImplementation("C")
## name = getImplementationName()
## if self.have_cAccessControl:
## self.assertEqual(name, "C")
## else:
## self.assertEqual(name, "PYTHON")
def test_setImplemenationPython(self): ## def test_setImplemenationPython(self):
setImplementation("Python") ## setImplementation("Python")
self.assertEqual(getImplementationName(), "PYTHON") ## self.assertEqual(getImplementationName(), "PYTHON")
def test_suite(): def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment