diff babel/core.py @ 591:d1618dfaf114 trunk

change Locale comparison: Locales are now considered equal if all of their attributes (language, territory, script, variant) are equal. Before __eq__ used the simple string representation which hides errors in Locale instantiation (see #279 and #311 for more information).
author fschwarz
date Thu, 09 Aug 2012 07:36:36 +0000
parents 6f86d60dab56
children e6b1efa9a255
line wrap: on
line diff
--- a/babel/core.py
+++ b/babel/core.py
@@ -214,7 +214,13 @@
         return identifier
 
     def __eq__(self, other):
-        return str(self) == str(other)
+        for key in ('language', 'territory', 'script', 'variant'):
+            if not hasattr(other, key):
+                return False
+        return (self.language == other.language) and \
+            (self.territory == other.territory) and \
+            (self.script == other.script) and \
+            (self.variant == other.variant)
 
     def __ne__(self, other):
         return not self.__eq__(other)
Copyright (C) 2012-2017 Edgewall Software