[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - BaseStopWords.py:1.1.2.7
Andreas Jung
andreas@digicool.com
Thu, 24 Jan 2002 19:21:28 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv26114
Modified Files:
Tag: ajung-textindexng-branch
BaseStopWords.py
Log Message:
added better error checking for stop words
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/BaseStopWords.py 1.1.2.6 => 1.1.2.7 ===
from types import DictType, StringType
from BTrees.OOBTree import OOBTree
-import os
+import os, re
_basedir = os.path.dirname(__file__)
+# illegal characters inside stop words
+illegal = re.compile('[ ]')
+
+class StopWordException(Exception): pass
+
+
class BaseStopWords:
""" base class for all StopWord objects """
@@ -46,7 +52,19 @@
def __len__(self): return len(self._words)
def __delitem__(self,k): del self._words[k]
- def __setitem__(self,k,v): self._words[k] = v
+ def __setitem__(self,k,v):
+
+ k = k.strip()
+
+ if k:
+ if illegal.search(k):
+ raise StopWordException, \
+ ' stop word contains illegal characters'
+
+ self._words[k] = v
+
+ else:
+ raise StopWordException,'stop word is empty'
def readStopWords(self, fname):
@@ -68,7 +86,8 @@
l = l.strip()
if l:
- d[ l ] = None
+ self[ l ] = None
return d
+