[Checkins] SVN: zc.intid/trunk/src/zc/intid/ Make the utility's `getId` method consistent with that of zope.intid in regard
Patrick Strawderman
patrick at zope.com
Mon Jun 27 10:48:34 EDT 2011
Log message for revision 121988:
Make the utility's `getId` method consistent with that of zope.intid in regard
to handling proxies.
Changed:
U zc.intid/trunk/src/zc/intid/tests.py
U zc.intid/trunk/src/zc/intid/utility.py
-=-
Modified: zc.intid/trunk/src/zc/intid/tests.py
===================================================================
--- zc.intid/trunk/src/zc/intid/tests.py 2011-06-27 14:42:51 UTC (rev 121987)
+++ zc.intid/trunk/src/zc/intid/tests.py 2011-06-27 14:48:34 UTC (rev 121988)
@@ -22,6 +22,8 @@
import zc.intid.utility
import zope.event
import zope.interface.verify
+import zope.security.checker
+import zope.security.proxy
class P(object):
@@ -45,6 +47,40 @@
zope.interface.verify.verifyObject(zc.intid.IIntIds, u)
zope.interface.verify.verifyObject(zc.intid.IIntIdsSubclass, u)
+ def test_proxies(self):
+ # This test ensures that the `getId` method exhibits the same
+ # behavior when passed a proxy as it does in zope.intid.
+ u = self.createIntIds()
+ obj = P()
+ iid = u.register(obj)
+ proxied = zope.security.proxy.Proxy(obj,
+ zope.security.checker.CheckerPublic)
+ # Passing `getId` a proxied object yields the correct id
+ self.assertEquals(u.getId(proxied), iid)
+ # `getId` raises a KeyError with the proxied object if it isn't
+ # in its mapping.
+ obj.iid = None
+ try:
+ u.getId(proxied)
+ except KeyError, exc:
+ pass
+ self.assert_(exc.args[0] is proxied)
+ obj.iid = -1
+ try:
+ u.getId(proxied)
+ except KeyError, exc:
+ pass
+ self.assert_(exc.args[0] is proxied)
+ obj = P()
+ obj.iid = iid
+ proxied = zope.security.proxy.Proxy(obj,
+ zope.security.checker.CheckerPublic)
+ try:
+ u.getId(proxied)
+ except KeyError, exc:
+ pass
+ self.assert_(exc.args[0] is proxied)
+
def test_non_keyreferences(self):
#
# This test, copied from zope.intid, was used in that context to
Modified: zc.intid/trunk/src/zc/intid/utility.py
===================================================================
--- zc.intid/trunk/src/zc/intid/utility.py 2011-06-27 14:42:51 UTC (rev 121987)
+++ zc.intid/trunk/src/zc/intid/utility.py 2011-06-27 14:48:34 UTC (rev 121988)
@@ -74,10 +74,11 @@
return default
def getId(self, ob):
- uid = getattr(unwrap(ob), self.attribute, None)
+ unwrapped = unwrap(ob)
+ uid = getattr(unwrapped, self.attribute, None)
if uid is None:
raise KeyError(ob)
- if self.refs[uid] is not ob:
+ if uid not in self.refs or self.refs[uid] is not unwrapped:
# not an id that matches
raise KeyError(ob)
return uid
More information about the checkins
mailing list