comparison babel/messages/catalog.py @ 250:194f927d8c5a

add a __cmp__ to Message that correctly sorts by id, taking into account plurals thanks zepolen
author pjenvey
date Mon, 13 Aug 2007 00:59:09 +0000
parents fc8b8c2bba53
children 2398fc97675b
comparison
equal deleted inserted replaced
249:d42e85b23272 250:194f927d8c5a
76 self.lineno = lineno 76 self.lineno = lineno
77 77
78 def __repr__(self): 78 def __repr__(self):
79 return '<%s %r (flags: %r)>' % (type(self).__name__, self.id, 79 return '<%s %r (flags: %r)>' % (type(self).__name__, self.id,
80 list(self.flags)) 80 list(self.flags))
81
82 def __cmp__(self, obj):
83 """Compare Messages, taking into account plural ids"""
84 if isinstance(obj, Message):
85 plural = self.pluralizable
86 obj_plural = obj.pluralizable
87 if plural and obj_plural:
88 return cmp(self.id[0], obj.id[0])
89 elif plural:
90 return cmp(self.id[0], obj.id)
91 elif obj_plural:
92 return cmp(self.id, obj.id[0])
93 return cmp(self.id, obj.id)
81 94
82 def fuzzy(self): 95 def fuzzy(self):
83 return 'fuzzy' in self.flags 96 return 'fuzzy' in self.flags
84 fuzzy = property(fuzzy, doc="""\ 97 fuzzy = property(fuzzy, doc="""\
85 Whether the translation is fuzzy. 98 Whether the translation is fuzzy.
Copyright (C) 2012-2017 Edgewall Software