Commit 0b19689f authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[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
parent ada2f065f279
......@@ -554,7 +554,10 @@ class Entity(AppObject):
return '<Entity %s %s %s at %s>' % (
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):
......
......@@ -700,10 +700,15 @@ class RQLExpression(object):
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)
......
......@@ -48,9 +48,12 @@ class EditedEntity(dict):
# 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'
......
......@@ -140,17 +140,20 @@ class AbstractSource(object):
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"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment