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

Andreas Jung andreas at andreas-jung.com
Mon Jun 5 05:56:49 EDT 2006


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

Changed:
  U   Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
  U   Zope/branches/Zope-2_8-branch/lib/python/DocumentTemplate/sequence/SortEx.py

-=-
Modified: Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
===================================================================
--- Zope/branches/Zope-2_8-branch/doc/CHANGES.txt	2006-06-05 09:55:51 UTC (rev 68491)
+++ Zope/branches/Zope-2_8-branch/doc/CHANGES.txt	2006-06-05 09:56:48 UTC (rev 68492)
@@ -14,6 +14,14 @@
      to the rules for such a type laid out in the Python docs:
      http://docs.python.org/api/supporting-cycle-detection.html
 
+  after Zope 2.8.7 (unreleased)
+
+    Bugs fixed
+
+      - Collector #2116: sequence.sort() did not work properly
+        locale related comparison methods
+
+
   Zope 2.8.7 (2007/05/29)
 
     Features added:

Modified: Zope/branches/Zope-2_8-branch/lib/python/DocumentTemplate/sequence/SortEx.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/DocumentTemplate/sequence/SortEx.py	2006-06-05 09:55:51 UTC (rev 68491)
+++ Zope/branches/Zope-2_8-branch/lib/python/DocumentTemplate/sequence/SortEx.py	2006-06-05 09:56:48 UTC (rev 68492)
@@ -1,9 +1,9 @@
 ##############################################################################
 #
-# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@@ -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