[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/intid/ Merge old and
new IIntIdsSet interfaces:
Dominik Huber
dominik.huber at projekt01.ch
Thu Jun 9 04:07:15 EDT 2005
Log message for revision 30693:
Merge old and new IIntIdsSet interfaces:
def register(ob_or_key)
def unregister(ob_or_key)
Changed:
U Zope3/trunk/src/zope/app/intid/__init__.py
U Zope3/trunk/src/zope/app/intid/browser/__init__.py
U Zope3/trunk/src/zope/app/intid/interfaces.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-09 04:11:54 UTC (rev 30692)
+++ Zope3/trunk/src/zope/app/intid/__init__.py 2005-06-09 08:07:15 UTC (rev 30693)
@@ -104,9 +104,13 @@
return uid
self._v_nextid = None
- def register(self, key):
+ def register(self, ob_or_key):
# Note that we'll still need to keep this proxy removal.
- key = removeSecurityProxy(key)
+ key = removeSecurityProxy(ob_or_key)
+
+ if not IKeyReference.providedBy(key):
+ key = IKeyReference(key)
+
if key in self.ids:
return self.ids[key]
uid = self._generateId()
@@ -114,9 +118,13 @@
self.ids[key] = uid
return uid
- def unregister(self, key):
+ def unregister(self, ob_or_key):
# Note that we'll still need to keep this proxy removal.
- key = removeSecurityProxy(key)
+ key = removeSecurityProxy(ob_or_key)
+
+ if not IKeyReference.providedBy(key):
+ key = IKeyReference(key)
+
uid = self.ids[key]
del self.refs[uid]
del self.ids[key]
Modified: Zope3/trunk/src/zope/app/intid/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/browser/__init__.py 2005-06-09 04:11:54 UTC (rev 30692)
+++ Zope3/trunk/src/zope/app/intid/browser/__init__.py 2005-06-09 08:07:15 UTC (rev 30693)
@@ -17,7 +17,6 @@
"""
from zope.security.proxy import removeSecurityProxy
from zope.app import zapi
-from zope.app.keyreference.interfaces import IKeyReference
class IntIdsView(object):
@@ -27,8 +26,8 @@
def populate(self):
# TODO: I think this should be moved to the functional test.
- self.context.register(IKeyReference(zapi.traverse(self.context, "/")))
- self.context.register(IKeyReference(zapi.traverse(self.context, "/++etc++site")))
+ self.context.register(zapi.traverse(self.context, "/"))
+ self.context.register(zapi.traverse(self.context, "/++etc++site"))
self.request.response.redirect('index.html')
def items(self):
Modified: Zope3/trunk/src/zope/app/intid/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/interfaces.py 2005-06-09 04:11:54 UTC (rev 30692)
+++ Zope3/trunk/src/zope/app/intid/interfaces.py 2005-06-09 08:07:15 UTC (rev 30693)
@@ -33,17 +33,18 @@
class IIntIdsSet(Interface):
- def register(key):
- """Register a key reference and returns a unique id generated for it.
+ def register(ob_or_key):
+ """Register an object or a key reference and return a unique id.
If the object adapted to key reference is already registered, its
- id is returned anyway.
+ id is returned anyway otherwise, a unique id is generated for it
+ and returned.
"""
- def unregister(key):
- """Remove the key reference from the indexes.
+ def unregister(ob_or_key):
+ """Remove the object or the key reference from the indexes.
- ValueError is raised if the object adapted to key reference is not
+ KeyError is raised if the object adapted to key reference is not
registered previously.
"""
Modified: Zope3/trunk/src/zope/app/intid/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/tests.py 2005-06-09 04:11:54 UTC (rev 30692)
+++ Zope3/trunk/src/zope/app/intid/tests.py 2005-06-09 08:07:15 UTC (rev 30693)
@@ -65,7 +65,7 @@
verifyObject(IIntIds, IntIds())
- def test(self):
+ def test_empty(self):
from zope.app.intid import IntIds
from zope.app.keyreference.interfaces import IKeyReference
@@ -100,9 +100,53 @@
self.assertRaises(KeyError, u.getObject, uid)
self.assertRaises(KeyError, u.getId, obj)
+ def test_key(self):
+ from zope.app.intid import IntIds
+ from zope.app.keyreference.interfaces import IKeyReference
+
+ u = IntIds()
+ obj = P()
+
+ obj._p_jar = ConnectionStub()
+
+ key = IKeyReference(obj)
+
+ uid = u.register(key)
+ self.assert_(u.getObject(uid) is obj)
+ self.assert_(u.queryObject(uid) is obj)
+ self.assertEquals(u.getId(obj), uid)
+ self.assertEquals(u.queryId(obj), uid)
+
+ uid2 = u.register(key)
+ self.assertEquals(uid, uid2)
+
+ u.unregister(key)
+ self.assertRaises(KeyError, u.getObject, uid)
+ self.assertRaises(KeyError, u.getId, obj)
+
+ def test_ob(self):
+ from zope.app.intid import IntIds
+
+ u = IntIds()
+ obj = P()
+
+ obj._p_jar = ConnectionStub()
+
+ uid = u.register(obj)
+ self.assert_(u.getObject(uid) is obj)
+ self.assert_(u.queryObject(uid) is obj)
+ self.assertEquals(u.getId(obj), uid)
+ self.assertEquals(u.queryId(obj), uid)
+
+ uid2 = u.register(obj)
+ self.assertEquals(uid, uid2)
+
+ u.unregister(obj)
+ self.assertRaises(KeyError, u.getObject, uid)
+ self.assertRaises(KeyError, u.getId, obj)
+
def test_len_items(self):
from zope.app.intid import IntIds
- from zope.app.keyreference.interfaces import IKeyReference
from zope.app.keyreference.persistent import KeyReferenceToPersistent
u = IntIds()
obj = P()
@@ -112,9 +156,7 @@
self.assertEquals(u.items(), [])
self.assertEquals(list(u), [])
- key = IKeyReference(obj)
-
- uid = u.register(key)
+ uid = u.register(obj)
ref = KeyReferenceToPersistent(obj)
self.assertEquals(len(u), 1)
self.assertEquals(u.items(), [(uid, ref)])
@@ -123,9 +165,7 @@
obj2 = P()
obj2.__parent__ = obj
- key2 = IKeyReference(obj2)
-
- uid2 = u.register(key2)
+ uid2 = u.register(obj2)
ref2 = KeyReferenceToPersistent(obj2)
self.assertEquals(len(u), 2)
result = u.items()
@@ -139,8 +179,8 @@
expected.sort()
self.assertEquals(result, expected)
- u.unregister(key)
- u.unregister(key2)
+ u.unregister(obj)
+ u.unregister(obj2)
self.assertEquals(len(u), 0)
self.assertEquals(u.items(), [])
More information about the Zope3-Checkins
mailing list