return '<%s %r (flags: %r)>' % (type(self).__name__, self.id,
list(self.flags))
- def __cmp__(self, obj):
+ def __cmp__(self, other):
"""Compare Messages, taking into account plural ids"""
- def values_to_compare():
- if isinstance(obj, Message):
- plural = self.pluralizable
- obj_plural = obj.pluralizable
- if plural and obj_plural:
- return self.id[0], obj.id[0]
- elif plural:
- return self.id[0], obj.id
- elif obj_plural:
- return self.id, obj.id[0]
- return self.id, obj.id
- this, other = values_to_compare()
- return cmp(this, other)
+ def values_to_compare(obj):
+ if isinstance(obj, Message) and obj.pluralizable:
+ return obj.id[0]
+ return obj.id
+ return cmp(values_to_compare(self), values_to_compare(other))
def __gt__(self, other):
return self.__cmp__(other) > 0