Mercurial > babel > mirror
comparison babel/messages/catalog.py @ 565:b0e80df660ab trunk
refactor Catalog.__cmp__ method
author | fschwarz |
---|---|
date | Mon, 26 Sep 2011 08:53:28 +0000 |
parents | 1ef087352e01 |
children | 99d51589c822 |
comparison
equal
deleted
inserted
replaced
564:1ef087352e01 | 565:b0e80df660ab |
---|---|
87 return '<%s %r (flags: %r)>' % (type(self).__name__, self.id, | 87 return '<%s %r (flags: %r)>' % (type(self).__name__, self.id, |
88 list(self.flags)) | 88 list(self.flags)) |
89 | 89 |
90 def __cmp__(self, obj): | 90 def __cmp__(self, obj): |
91 """Compare Messages, taking into account plural ids""" | 91 """Compare Messages, taking into account plural ids""" |
92 if isinstance(obj, Message): | 92 def values_to_compare(): |
93 plural = self.pluralizable | 93 if isinstance(obj, Message): |
94 obj_plural = obj.pluralizable | 94 plural = self.pluralizable |
95 if plural and obj_plural: | 95 obj_plural = obj.pluralizable |
96 return cmp(self.id[0], obj.id[0]) | 96 if plural and obj_plural: |
97 elif plural: | 97 return self.id[0], obj.id[0] |
98 return cmp(self.id[0], obj.id) | 98 elif plural: |
99 elif obj_plural: | 99 return self.id[0], obj.id |
100 return cmp(self.id, obj.id[0]) | 100 elif obj_plural: |
101 return cmp(self.id, obj.id) | 101 return self.id, obj.id[0] |
102 return self.id, obj.id | |
103 this, other = values_to_compare() | |
104 return cmp(this, other) | |
102 | 105 |
103 def __gt__(self, other): | 106 def __gt__(self, other): |
104 return self.__cmp__(other) > 0 | 107 return self.__cmp__(other) > 0 |
105 | 108 |
106 def __lt__(self, other): | 109 def __lt__(self, other): |