syslocale: Normalize encoding based on the locale.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 15 Feb 2010 03:04:01 +0000 (19:04 -0800)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 15 Feb 2010 03:04:01 +0000 (19:04 -0800)
collate/syslocale.py

index b9f9b92..4a67044 100644 (file)
@@ -19,6 +19,8 @@ Avoid this backend if...
  - ICU or UCA support is available for the current locale.
  - You are sorting strings from alphabets outside the primary locale.
  - You need to support collating multiple locales at once.
  - ICU or UCA support is available for the current locale.
  - You are sorting strings from alphabets outside the primary locale.
  - You need to support collating multiple locales at once.
+ - You need the same results across multiple platforms.
 """
 
 import locale
 """
 
 import locale
@@ -31,6 +33,7 @@ class Collator(collate._abcollator.Collator):
     """C library locale-based collation."""
 
     def __init__(self, locale_code, encoding=None):
     """C library locale-based collation."""
 
     def __init__(self, locale_code, encoding=None):
+        locale_code, encoding = collate._locale.getpair(locale_code, encoding)
         try:
             locale.setlocale(locale.LC_COLLATE, locale_code)
         except locale.Error:
         try:
             locale.setlocale(locale.LC_COLLATE, locale_code)
         except locale.Error:
@@ -56,7 +59,6 @@ class Collator(collate._abcollator.Collator):
         If strs rather than unicodes are passed in, they are first
         decoded according to the 'encoding' attribute of the Collator.
         """
         If strs rather than unicodes are passed in, they are first
         decoded according to the 'encoding' attribute of the Collator.
         """
-
         if isinstance(a, str):
             a = a.decode(self.encoding, "replace")
         if isinstance(b, str):
         if isinstance(a, str):
             a = a.decode(self.encoding, "replace")
         if isinstance(b, str):