[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/uniqueid/ Added
__hash__ to IReference and updated ReferenceToPersistent to
implement it.
Gintautas Miliauskas
gintas at pov.lt
Fri Jun 11 05:50:20 EDT 2004
Log message for revision 25341:
Added __hash__ to IReference and updated ReferenceToPersistent to implement it.
-=-
Modified: Zope3/trunk/src/zope/app/uniqueid/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/__init__.py 2004-06-10 18:36:08 UTC (rev 25340)
+++ Zope3/trunk/src/zope/app/uniqueid/__init__.py 2004-06-11 09:50:19 UTC (rev 25341)
@@ -96,11 +96,14 @@
def __call__(self):
return self.object
+ def __hash__(self):
+ return self.object._p_oid
+
def __cmp__(self, other):
if not isinstance(other, ReferenceToPersistent):
raise TypeError("Cannot compare ReferenceToPersistent with %r" %
(other,))
- return cmp(self.object._p_oid, other.object._p_oid)
+ return cmp(self.__hash__(), other.__hash__())
def connectionOfPersistent(ob):
Modified: Zope3/trunk/src/zope/app/uniqueid/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/interfaces.py 2004-06-10 18:36:08 UTC (rev 25340)
+++ Zope3/trunk/src/zope/app/uniqueid/interfaces.py 2004-06-11 09:50:19 UTC (rev 25341)
@@ -7,16 +7,18 @@
class IReference(Interface):
- """A reference to an object (like a weak ref)
+ """A reference to an object (similar to a weak reference).
- Have to be orderable. The references are only equal if they
- reference the same object.
+ The references are compared by their hashes.
"""
def __call__():
- """Get the object this reference is linking to"""
+ """Get the object this reference is linking to."""
+ def __hash__():
+ """Get a unique identifier of the referenced object."""
+
class IUniqueIdUtilityQuery(Interface):
def getObject(uid):
More information about the Zope3-Checkins
mailing list