From 0e77d25b167ffc09da0e4b7aa884f4e9909fc5f9 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 5 Sep 2006 23:31:31 -0800 Subject: [PATCH] add comparision opperators, this is a major bug fix.. previously two empty containers would compare equal causing the removal of the first one if a later one was really removed... The problems of inheriting from list.. :( It was previously masked because I would expand everything by default and now that I don't, more items are empty exposing the bug... [git-p4: depot-paths = "//depot/": change = 884] --- DIDLLite.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/DIDLLite.py b/DIDLLite.py index 865cf59..ea11b40 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -59,6 +59,29 @@ class Object(object): if kwargs.has_key('content'): self._content = kwargs['content'] + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __le__(self, other): + return self.__cmp__(other) <= 0 + + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return self.__cmp__(other) != 0 + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __ge__(self, other): + return self.__cmp__(other) >= 0 + + def __cmp__(self, other): + if not isinstance(other, self.__class__): + return 1 + return cmp(self.id, other.id) + def __repr__(self): cls = self.__class__ return '<%s.%s: id: %s, parent: %s, title: %s>' % \