Commit 8813ebc8 authored by Andreas Jung's avatar Andreas Jung

- Collector #2116: sequence.sort() did not work properly

        locale related comparison methods
parent 3a1222ab
...@@ -20,6 +20,9 @@ Zope Changes ...@@ -20,6 +20,9 @@ Zope Changes
- Updated Five to bugfix release 1.3.6. - Updated Five to bugfix release 1.3.6.
- Collector #2116: sequence.sort() did not work properly
locale related comparison methods
Zope 2.9.3 (2006/05/13) Zope 2.9.3 (2006/05/13)
Bugs fixed Bugs fixed
......
...@@ -17,7 +17,8 @@ eg Sort(sequence, (("akey", "nocase"), ("anotherkey", "cmp", "desc"))) ...@@ -17,7 +17,8 @@ eg Sort(sequence, (("akey", "nocase"), ("anotherkey", "cmp", "desc")))
$Id$ $Id$
""" """
from types import TupleType from App.config import getConfiguration
def sort(sequence, sort=(), _=None, mapping=0): def sort(sequence, sort=(), _=None, mapping=0):
""" """
...@@ -82,7 +83,7 @@ def sort(sequence, sort=(), _=None, mapping=0): ...@@ -82,7 +83,7 @@ def sort(sequence, sort=(), _=None, mapping=0):
s=[] s=[]
for client in sequence: for client in sequence:
k = None k = None
if type(client)==TupleType and len(client)==2: if isinstance(client, tuple) and len(client)==2:
if isort: k=client[0] if isort: k=client[0]
v=client[1] v=client[1]
else: else:
...@@ -133,12 +134,25 @@ basic_type={type(''): 1, type(0): 1, type(0.0): 1, type(()): 1, type([]): 1, ...@@ -133,12 +134,25 @@ basic_type={type(''): 1, type(0): 1, type(0.0): 1, type(()): 1, type([]): 1,
def nocase(str1, str2): def nocase(str1, str2):
return cmp(str1.lower(), str2.lower()) return cmp(str1.lower(), str2.lower())
import sys def getStrcoll():
if sys.modules.has_key("locale"): # only if locale is already imported
from locale import strcoll 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
def strcoll_nocase(str1, str2): else:
return strcoll(str1.lower(), str2.lower()) raise RuntimeError("strcoll() is only available for a proper 'locale' configuration in zope.conf")
def make_sortfunctions(sortfields, _): def make_sortfunctions(sortfields, _):
...@@ -168,9 +182,9 @@ def make_sortfunctions(sortfields, _): ...@@ -168,9 +182,9 @@ def make_sortfunctions(sortfields, _):
elif f_name == "nocase": elif f_name == "nocase":
func = nocase func = nocase
elif f_name in ("locale", "strcoll"): elif f_name in ("locale", "strcoll"):
func = strcoll func = getStrcoll()
elif f_name in ("locale_nocase", "strcoll_nocase"): elif f_name in ("locale_nocase", "strcoll_nocase"):
func = strcoll_nocase func = getStrcoll_nocase()
else: # no - look it up in the namespace else: # no - look it up in the namespace
func = _.getitem(f_name, 0) func = _.getitem(f_name, 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment