[Zope3-checkins] SVN: Zope3/trunk/ Fixed bug 185: Keyword Index
isinstance check fails on security proxy
Christian Theune
ct at gocept.com
Fri Dec 2 17:03:07 EST 2005
Log message for revision 40508:
Fixed bug 185: Keyword Index isinstance check fails on security proxy
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/index/keyword/index.py
U Zope3/trunk/src/zope/index/keyword/interfaces.py
U Zope3/trunk/src/zope/index/keyword/tests.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-12-02 20:41:16 UTC (rev 40507)
+++ Zope3/trunk/doc/CHANGES.txt 2005-12-02 22:03:05 UTC (rev 40508)
@@ -162,6 +162,8 @@
Bug Fixes
+ - Fixed bug 185: Keyword Index isinstance check fails on security proxy
+
- Improved bug 199: ZPTPage macro expansion
Changed label text to match the corresponding label in Zope 2 and
activated the name spaces for macro expansion in read().
Modified: Zope3/trunk/src/zope/index/keyword/index.py
===================================================================
--- Zope3/trunk/src/zope/index/keyword/index.py 2005-12-02 20:41:16 UTC (rev 40507)
+++ Zope3/trunk/src/zope/index/keyword/index.py 2005-12-02 22:03:05 UTC (rev 40508)
@@ -22,7 +22,7 @@
from BTrees.IIBTree import IISet, union, intersection
from BTrees.Length import Length
-from types import ListType, TupleType, StringTypes
+from types import StringTypes
from zope.index.interfaces import IInjection, IStatistics
from zope.index.keyword.interfaces import IKeywordQuerying
from zope.interface import implements
@@ -60,11 +60,12 @@
return bool(self._rev_index.has_key(docid))
def index_doc(self, docid, seq):
-
- if not isinstance(seq, (TupleType, ListType)):
+ if isinstance(seq, StringTypes):
raise TypeError('seq argument must be a list/tuple of strings')
- if not seq: return
+ if not seq:
+ return
+
if self.normalize:
seq = [w.lower() for w in seq]
@@ -90,18 +91,20 @@
self._insert_reverse(docid, new_kw)
def unindex_doc(self, docid):
-
idx = self._fwd_index
try:
for word in self._rev_index[docid]:
idx[word].remove(docid)
- if not idx[word]: del idx[word]
- except KeyError: return
+ if not idx[word]:
+ del idx[word]
+ except KeyError:
+ return
try:
del self._rev_index[docid]
- except KeyError: pass
+ except KeyError:
+ pass
self._num_docs.change(-1)
@@ -118,15 +121,14 @@
def _insert_reverse(self, docid, words):
""" add words to forward index """
- if words:
+ if words:
self._rev_index[docid] = words
def search(self, query, operator='and'):
+ """Execute a search given by 'query'."""
+ if isinstance(query, StringTypes):
+ query = [query]
- if isinstance(query, StringTypes): query = [query]
- if not isinstance(query, (TupleType, ListType)):
- raise TypeError('query argument must be a list/tuple of strings')
-
if self.normalize:
query = [w.lower() for w in query]
@@ -137,10 +139,11 @@
docids = self._fwd_index.get(word, IISet())
rs = f(rs, docids)
- if rs: return rs
- else: return IISet()
+ if rs:
+ return rs
+ else:
+ return IISet()
-
class CaseSensitiveKeywordIndex(KeywordIndex):
""" A case-sensitive keyword index """
normalize = False
Modified: Zope3/trunk/src/zope/index/keyword/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/index/keyword/interfaces.py 2005-12-02 20:41:16 UTC (rev 40507)
+++ Zope3/trunk/src/zope/index/keyword/interfaces.py 2005-12-02 22:03:05 UTC (rev 40508)
@@ -21,9 +21,11 @@
"""Query over a set of keywords, seperated by white space."""
def search(query, operator='and'):
- """Execute a search given by 'query' as a list/tuple of
- (unicode) strings against the index. 'operator' can be either
- 'and' or 'or' to search for all keywords or any keyword.
+ """Execute a search given by 'query'.
+
+ 'query' can be a (unicode) string or an iterable of (unicode) strings.
+ 'operator' can be either 'and' or 'or' to search for documents
+ containing all keywords or any keyword.
- Return an IISet of docids
+ Return an IISet of docids
"""
Modified: Zope3/trunk/src/zope/index/keyword/tests.py
===================================================================
--- Zope3/trunk/src/zope/index/keyword/tests.py 2005-12-02 20:41:16 UTC (rev 40507)
+++ Zope3/trunk/src/zope/index/keyword/tests.py 2005-12-02 22:03:05 UTC (rev 40508)
@@ -50,14 +50,12 @@
def _search_or(self, query, expected):
return self._search(query, expected, 'or')
-
def test_interface(self):
verifyClass(IInjection, KeywordIndex)
verifyClass(IStatistics, KeywordIndex)
verifyClass(IKeywordQuerying, KeywordIndex)
def test_empty_index(self):
-
self.assertEqual(self.index.documentCount(), 0)
self.assertEqual(self.index.wordCount(), 0)
self._populate_index()
@@ -68,7 +66,6 @@
self.assertEqual(self.index.wordCount(), 0)
def test_unindex(self):
-
self._populate_index()
self.assertEqual(self.index.documentCount(), 4)
self.index.unindex_doc(1)
@@ -77,9 +74,7 @@
self.index.unindex_doc(-99999) # no exception should be raised
self.assertEqual(self.index.documentCount(), 2)
-
def test_reindex(self):
-
self._populate_index()
self.assertEqual(self.index.documentCount(), 4)
self.index.unindex_doc(1)
@@ -90,14 +85,12 @@
self._search('quick', IISet())
self._search('foo', IISet())
self._search('bar', IISet([1]))
- self._search('doom', IISet())
- self._search('blabla', IISet([1]))
+ self._search(['doom'], IISet())
+ self._search(['blabla'], IISet([1]))
self._search_and(('bar', 'blabla'), IISet([1]))
- self._search('cmf', IISet([5]))
+ self._search(['cmf'], IISet([5]))
-
def test_hasdoc(self):
-
self._populate_index()
self.assertEqual(self.index.has_doc(1), 1)
self.assertEqual(self.index.has_doc(2), 1)
@@ -106,18 +99,15 @@
self.assertEqual(self.index.has_doc(5), 1)
self.assertEqual(self.index.has_doc(6), 0)
-
def test_simplesearch(self):
-
self._populate_index()
- self._search('', IISet())
- self._search('cmf', IISet([1, 5]))
- self._search('zope', IISet([1, 3]))
- self._search('zope3', IISet([1]))
- self._search('foo', IISet())
+ self._search([''], IISet())
+ self._search(['cmf'], IISet([1, 5]))
+ self._search(['zope'], IISet([1, 3]))
+ self._search(['zope3'], IISet([1]))
+ self._search(['foo'], IISet())
def test_search_and(self):
-
self._populate_index()
self._search_and(('cmf', 'zope3'), IISet([1]))
self._search_and(('cmf', 'zope'), IISet([1]))
@@ -125,13 +115,15 @@
self._search_and(('zope', 'ZOPE'), IISet([1, 3]))
def test_search_or(self):
-
self._populate_index()
self._search_or(('cmf', 'zope3'), IISet([1, 5]))
self._search_or(('cmf', 'zope'), IISet([1, 3, 5]))
self._search_or(('cmf', 'zope4'), IISet([1, 5]))
self._search_or(('zope', 'ZOPE'), IISet([1,3]))
+ def test_index_input(self):
+ self.assertRaises(TypeError, self.index.index_doc, 1, "non-sequence-string")
+
def test_suite():
return TestSuite((makeSuite(KeywordIndexTest), ))
More information about the Zope3-Checkins
mailing list