[Zope-Checkins] SVN: Zope/trunk/ Merged r40536 from 2.9 branch:
Florent Guillaume
fg at nuxeo.com
Mon Dec 5 10:12:53 EST 2005
Log message for revision 40537:
Merged r40536 from 2.9 branch:
ObjectManager now has an hasObject method to test presence. This
brings it in line with BTreeFolder.
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/OFS/ObjectManager.py
U Zope/trunk/lib/python/OFS/interfaces.py
U Zope/trunk/lib/python/OFS/tests/testObjectManager.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2005-12-05 15:07:46 UTC (rev 40536)
+++ Zope/trunk/doc/CHANGES.txt 2005-12-05 15:12:52 UTC (rev 40537)
@@ -26,6 +26,9 @@
Features added
+ - ObjectManager now has an hasObject method to test presence. This
+ brings it in line with BTreeFolder.
+
- Using FastCGI is offically deprecated.
- Improved logging of ConflictErrors. All conflict errors are
Modified: Zope/trunk/lib/python/OFS/ObjectManager.py
===================================================================
--- Zope/trunk/lib/python/OFS/ObjectManager.py 2005-12-05 15:07:46 UTC (rev 40536)
+++ Zope/trunk/lib/python/OFS/ObjectManager.py 2005-12-05 15:12:52 UTC (rev 40537)
@@ -272,6 +272,20 @@
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,
suppress_events=False):
"""Set an object into this container.
Modified: Zope/trunk/lib/python/OFS/interfaces.py
===================================================================
--- Zope/trunk/lib/python/OFS/interfaces.py 2005-12-05 15:07:46 UTC (rev 40536)
+++ Zope/trunk/lib/python/OFS/interfaces.py 2005-12-05 15:12:52 UTC (rev 40537)
@@ -531,6 +531,10 @@
"""
"""
+ def hasObject(id):
+ """Indicate whether the folder has an item by ID.
+ """
+
def objectIds(spec=None):
"""List the IDs of the subobjects of the current object.
Modified: Zope/trunk/lib/python/OFS/tests/testObjectManager.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testObjectManager.py 2005-12-05 15:07:46 UTC (rev 40536)
+++ Zope/trunk/lib/python/OFS/tests/testObjectManager.py 2005-12-05 15:12:52 UTC (rev 40537)
@@ -328,6 +328,22 @@
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()
More information about the Zope-Checkins
mailing list