[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/KeywordIndex - KeywordIndex.py:1.15
Sidnei da Silva
sidnei@x3ng.com.br
Tue, 17 Jun 2003 15:01:37 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/KeywordIndex
In directory cvs.zope.org:/tmp/cvs-serv17889/lib/python/Products/PluginIndexes/KeywordIndex
Modified Files:
KeywordIndex.py
Log Message:
- Made all PluginIndexes and ZCTextIndex use 'safe_callable',
which is aware of extension classes that fill 'tp_callable'
but don't define '__call__'.
- Made KeywordIndex be more robust about receiving a value that
is not a string or an iterable type.
=== Zope/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py 1.14 => 1.15 ===
--- Zope/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py:1.14 Fri Feb 28 10:51:33 2003
+++ Zope/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py Tue Jun 17 15:01:07 2003
@@ -11,6 +11,8 @@
#
##############################################################################
+from types import StringType, UnicodeType
+
from zLOG import LOG, ERROR
from BTrees.OOBTree import OOSet, difference
@@ -18,6 +20,7 @@
from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.UnIndex import UnIndex
+from Products.PluginIndexes.common import safe_callable
class KeywordIndex(UnIndex):
@@ -87,17 +90,21 @@
def _get_object_keywords(self, obj, attr):
newKeywords = getattr(obj, attr, ())
- if callable(newKeywords):
+ if safe_callable(newKeywords):
newKeywords = newKeywords()
- if hasattr(newKeywords,'capitalize'): # is it string-like ?
- newKeywords = [newKeywords]
+ if (isinstance(newKeywords, StringType)
+ or isinstance(newKeywords, UnicodeType)): #Python 2.1 compat isinstance
+ return (newKeywords,)
else:
- # Uniqueify keywords
unique = {}
- for k in newKeywords:
- unique[k] = None
- newKeywords = unique.keys()
- return newKeywords
+ try:
+ for k in newKeywords:
+ unique[k] = None
+ except TypeError:
+ # Not a sequence
+ return (newKeywords,)
+ else:
+ return unique.keys()
def unindex_objectKeywords(self, documentId, keywords):
""" carefully unindex the object with integer id 'documentId'"""
@@ -125,7 +132,7 @@
manage_addKeywordIndexForm = DTMLFile('dtml/addKeywordIndex', globals())
-def manage_addKeywordIndex(self, id, extra=None,
+def manage_addKeywordIndex(self, id, extra=None,
REQUEST=None, RESPONSE=None, URL3=None):
"""Add a keyword index"""
return self.manage_addIndex(id, 'KeywordIndex', extra=extra, \