Commit 665b04c9 authored by Florent Guillaume's avatar Florent Guillaume

Merged r40536 from 2.9 branch:

ObjectManager now has an hasObject method to test presence. This
brings it in line with BTreeFolder.
parent 1c42c045
......@@ -58,6 +58,9 @@ Zope Changes
Other
- ObjectManager now has an hasObject method to test presence. This
brings it in line with BTreeFolder.
- Made 'zopectl test' work for software homes which do not have
an "inplace" build (it used to require that test.py be in
$ZOPE_HOME/bin/; now it will use $ZOPE_HOME as a fallback).
......
......@@ -261,6 +261,20 @@ class ObjectManager(
raise AttributeError, id
return default
def hasObject(self, id):
"""Indicate whether the folder has an item by ID.
This doesn't try to be more intelligent than _getOb, and doesn't
consult _objects (for performance reasons). The common use case
is to check that an object does *not* exist.
"""
if (id in ('.', '..') or
id.startswith('_') or
id.startswith('aq_') or
id.endswith('__')):
return False
return getattr(aq_base(self), id, None) is not None
def _setObject(self, id, object, roles=None, user=None, set_owner=1):
v=self._checkId(id)
if v is not None: id=v
......
......@@ -303,6 +303,23 @@ class ObjectManagerTests( unittest.TestCase ):
om2._setObject(ob.getId(), ob)
self.assertRaises(DeleteFailed, om1._delObject, 'om2')
def test_hasObject(self):
om = self._makeOne()
self.failIf(om.hasObject('_properties'))
self.failIf(om.hasObject('_getOb'))
self.failIf(om.hasObject('__of__'))
self.failIf(om.hasObject('.'))
self.failIf(om.hasObject('..'))
self.failIf(om.hasObject('aq_base'))
om.zap__ = True
self.failIf(om.hasObject('zap__'))
self.failIf(om.hasObject('foo'))
si = SimpleItem('foo')
om._setObject('foo', si)
self.assert_(om.hasObject('foo'))
om._delObject('foo')
self.failIf(om.hasObject('foo'))
def test_setObject_checkId_ok(self):
om = self._makeOne()
si = SimpleItem('1')
......
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