# HG changeset patch # User Nicolas Chauvat # Date 1366635262 -7200 # Node ID 80783605d27070f49feac3af744ea00ca66408f4 # Parent ada2f065f279a6f8c9f308c0d889622f2059f366 [toward-py3k] rewrite __cmp__ (closes #2715115) In Python 3k `__cmp__` special method is no longer supported. So we split it in `__lt__` and `__eq__`. details on Python3k behavior here: http://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons diff -r ada2f065f279 -r 80783605d270 entity.py --- a/entity.py Mon Apr 08 17:33:49 2013 +0200 +++ b/entity.py Mon Apr 22 14:54:22 2013 +0200 @@ -554,7 +554,10 @@ return '' % ( self.e_schema, self.eid, list(self.cw_attr_cache), id(self)) - def __cmp__(self, other): + def __lt__(self, other): + raise NotImplementedError('comparison not implemented for %s' % self.__class__) + + def __eq__(self, other): raise NotImplementedError('comparison not implemented for %s' % self.__class__) def _cw_update_attr_cache(self, attrcache): diff -r ada2f065f279 -r 80783605d270 schema.py --- a/schema.py Mon Apr 08 17:33:49 2013 +0200 +++ b/schema.py Mon Apr 22 14:54:22 2013 +0200 @@ -700,10 +700,15 @@ def __repr__(self): return '%s(%s)' % (self.__class__.__name__, self.full_rql) - def __cmp__(self, other): + def __lt__(self, other): if hasattr(other, 'expression'): - return cmp(other.expression, self.expression) - return -1 + return self.expression < other.expression + return True + + def __eq__(self, other): + if hasattr(other, 'expression'): + return self.expression == other.expression + return False def __deepcopy__(self, memo): return self.__class__(self.expression, self.mainvars) diff -r ada2f065f279 -r 80783605d270 server/edition.py --- a/server/edition.py Mon Apr 08 17:33:49 2013 +0200 +++ b/server/edition.py Mon Apr 22 14:54:22 2013 +0200 @@ -48,9 +48,12 @@ # dict|set keyable return hash(id(self)) - def __cmp__(self, other): + def __lt__(self, other): # we don't want comparison by value inherited from dict - return cmp(id(self), id(other)) + return id(self) < id(other) + + def __eq__(self, other): + return id(self) == id(other) def __setitem__(self, attr, value): assert attr != 'eid' diff -r ada2f065f279 -r 80783605d270 server/sources/__init__.py --- a/server/sources/__init__.py Mon Apr 08 17:33:49 2013 +0200 +++ b/server/sources/__init__.py Mon Apr 22 14:54:22 2013 +0200 @@ -140,17 +140,20 @@ return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__, self.eid, id(self)) - def __cmp__(self, other): + def __lt__(self, other): """simple comparison function to get predictable source order, with the system source at last """ if self.uri == other.uri: - return 0 + return False if self.uri == 'system': - return 1 + return False if other.uri == 'system': - return -1 - return cmp(self.uri, other.uri) + return True + return self.uri < other.uri + + def __eq__(self, other): + return self.uri == other.uri def backup(self, backupfile, confirm, format='native'): """method called to create a backup of source's data"""