[kupfer] utils: doctest for locale_sort
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] utils: doctest for locale_sort
- Date: Thu, 20 Aug 2009 22:10:18 +0000 (UTC)
commit 7063a237e230029f10e3d8956ab1c646aa748cec
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed Aug 19 02:18:50 2009 +0200
utils: doctest for locale_sort
kupfer/utils.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 5f6ddc1..0e52f0d 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -46,7 +46,18 @@ def get_dirlist(folder, depth=0, include=None, exclude=None):
def locale_sort(seq, key=unicode):
"""Return @seq of objects with @key function as a list sorted
- in locale lexical order"""
+ in locale lexical order
+
+ >>> locale.setlocale(locale.LC_ALL, "C")
+ 'C'
+ >>> locale_sort("abcABC")
+ ['A', 'B', 'C', 'a', 'b', 'c']
+
+ >>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
+ 'en_US.UTF-8'
+ >>> locale_sort("abcABC")
+ ['a', 'A', 'b', 'B', 'c', 'C']
+ """
locale_cmp = lambda s, o: locale.strcoll(key(s), key(o))
seq = seq if isinstance(seq, list) else list(seq)
seq.sort(cmp=locale_cmp)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]