Commit f1fd494b authored by Hanno Schlichting's avatar Hanno Schlichting

Removed deprecated ``catalog-getObject-raises`` zope.conf option. The option...

Removed deprecated ``catalog-getObject-raises`` zope.conf option. The option was slated for removal in Zope 2.10.
parent 53e9915b
......@@ -35,6 +35,8 @@ Bugs Fixed
Restructuring
+++++++++++++
- Removed deprecated ``catalog-getObject-raises`` zope.conf option.
- Removed unmaintained HelpSys documents from ZCatalog and PluginIndexes.
Useful explanations are given inside the form templates.
......
......@@ -16,14 +16,9 @@ from zope.interface import implements
import Acquisition
from Acquisition import aq_parent
import Record
from ZODB.POSException import ConflictError
from interfaces import ICatalogBrain
# Switch for new behavior, raise exception instead of returning None.
# Use 'catalog-getObject-raises off' in zope.conf to restore old behavior.
GETOBJECT_RAISES = True
class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
"""Abstract base brain that handles looking up attributes as
......@@ -51,14 +46,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
Same as getObject, but does not do security checks.
"""
try:
return aq_parent(self).unrestrictedTraverse(self.getPath())
except ConflictError:
raise
except Exception:
if GETOBJECT_RAISES:
raise
return None
return aq_parent(self).unrestrictedTraverse(self.getPath())
def getObject(self, REQUEST=None):
"""Return the object for this record
......@@ -76,25 +64,9 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
return None
parent = aq_parent(self)
if len(path) > 1:
try:
parent = parent.unrestrictedTraverse(path[:-1])
except ConflictError:
raise
except Exception:
if GETOBJECT_RAISES:
raise
return None
try:
target = parent.restrictedTraverse(path[-1])
except ConflictError:
raise
except Exception:
if GETOBJECT_RAISES:
raise
return None
parent = parent.unrestrictedTraverse(path[:-1])
return target
return parent.restrictedTraverse(path[-1])
def getRID(self):
"""Return the record ID for this object."""
......
......@@ -99,27 +99,11 @@ class ConflictingCatalog(DummyCatalog):
raise ConflictError
class BrainsTestBase(object):
_old_flag = None
class TestBrains(unittest.TestCase):
def setUp(self):
self.cat = DummyCatalog()
self.cat.REQUEST = DummyRequest()
self._init_getOb_flag()
def tearDown(self):
if self._old_flag is not None:
self._restore_getOb_flag()
def _init_getOb_flag(self):
from Products.ZCatalog import CatalogBrains
self._old_flag = CatalogBrains.GETOBJECT_RAISES
CatalogBrains.GETOBJECT_RAISES = self._flag_value()
def _restore_getOb_flag(self):
from Products.ZCatalog import CatalogBrains
CatalogBrains.GETOBJECT_RAISES = self._old_flag
def _makeBrain(self, rid):
from Products.ZCatalog.CatalogBrains import AbstractCatalogBrain
......@@ -165,12 +149,6 @@ class BrainsTestBase(object):
self.assertEqual(b.getPath(), '/conflicter')
self.assertRaises(ConflictError, b.getObject)
class TestBrains(BrainsTestBase, unittest.TestCase):
def _flag_value(self):
return True
def testGetObjectRaisesUnauthorized(self):
from zExceptions import Unauthorized
b = self._makeBrain(2)
......@@ -185,25 +163,7 @@ class TestBrains(BrainsTestBase, unittest.TestCase):
self.assertRaises((NotFound, AttributeError, KeyError), b.getObject)
class TestBrainsOldBehavior(BrainsTestBase, unittest.TestCase):
def _flag_value(self):
return False
def testGetObjectReturnsNoneForUnauthorized(self):
b = self._makeBrain(2)
self.assertEqual(b.getPath(), '/secret')
self.assertEqual(b.getObject(), None)
def testGetObjectReturnsNoneForMissing(self):
b = self._makeBrain(3)
self.assertEqual(b.getPath(), '/zonked')
self.assertRaises(KeyError, self.cat.getobject, 3)
self.assertEqual(b.getObject(), None)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestBrains))
suite.addTest(unittest.makeSuite(TestBrainsOldBehavior))
return suite
......@@ -709,8 +709,6 @@ class PickySecurityManager:
class TestZCatalogGetObject(unittest.TestCase):
# Test what objects are returned by brain.getObject()
_old_flag = None
def setUp(self):
from Products.ZCatalog.ZCatalog import ZCatalog
catalog = ZCatalog('catalog')
......@@ -722,17 +720,6 @@ class TestZCatalogGetObject(unittest.TestCase):
def tearDown(self):
noSecurityManager()
if self._old_flag is not None:
self._restore_getObject_flag()
def _init_getObject_flag(self, flag):
from Products.ZCatalog import CatalogBrains
self._old_flag = CatalogBrains.GETOBJECT_RAISES
CatalogBrains.GETOBJECT_RAISES = flag
def _restore_getObject_flag(self):
from Products.ZCatalog import CatalogBrains
CatalogBrains.GETOBJECT_RAISES = self._old_flag
def test_getObject_found(self):
# Check normal traversal
......@@ -747,7 +734,6 @@ class TestZCatalogGetObject(unittest.TestCase):
def test_getObject_missing_raises_NotFound(self):
# Check that if the object is missing we raise
from zExceptions import NotFound
self._init_getObject_flag(True)
root = self.root
catalog = root.catalog
root.ob = Folder('ob')
......@@ -760,7 +746,6 @@ class TestZCatalogGetObject(unittest.TestCase):
def test_getObject_restricted_raises_Unauthorized(self):
# Check that if the object's security does not allow traversal,
# None is returned
self._init_getObject_flag(True)
root = self.root
catalog = root.catalog
root.fold = Folder('fold')
......@@ -782,42 +767,6 @@ class TestZCatalogGetObject(unittest.TestCase):
self.failIf(ob is None)
self.assertEqual(ob.getId(), 'ob')
def test_getObject_missing_returns_None(self):
# Check that if the object is missing None is returned
self._init_getObject_flag(False)
root = self.root
catalog = root.catalog
root.ob = Folder('ob')
catalog.catalog_object(root.ob)
brain = catalog.searchResults({'id': 'ob'})[0]
del root.ob
self.assertEqual(brain.getObject(), None)
def test_getObject_restricted_returns_None(self):
# Check that if the object's security does not allow traversal,
# None is returned
self._init_getObject_flag(False)
root = self.root
catalog = root.catalog
root.fold = Folder('fold')
root.fold.ob = Folder('ob')
catalog.catalog_object(root.fold.ob)
brain = catalog.searchResults({'id': 'ob'})[0]
# allow all accesses
pickySecurityManager = PickySecurityManager()
setSecurityManager(pickySecurityManager)
self.assertEqual(brain.getObject().getId(), 'ob')
# disallow just 'ob' access
pickySecurityManager = PickySecurityManager(['ob'])
setSecurityManager(pickySecurityManager)
self.assertEqual(brain.getObject(), None)
# disallow just 'fold' access
pickySecurityManager = PickySecurityManager(['fold'])
setSecurityManager(pickySecurityManager)
ob = brain.getObject()
self.failIf(ob is None)
self.assertEqual(ob.getId(), 'ob')
# Now test _unrestrictedGetObject
def test_unrestrictedGetObject_found(self):
......@@ -855,7 +804,6 @@ class TestZCatalogGetObject(unittest.TestCase):
def test_unrestrictedGetObject_missing_raises_NotFound(self):
# Check that if the object is missing we raise
from zExceptions import NotFound
self._init_getObject_flag(True)
root = self.root
catalog = root.catalog
root.ob = Folder('ob')
......@@ -865,17 +813,6 @@ class TestZCatalogGetObject(unittest.TestCase):
self.assertRaises((NotFound, AttributeError, KeyError),
brain._unrestrictedGetObject)
def test_unrestrictedGetObject_missing_returns_None(self):
# Check that if the object is missing None is returned
self._init_getObject_flag(False)
root = self.root
catalog = root.catalog
root.ob = Folder('ob')
catalog.catalog_object(root.ob)
brain = catalog.searchResults({'id': 'ob'})[0]
del root.ob
self.assertEqual(brain._unrestrictedGetObject(), None)
def test_suite():
suite = unittest.TestSuite()
......
import os
import sys
import time
import logging
from re import compile
from socket import gethostbyaddr
......@@ -23,7 +21,7 @@ def _setenv(name, value):
def debug_mode(value):
value and _setenv('Z_DEBUG_MODE', '1')
import Globals # to set value
Globals.DevelopmentMode = boolean(value)
Globals.DevelopmentMode = bool(value)
return value
def locale(value):
......@@ -118,20 +116,6 @@ def enable_ms_public_header(value):
import webdav
webdav.enable_ms_public_header = value
def catalog_getObject_raises(value):
if value is not None:
import warnings
warnings.warn(
"'catalog-getObject-raises' option will be removed in Zope 2.10:\n",
DeprecationWarning)
from Products.ZCatalog import CatalogBrains
CatalogBrains.GETOBJECT_RAISES = bool(value)
return value
# server handlers
def root_handler(config):
......
......@@ -855,17 +855,6 @@
</description>
</key>
<key name="catalog-getObject-raises" datatype="boolean"
handler="catalog_getObject_raises">
<description>
If this directive is set to "on" (the default), ZCatalog brains objects
will raise NotFound exceptions from 'getObject' for unreachable objects,
and Unauthorized for disallowed objects. If the option is "off", they
will return None in such cases (which was the old behavior)
</description>
<metadefault>on</metadefault>
</key>
<multisection type="ZServer.server" name="*" attribute="servers"/>
<key name="port-base" datatype="integer" default="0">
......
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