[Zope-Checkins] SVN: Zope/branches/2.10/ - Collector #2116: sequence.sort() did not work properly

Andreas Jung andreas at andreas-jung.com
Mon Jun 5 05:57:29 EDT 2006


Log message for revision 68493:
  
        - Collector #2116: sequence.sort() did not work properly
          locale related comparison methods
  

Changed:
  U   Zope/branches/2.10/doc/CHANGES.txt
  U   Zope/branches/2.10/lib/python/DocumentTemplate/sequence/SortEx.py

-=-
Modified: Zope/branches/2.10/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.10/doc/CHANGES.txt	2006-06-05 09:56:48 UTC (rev 68492)
+++ Zope/branches/2.10/doc/CHANGES.txt	2006-06-05 09:57:28 UTC (rev 68493)
@@ -23,6 +23,10 @@
 
       - Acquisition wrappers now correctly proxy __contains__.
 
+      - Collector #2116: sequence.sort() did not work properly
+        locale related comparison methods
+
+
   Zope 2.10.0 beta 1 (2006/05/30)
 
     Restructuring

Modified: Zope/branches/2.10/lib/python/DocumentTemplate/sequence/SortEx.py
===================================================================
--- Zope/branches/2.10/lib/python/DocumentTemplate/sequence/SortEx.py	2006-06-05 09:56:48 UTC (rev 68492)
+++ Zope/branches/2.10/lib/python/DocumentTemplate/sequence/SortEx.py	2006-06-05 09:57:28 UTC (rev 68493)
@@ -17,8 +17,9 @@
 $Id$
 """
 
-from types import TupleType
+from App.config import getConfiguration
 
+
 def sort(sequence, sort=(), _=None, mapping=0):
     """
     - sequence is a sequence of objects to be sorted
@@ -82,7 +83,7 @@
     s=[]
     for client in sequence:
         k = None
-        if type(client)==TupleType and len(client)==2:
+        if isinstance(client, tuple) and len(client)==2:
             if isort: k=client[0]
             v=client[1]
         else:
@@ -133,14 +134,27 @@
 def nocase(str1, str2):
     return cmp(str1.lower(), str2.lower())
 
-import sys
-if sys.modules.has_key("locale"): # only if locale is already imported
-    from locale import strcoll
+def getStrcoll():
 
-    def strcoll_nocase(str1, str2):
-        return strcoll(str1.lower(), str2.lower())
+    if getConfiguration().locale:
+        from locale import strcoll
+        return strcoll
+    else:
+        raise RuntimeError("strcoll() is only available for a proper 'locale' configuration in zope.conf")
 
+def getStrcoll_nocase():
 
+    if getConfiguration().locale:
+        from locale import strcoll
+        return strcoll
+        def strcoll_nocase(str1, str2):
+            return strcoll(str1.lower(), str2.lower())
+        return strcoll_nocase
+
+    else:
+        raise RuntimeError("strcoll() is only available for a proper 'locale' configuration in zope.conf")
+
+
 def make_sortfunctions(sortfields, _):
     """Accepts a list of sort fields; splits every field, finds comparison
     function. Returns a list of 3-tuples (field, cmp_function, asc_multplier)"""
@@ -168,9 +182,9 @@
         elif f_name == "nocase":
             func = nocase
         elif f_name in ("locale", "strcoll"):
-            func = strcoll
+            func = getStrcoll()
         elif f_name in ("locale_nocase", "strcoll_nocase"):
-            func = strcoll_nocase
+            func = getStrcoll_nocase()
         else: # no - look it up in the namespace
             func = _.getitem(f_name, 0)
 



More information about the Zope-Checkins mailing list