[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/intid/ Changed to
treat handling of objects that are not adaptable to
Jim Fulton
jim at zope.com
Tue Jun 14 10:24:06 EDT 2005
Log message for revision 30794:
Changed to treat handling of objects that are not adaptable to
IKeyReference. Query methods simply treat objects that are not
adaptable as not present. The unregister method ignores such objects.
This makes subscribers simpler to implement.
Changed:
U Zope3/trunk/src/zope/app/intid/__init__.py
U Zope3/trunk/src/zope/app/intid/tests.py
-=-
Modified: Zope3/trunk/src/zope/app/intid/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/__init__.py 2005-06-14 11:47:39 UTC (rev 30793)
+++ Zope3/trunk/src/zope/app/intid/__init__.py 2005-06-14 14:24:05 UTC (rev 30794)
@@ -74,7 +74,7 @@
def getId(self, ob):
try:
key = IKeyReference(ob)
- except NotYet:
+ except (NotYet, TypeError):
raise KeyError(ob)
try:
@@ -119,7 +119,9 @@
def unregister(self, ob):
# Note that we'll still need to keep this proxy removal.
ob = removeSecurityProxy(ob)
- key = IKeyReference(ob)
+ key = IKeyReference(ob, None)
+ if key is None:
+ return
uid = self.ids[key]
del self.refs[uid]
Modified: Zope3/trunk/src/zope/app/intid/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/tests.py 2005-06-14 11:47:39 UTC (rev 30793)
+++ Zope3/trunk/src/zope/app/intid/tests.py 2005-06-14 14:24:05 UTC (rev 30794)
@@ -29,7 +29,13 @@
from zope.app.location.interfaces import ILocation
from zope.app.component.hooks import setSite
+from zope.app.intid.interfaces import IIntIds
+from zope.app.intid import IntIds
+from zope.app.keyreference.persistent import KeyReferenceToPersistent
+from zope.app.keyreference.persistent import connectionOfPersistent
+from zope.app.keyreference.interfaces import IKeyReference
+
class P(Persistent):
implements(ILocation)
@@ -45,9 +51,6 @@
class ReferenceSetupMixin(object):
"""Registers adapters ILocation->IConnection and IPersistent->IReference"""
def setUp(self):
- from zope.app.keyreference.persistent import connectionOfPersistent
- from zope.app.keyreference.persistent import KeyReferenceToPersistent
- from zope.app.keyreference.interfaces import IKeyReference
self.root = setup.placefulSetUp(site=True)
ztapi.provideAdapter(IPersistent, IConnection, connectionOfPersistent)
ztapi.provideAdapter(IPersistent, IKeyReference,
@@ -60,14 +63,17 @@
class TestIntIds(ReferenceSetupMixin, unittest.TestCase):
def test_interface(self):
- from zope.app.intid.interfaces import IIntIds
- from zope.app.intid import IntIds
-
verifyObject(IIntIds, IntIds())
- def test(self):
- from zope.app.intid import IntIds
+ def test_non_keyreferences(self):
+ u = IntIds()
+ obj = object()
+ self.assert_(u.queryId(obj) is None)
+ self.assert_(u.unregister(obj) is None)
+ self.assertRaises(KeyError, u.getId, obj)
+
+ def test(self):
u = IntIds()
obj = P()
@@ -75,12 +81,10 @@
self.assertRaises(KeyError, u.getId, obj)
self.assertRaises(KeyError, u.getId, P())
- self.assertRaises(TypeError, u.getId, object())
self.assert_(u.queryId(obj) is None)
self.assert_(u.queryId(obj, 42) is 42)
self.assert_(u.queryId(P(), 42) is 42)
- self.assertRaises(TypeError, u.queryId, object())
self.assert_(u.queryObject(42) is None)
self.assert_(u.queryObject(42, obj) is obj)
@@ -98,8 +102,6 @@
self.assertRaises(KeyError, u.getId, obj)
def test_len_items(self):
- from zope.app.intid import IntIds
- from zope.app.keyreference.persistent import KeyReferenceToPersistent
u = IntIds()
obj = P()
obj._p_jar = ConnectionStub()
@@ -137,8 +139,6 @@
self.assertEquals(u.items(), [])
def test_getenrateId(self):
- from zope.app.intid import IntIds
-
u = IntIds()
self.assertEquals(u._v_nextid, None)
id1 = u._generateId()
@@ -155,8 +155,6 @@
class TestSubscribers(ReferenceSetupMixin, unittest.TestCase):
def setUp(self):
- from zope.app.intid.interfaces import IIntIds
- from zope.app.intid import IntIds
from zope.app.folder import Folder, rootFolder
ReferenceSetupMixin.setUp(self)
More information about the Zope3-Checkins
mailing list