[Zope-Checkins] SVN: Zope/trunk/ replaced DocumentTemplate.sequence
with zope.sequencesort
Andreas Jung
andreas at andreas-jung.com
Wed Oct 3 03:09:49 EDT 2007
Log message for revision 80542:
replaced DocumentTemplate.sequence with zope.sequencesort
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/DocumentTemplate/sequence/SortEx.py
U Zope/trunk/lib/python/DocumentTemplate/sequence/tests/testSequence.py
_U Zope/trunk/lib/python/zope/
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2007-10-03 07:03:27 UTC (rev 80541)
+++ Zope/trunk/doc/CHANGES.txt 2007-10-03 07:09:49 UTC (rev 80542)
@@ -9,6 +9,8 @@
Restructuring
+ - Document.sequence: replaced by zope.sequencesort
+
- All Products folders as well as the zope and zope.app folders are
declared as setuptools namespace packages now. See
http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Modified: Zope/trunk/lib/python/DocumentTemplate/sequence/SortEx.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/sequence/SortEx.py 2007-10-03 07:03:27 UTC (rev 80541)
+++ Zope/trunk/lib/python/DocumentTemplate/sequence/SortEx.py 2007-10-03 07:09:49 UTC (rev 80542)
@@ -10,232 +10,5 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
-"""
-Advanced sort support by Oleg Broytmann <phd@@phd.pp.ru> 23 Apr 2001
-eg Sort(sequence, (("akey", "nocase"), ("anotherkey", "cmp", "desc")))
-$Id$
-"""
-
-from App.config import getConfiguration
-
-
-def sort(sequence, sort=(), _=None, mapping=0):
- """
- - sequence is a sequence of objects to be sorted
-
- - sort is a sequence of tuples (key,func,direction)
- that define the sort order:
-
- - key is the name of an attribute to sort the objects by
-
- - func is the name of a comparison function. This parameter is
- optional
-
- allowed values:
-
- - "cmp" -- the standard comparison function (default)
-
- - "nocase" -- case-insensitive comparison
-
- - "strcoll" or "locale" -- locale-aware string comparison
-
- - "strcoll_nocase" or "locale_nocase" -- locale-aware case-insensitive
- string comparison
-
- - "xxx" -- a user-defined comparison function
-
- - direction -- defines the sort direction for the key (optional).
- (allowed values: "asc" (default) , "desc")
- """
-
-
-
- need_sortfunc = 0
- if sort:
- for s in sort:
- if len(s) > 1: # extended sort if there is reference to...
- # ...comparison function or sort order, even if they are "cmp" and "asc"
- need_sortfunc = 1
- break
-
- sortfields = sort # multi sort = key1,key2
- multsort = len(sortfields) > 1 # flag: is multiple sort
-
- if need_sortfunc:
- # prepare the list of functions and sort order multipliers
- sf_list = make_sortfunctions(sortfields, _)
-
- # clean the mess a bit
- if multsort: # More than one sort key.
- sortfields = map(lambda x: x[0], sf_list)
- else:
- sort = sf_list[0][0]
-
- elif sort:
- if multsort: # More than one sort key.
- sortfields = map(lambda x: x[0], sort)
- else:
- sort = sort[0][0]
-
- isort=not sort
-
- s=[]
- for client in sequence:
- k = None
- if isinstance(client, tuple) and len(client)==2:
- if isort: k=client[0]
- v=client[1]
- else:
- if isort: k=client
- v=client
-
- if sort:
- if multsort: # More than one sort key.
- k = []
- for sk in sortfields:
- try:
- if mapping: akey = v[sk]
- else: akey = getattr(v, sk)
- except (AttributeError, KeyError):
- akey = None
- if not basic_type(type(akey)):
- try: akey = akey()
- except: pass
- k.append(akey)
- else: # One sort key.
- try:
- if mapping: k = v[sort]
- else: k = getattr(v, sort)
- except (AttributeError, KeyError): k = None
- if not basic_type(type(k)):
- try: k = k()
- except: pass
-
- s.append((k,client))
-
- if need_sortfunc:
- by = SortBy(multsort, sf_list)
- s.sort(by)
- else:
- s.sort()
-
- sequence=[]
- for k, client in s:
- sequence.append(client)
- return sequence
-
-
-SortEx = sort
-
-basic_type={type(''): 1, type(0): 1, type(0.0): 1, type(()): 1, type([]): 1,
- type(None) : 1 }.has_key
-
-def nocase(str1, str2):
- return cmp(str1.lower(), str2.lower())
-
-
-def getStrcoll():
- """ check the Zope configuration for the 'locale' configuration
- and return a suitable implementation.
- """
-
- 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():
- """ check the Zope configuration for the 'locale' configuration
- and return a suitable implementation.
- """
-
- if getConfiguration().locale:
- from locale import strcoll
-
- def strcoll_nocase(str1, str2):
- return strcoll(str1.lower(), str2.lower())
- return strcoll_nocase
-
- else:
- raise RuntimeError("strcoll_nocase() 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)"""
-
- sf_list = []
- for field in sortfields:
- f = list(field)
- l = len(f)
-
- if l == 1:
- f.append("cmp")
- f.append("asc")
- elif l == 2:
- f.append("asc")
- elif l == 3:
- pass
- else:
- raise SyntaxError, "sort option must contains no more than 2 fields"
-
- f_name = f[1]
-
- # predefined function?
- if f_name == "cmp":
- func = cmp # builtin
- elif f_name == "nocase":
- func = nocase
- elif f_name in ("locale", "strcoll"):
- func = getStrcoll()
- elif f_name in ("locale_nocase", "strcoll_nocase"):
- func = getStrcoll_nocase()
- else: # no - look it up in the namespace
- func = _.getitem(f_name, 0)
-
- sort_order = f[2].lower()
-
- if sort_order == "asc":
- multiplier = +1
- elif sort_order == "desc":
- multiplier = -1
- else:
- raise SyntaxError, "sort direction must be either ASC or DESC"
-
- sf_list.append((f[0], func, multiplier))
-
- return sf_list
-
-
-class SortBy:
- def __init__(self, multsort, sf_list):
- self.multsort = multsort
- self.sf_list = sf_list
-
- def __call__(self, o1, o2):
- multsort = self.multsort
- if multsort:
- o1 = o1[0] # if multsort - take the first element (key list)
- o2 = o2[0]
-
- sf_list = self.sf_list
- l = len(sf_list)
-
- # assert that o1 and o2 are tuples of apropriate length
- assert len(o1) == l + 1 - multsort, "%s, %d" % (o1, l + multsort)
- assert len(o2) == l + 1 - multsort, "%s, %d" % (o2, l + multsort)
-
- # now run through the list of functions in sf_list and
- # compare every object in o1 and o2
- for i in range(l):
- # if multsort - we already extracted the key list
- # if not multsort - i is 0, and the 0th element is the key
- c1, c2 = o1[i], o2[i]
- func, multiplier = sf_list[i][1:3]
- n = func(c1, c2)
- if n: return n*multiplier
-
- # all functions returned 0 - identical sequences
- return 0
+from zope.sequencesort.ssort import *
Modified: Zope/trunk/lib/python/DocumentTemplate/sequence/tests/testSequence.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/sequence/tests/testSequence.py 2007-10-03 07:03:27 UTC (rev 80541)
+++ Zope/trunk/lib/python/DocumentTemplate/sequence/tests/testSequence.py 2007-10-03 07:09:49 UTC (rev 80542)
@@ -13,7 +13,7 @@
import os, sys, unittest
-from DocumentTemplate.sequence.SortEx import *
+from DocumentTemplate.sequence import *
from DocumentTemplate.sequence.tests.ztestlib import *
from DocumentTemplate.sequence.tests.results import *
Property changes on: Zope/trunk/lib/python/zope
___________________________________________________________________
Name: svn:externals
- annotation -r 77445 svn://svn.zope.org/repos/main/zope.annotation/trunk/src/zope/annotation
cachedescriptors -r 77445 svn://svn.zope.org/repos/main/zope.cachedescriptors/trunk/src/zope/cachedescriptors
component -r 77445 svn://svn.zope.org/repos/main/zope.component/trunk/src/zope/component
configuration -r 77445 svn://svn.zope.org/repos/main/zope.configuration/trunk/src/zope/configuration
contentprovider -r 77445 svn://svn.zope.org/repos/main/zope.contentprovider/trunk/src/zope/contentprovider
contenttype -r 77445 svn://svn.zope.org/repos/main/zope.contenttype/trunk/src/zope/contenttype
copypastemove -r 77445 svn://svn.zope.org/repos/main/zope.copypastemove/trunk/src/zope/copypastemove
datetime -r 77445 svn://svn.zope.org/repos/main/zope.datetime/trunk/src/zope/datetime
decorator -r 77445 svn://svn.zope.org/repos/main/zope.decorator/trunk/src/zope/decorator
deferredimport -r 77445 svn://svn.zope.org/repos/main/zope.deferredimport/trunk/src/zope/deferredimport
deprecation -r 77445 svn://svn.zope.org/repos/main/zope.deprecation/trunk/src/zope/deprecation
documenttemplate -r 77445 svn://svn.zope.org/repos/main/zope.documenttemplate/trunk/src/zope/documenttemplate
dottedname -r 77445 svn://svn.zope.org/repos/main/zope.dottedname/trunk/src/zope/dottedname
dublincore -r 77445 svn://svn.zope.org/repos/main/zope.dublincore/trunk/src/zope/dublincore
event -r 77445 svn://svn.zope.org/repos/main/zope.event/trunk/src/zope/event
exceptions -r 77445 svn://svn.zope.org/repos/main/zope.exceptions/trunk/src/zope/exceptions
filerepresentation -r 77445 svn://svn.zope.org/repos/main/zope.filerepresentation/trunk/src/zope/filerepresentation
formlib -r 77445 svn://svn.zope.org/repos/main/zope.formlib/trunk/src/zope/formlib
hookable -r 77445 svn://svn.zope.org/repos/main/zope.hookable/trunk/src/zope/hookable
i18nmessageid -r 77445 svn://svn.zope.org/repos/main/zope.i18nmessageid/trunk/src/zope/i18nmessageid
i18n -r 77445 svn://svn.zope.org/repos/main/zope.i18n/trunk/src/zope/i18n
index -r 77445 svn://svn.zope.org/repos/main/zope.index/trunk/src/zope/index
interface -r 77445 svn://svn.zope.org/repos/main/zope.interface/trunk/src/zope/interface
lifecycleevent -r 77445 svn://svn.zope.org/repos/main/zope.lifecycleevent/trunk/src/zope/lifecycleevent
location -r 77445 svn://svn.zope.org/repos/main/zope.location/trunk/src/zope/location
modulealias -r 77445 svn://svn.zope.org/repos/main/zope.modulealias/trunk/src/zope/modulealias
pagetemplate -r 77445 svn://svn.zope.org/repos/main/zope.pagetemplate/trunk/src/zope/pagetemplate
proxy -r 77445 svn://svn.zope.org/repos/main/zope.proxy/trunk/src/zope/proxy
publisher -r 77445 svn://svn.zope.org/repos/main/zope.publisher/trunk/src/zope/publisher
rdb -r 77445 svn://svn.zope.org/repos/main/zope.rdb/trunk/src/zope/rdb
schema -r 77445 svn://svn.zope.org/repos/main/zope.schema/trunk/src/zope/schema
security -r 77445 svn://svn.zope.org/repos/main/zope.security/trunk/src/zope/security
sendmail -r 77445 svn://svn.zope.org/repos/main/zope.sendmail/trunk/src/zope/sendmail
server -r 77445 svn://svn.zope.org/repos/main/zope.server/trunk/src/zope/server
size -r 77445 svn://svn.zope.org/repos/main/zope.size/trunk/src/zope/size
structuredtext -r 77445 svn://svn.zope.org/repos/main/zope.structuredtext/trunk/src/zope/structuredtext
tales -r 77445 svn://svn.zope.org/repos/main/zope.tales/trunk/src/zope/tales
tal -r 77445 svn://svn.zope.org/repos/main/zope.tal/trunk/src/zope/tal
testbrowser -r 77445 svn://svn.zope.org/repos/main/zope.testbrowser/trunk/src/zope/testbrowser
testing -r 77445 svn://svn.zope.org/repos/main/zope.testing/trunk/src/zope/testing
thread -r 77445 svn://svn.zope.org/repos/main/zope.thread/trunk/src/zope/thread
traversing -r 77445 svn://svn.zope.org/repos/main/zope.traversing/trunk/src/zope/traversing
viewlet -r 77445 svn://svn.zope.org/repos/main/zope.viewlet/trunk/src/zope/viewlet
wfmc -r 77445 svn://svn.zope.org/repos/main/zope.wfmc/trunk/src/zope/wfmc
+ annotation -r 77445 svn://svn.zope.org/repos/main/zope.annotation/trunk/src/zope/annotation
cachedescriptors -r 77445 svn://svn.zope.org/repos/main/zope.cachedescriptors/trunk/src/zope/cachedescriptors
component -r 77445 svn://svn.zope.org/repos/main/zope.component/trunk/src/zope/component
configuration -r 77445 svn://svn.zope.org/repos/main/zope.configuration/trunk/src/zope/configuration
contentprovider -r 77445 svn://svn.zope.org/repos/main/zope.contentprovider/trunk/src/zope/contentprovider
contenttype -r 77445 svn://svn.zope.org/repos/main/zope.contenttype/trunk/src/zope/contenttype
copypastemove -r 77445 svn://svn.zope.org/repos/main/zope.copypastemove/trunk/src/zope/copypastemove
datetime -r 77445 svn://svn.zope.org/repos/main/zope.datetime/trunk/src/zope/datetime
decorator -r 77445 svn://svn.zope.org/repos/main/zope.decorator/trunk/src/zope/decorator
deferredimport -r 77445 svn://svn.zope.org/repos/main/zope.deferredimport/trunk/src/zope/deferredimport
deprecation -r 77445 svn://svn.zope.org/repos/main/zope.deprecation/trunk/src/zope/deprecation
documenttemplate -r 77445 svn://svn.zope.org/repos/main/zope.documenttemplate/trunk/src/zope/documenttemplate
dottedname -r 77445 svn://svn.zope.org/repos/main/zope.dottedname/trunk/src/zope/dottedname
dublincore -r 77445 svn://svn.zope.org/repos/main/zope.dublincore/trunk/src/zope/dublincore
event -r 77445 svn://svn.zope.org/repos/main/zope.event/trunk/src/zope/event
exceptions -r 77445 svn://svn.zope.org/repos/main/zope.exceptions/trunk/src/zope/exceptions
filerepresentation -r 77445 svn://svn.zope.org/repos/main/zope.filerepresentation/trunk/src/zope/filerepresentation
formlib -r 77445 svn://svn.zope.org/repos/main/zope.formlib/trunk/src/zope/formlib
hookable -r 77445 svn://svn.zope.org/repos/main/zope.hookable/trunk/src/zope/hookable
i18nmessageid -r 77445 svn://svn.zope.org/repos/main/zope.i18nmessageid/trunk/src/zope/i18nmessageid
i18n -r 77445 svn://svn.zope.org/repos/main/zope.i18n/trunk/src/zope/i18n
index -r 77445 svn://svn.zope.org/repos/main/zope.index/trunk/src/zope/index
interface -r 77445 svn://svn.zope.org/repos/main/zope.interface/trunk/src/zope/interface
lifecycleevent -r 77445 svn://svn.zope.org/repos/main/zope.lifecycleevent/trunk/src/zope/lifecycleevent
location -r 77445 svn://svn.zope.org/repos/main/zope.location/trunk/src/zope/location
modulealias -r 77445 svn://svn.zope.org/repos/main/zope.modulealias/trunk/src/zope/modulealias
pagetemplate -r 77445 svn://svn.zope.org/repos/main/zope.pagetemplate/trunk/src/zope/pagetemplate
proxy -r 77445 svn://svn.zope.org/repos/main/zope.proxy/trunk/src/zope/proxy
publisher -r 77445 svn://svn.zope.org/repos/main/zope.publisher/trunk/src/zope/publisher
rdb -r 77445 svn://svn.zope.org/repos/main/zope.rdb/trunk/src/zope/rdb
schema -r 77445 svn://svn.zope.org/repos/main/zope.schema/trunk/src/zope/schema
security -r 77445 svn://svn.zope.org/repos/main/zope.security/trunk/src/zope/security
sequencesort -r 77445 svn://svn.zope.org/repos/main/zope.sequencesort/trunk/src/zope/sequencesort
sendmail -r 77445 svn://svn.zope.org/repos/main/zope.sendmail/trunk/src/zope/sendmail
server -r 77445 svn://svn.zope.org/repos/main/zope.server/trunk/src/zope/server
size -r 77445 svn://svn.zope.org/repos/main/zope.size/trunk/src/zope/size
structuredtext -r 77445 svn://svn.zope.org/repos/main/zope.structuredtext/trunk/src/zope/structuredtext
tales -r 77445 svn://svn.zope.org/repos/main/zope.tales/trunk/src/zope/tales
tal -r 77445 svn://svn.zope.org/repos/main/zope.tal/trunk/src/zope/tal
testbrowser -r 77445 svn://svn.zope.org/repos/main/zope.testbrowser/trunk/src/zope/testbrowser
testing -r 77445 svn://svn.zope.org/repos/main/zope.testing/trunk/src/zope/testing
thread -r 77445 svn://svn.zope.org/repos/main/zope.thread/trunk/src/zope/thread
traversing -r 77445 svn://svn.zope.org/repos/main/zope.traversing/trunk/src/zope/traversing
viewlet -r 77445 svn://svn.zope.org/repos/main/zope.viewlet/trunk/src/zope/viewlet
wfmc -r 77445 svn://svn.zope.org/repos/main/zope.wfmc/trunk/src/zope/wfmc
More information about the Zope-Checkins
mailing list