Chris, this is also not a good solution. The suggested way to register Splitters would be to use the Product registry in the same way we register indexes there. Andreas ----- Original Message ----- From: "Chris Withers" <chrisw@nipltd.com> To: <zope-dev@zope.org>; <andreas@zope.com> Sent: Donnerstag, 16. August 2001 07:08 Subject: BugFix to enable other products to register Splitters
Hi,
Given the Collector is broken again, here's a mail report of a bug and fix:
The way splitters are currently implemented in PluginIndexes makes it practically impossible to register new types of splitter.
These patches provide a registerSplitter method for the PluginIndexes.TextIndex.Splitter module.
All the tests pass and the registerSplitter function is implicitly tested by this ;-)
cheers,
Chris & Harry
---------------------------------------------------------------------------- ----
--- e:\refcvs\zope\lib\python\products\pluginindexes\textindex\splitter\__init__ .py Fri Jun 01 14:47:34 2001 +++ E:\localcvs\AlexCons\Products\PluginIndexes\TextIndex\Splitter\__init__.py Thu Aug 16 11:43:39 2001 @@ -1,22 +1,32 @@ -import os,sys,exceptions +from ZopeSplitter import Splitter as ZopeSplitter +from ISO_8859_1_Splitter import Splitter as ISO_8859_1_Splitter
-availableSplitters = ( - ("ZopeSplitter" , "Zope Default Splitter"), - ("ISO_8859_1_Splitter" , "Werner Strobles ISO-8859-1 Splitter") -) +splitterNames = [] +splitterMapping = {}
-splitterNames = map(lambda x: x[0],availableSplitters) +def availableSplitters(): + list = [] + for name in splitterMapping.keys(): + list.append((name,splitterMapping[name][0])) + return tuple(list)
def getSplitter(name=None):
- if not name in splitterNames and name: - raise exceptions.RuntimeError, "No such splitter '%s'" % name - - if not name: name = splitterNames[0] - if not vars().has_key(name): - exec( "from %s import Splitter as %s" % (name,name)) - - return vars()[name] + if name is None: + name = splitterNames[0] + + try: + return splitterMapping[name][1] + except KeyError: + raise RuntimeError, "No such splitter '%s'" % name
+def registerSplitter(name,description,module,default=0): + global splitterNames + splitterMapping[name]=(description,module) + if default: + splitterNames.insert(0,name) + else: + splitterNames.append(name)
- +registerSplitter("ZopeSplitter", "Zope Default Splitter", ZopeSplitter) +registerSplitter("ISO_8859_1_Splitter","Werner Strobles ISO-8859-1 Splitter", ISO_8859_1_Splitter)
---------------------------------------------------------------------------- ----
--- e:\refcvs\zope\lib\python\products\pluginindexes\textindex\tests\testSplitte r.py Mon Aug 06 20:23:04 2001 +++ E:\localcvs\AlexCons\Products\PluginIndexes\TextIndex\tests\testSplitter.py Thu Aug 16 11:49:56 2001 @@ -119,9 +119,9 @@ def testAvailableSplitters( self ): "Test available splitters"
- assert len(Splitter.availableSplitters) >0 + assert len(Splitter.availableSplitters()) >0 assert len(Splitter.splitterNames)>0 - assert len(Splitter.availableSplitters)==len(Splitter.splitterNames) + assert len(Splitter.availableSplitters())==len(Splitter.splitterNames)
@@ -133,21 +133,11 @@ assert result==splitted, "%s: %s vs %s" % (sp_name,result,splitted)
- def testZopeSplitter(self): - """test ZopeSplitter (this test is known to fail because it does not support ISO stuff) """ - - for text,splitted in self.testdata: - self._test("ZopeSplitter",text,splitted) - def testISOSplitter(self): """test ISOSplitter"""
for text,splitted in self.testdata: self._test("ISO_8859_1_Splitter",text,splitted) - -# for loc in ["","ru_RU.KOI8-R"]: -# locale.setlocale(locale.LC_ALL , loc) -
def test_suite():