[Zope-Checkins] SVN: Zope/trunk/ - some minor plugin indexes cleanup
Yvo Schubbe
y.2007- at wcm-solutions.de
Tue Jan 30 13:58:09 EST 2007
Log message for revision 72262:
- some minor plugin indexes cleanup
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py
U Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
U Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py
U Zope/trunk/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py
U Zope/trunk/lib/python/Products/PluginIndexes/TopicIndex/TopicIndex.py
U Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py
_U Zope/trunk/lib/python/Products/PluginIndexes/common/tests/__init__.py
_U Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_UnIndex.py
A Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_util.py
UU Zope/trunk/lib/python/Products/PluginIndexes/common/util.py
U Zope/trunk/lib/python/Products/PluginIndexes/interfaces.py
U Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/doc/CHANGES.txt 2007-01-30 18:58:05 UTC (rev 72262)
@@ -8,6 +8,8 @@
Restructuring
+ - Indexes: Removed unused parameters from '_apply_index' methods.
+
- Fixed Collector #2190: Calls to
zope.security.management.checkPermission aren't rerouted to
Zope 2's security policy.
@@ -78,6 +80,8 @@
Bugs Fixed
+ - PluginIndexes: Fixed 'parseIndexRequest' for false values.
+
- Collector #2269: fixed broken ZPT FTP support
- Collector #2261: Acquisition when creating objects via Webdav.
Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -19,7 +19,6 @@
from logging import getLogger
from datetime import date, datetime
from datetime import tzinfo, timedelta
-from types import StringType, FloatType, IntType
import BTrees.Length
from BTrees.IIBTree import IISet, union, intersection, multiunion
@@ -90,7 +89,7 @@
implements(IDateIndex)
meta_type = 'DateIndex'
- query_options = ['query', 'range']
+ query_options = ('query', 'range')
index_naive_time_as_local = True # False means index as UTC
_properties=({'id':'index_naive_time_as_local',
@@ -157,14 +156,14 @@
return returnStatus
- def _apply_index( self, request, cid='', type=type ):
+ def _apply_index(self, request):
"""Apply the index to query parameters given in the argument
Normalize the 'query' arguments into integer values at minute
precision before querying.
"""
- record = parseIndexRequest( request, self.id, self.query_options )
- if record.keys == None:
+ record = parseIndexRequest(request, self.id, self.query_options)
+ if record.keys is None:
return None
keys = map( self._convert, record.keys )
@@ -215,22 +214,17 @@
else:
setlist = index.values(lo)
- #for k, set in setlist:
- #if type(set) is IntType:
- #set = IISet((set,))
- #r = set_func(r, set)
- # XXX: Use multiunion!
r = multiunion(setlist)
else: # not a range search
for key in keys:
set = index.get(key, None)
if set is not None:
- if type(set) is IntType:
+ if isinstance(set, int):
set = IISet((set,))
r = set_func(r, set)
- if type(r) is IntType:
+ if isinstance(r, int):
r = IISet((r,))
if r is None:
@@ -242,20 +236,20 @@
"""Convert Date/Time value to our internal representation"""
# XXX: Code patched 20/May/2003 by Kiran Jonnalagadda to
# convert dates to UTC first.
- if isinstance( value, DateTime ):
+ if isinstance(value, DateTime):
t_tup = value.toZone('UTC').parts()
- elif type( value ) in (FloatType, IntType):
+ elif isinstance(value, (float, int)):
t_tup = time.gmtime( value )
- elif type( value ) is StringType and value:
+ elif isinstance(value, str) and value:
t_obj = DateTime( value ).toZone('UTC')
t_tup = t_obj.parts()
- elif type( value ) is date:
- t_tup = value.timetuple()
- elif type( value ) is datetime:
+ elif isinstance(value, datetime):
if self.index_naive_time_as_local and value.tzinfo is None:
value = value.replace(tzinfo=Local)
# else if tzinfo is None, naive time interpreted as UTC
t_tup = value.utctimetuple()
+ elif isinstance(value, date):
+ t_tup = value.timetuple()
else:
return default
Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -63,6 +63,7 @@
security = ClassSecurityInfo()
meta_type = "DateRangeIndex"
+ query_options = ('query',)
manage_options= ( { 'label' : 'Properties'
, 'action' : 'manage_indexProperties'
@@ -70,8 +71,6 @@
,
)
- query_options = ['query']
-
since_field = until_field = None
def __init__(self, id, since_field=None, until_field=None,
@@ -213,7 +212,6 @@
t2 = self._until_only
result = []
- IntType = type( 0 )
if not withLengths:
@@ -224,7 +222,7 @@
for key in t1.keys():
set = t1[ key ]
- if type( set ) is IntType:
+ if isinstance(set, int):
length = 1
else:
length = len( set )
@@ -232,7 +230,7 @@
for key in t2.keys():
set = t2[ key ]
- if type( set ) is IntType:
+ if isinstance(set, int):
length = 1
else:
length = len( set )
@@ -240,12 +238,12 @@
return tuple( result )
- def _apply_index( self, request, cid='' ):
+ def _apply_index(self, request):
"""
Apply the index to query parameters given in 'request', which
should be a mapping object.
- If the request does not contain the needed parametrs, then
+ If the request does not contain the needed parameters, then
return None.
If the request contains a parameter with the name of the
@@ -257,7 +255,7 @@
second object is a tuple containing the names of all data fields
used.
"""
- record = parseIndexRequest( request, self.getId() )
+ record = parseIndexRequest(request, self.id, self.query_options)
if record.keys is None:
return None
@@ -396,10 +394,10 @@
def _convertDateTime( self, value ):
if value is None:
return value
- if type( value ) == type( '' ):
+ if isinstance(value, str):
dt_obj = DateTime( value )
value = dt_obj.millis() / 1000 / 60 # flatten to minutes
- if isinstance( value, DateTime ):
+ if isinstance(value, DateTime):
value = value.millis() / 1000 / 60 # flatten to minutes
result = int( value )
if isinstance(result, long): # this won't work (Python 2.3)
Modified: Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -15,7 +15,6 @@
$Id$
"""
-from types import StringType, ListType, TupleType
from logging import getLogger
from Globals import Persistent, DTMLFile
@@ -56,6 +55,7 @@
implements(IPathIndex, IUniqueValueIndex)
meta_type="PathIndex"
+ query_options = ('query', 'level', 'operator')
manage_options= (
{'label': 'Settings',
@@ -63,8 +63,6 @@
'help': ('PathIndex','PathIndex_Settings.stx')},
)
- query_options = ("query", "level", "operator")
-
def __init__(self,id,caller=None):
self.id = id
self.operators = ('or','and')
@@ -108,7 +106,7 @@
else:
path = f
- if not isinstance(path, (StringType, TupleType)):
+ if not isinstance(path, (str, tuple)):
raise TypeError('path value must be string or tuple of strings')
else:
try:
@@ -116,7 +114,7 @@
except AttributeError:
return 0
- if isinstance(path, (ListType, TupleType)):
+ if isinstance(path, (list, tuple)):
path = '/'+ '/'.join(path[1:])
comps = filter(None, path.split('/'))
@@ -165,8 +163,7 @@
level >= 0 starts searching at the given level
level < 0 not implemented yet
"""
-
- if isinstance(path, StringType):
+ if isinstance(path, str):
level = default_level
else:
level = int(path[1])
@@ -207,18 +204,16 @@
def __len__(self):
return self._length()
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request):
""" hook for (Z)Catalog
'request' -- mapping type (usually {"path": "..." }
additionaly a parameter "path_level" might be passed
to specify the level (see search())
-
- 'cid' -- ???
"""
+ record = parseIndexRequest(request, self.id, self.query_options)
+ if record.keys is None:
+ return None
- record = parseIndexRequest(request,self.id,self.query_options)
- if record.keys==None: return None
-
level = record.get("level",0)
operator = record.get('operator',self.useOperator).lower()
Modified: Zope/trunk/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/TextIndex/TextIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -82,6 +82,7 @@
implements(ITextIndex, IPluggableIndex)
meta_type='TextIndex'
+ query_options = ('query', 'operator')
manage_options= (
{'label': 'Settings',
@@ -89,8 +90,6 @@
'help': ('TextIndex','TextIndex_Settings.stx')},
)
- query_options = ["query","operator"]
-
def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None,
caller=None, extra=None):
"""Create an index
@@ -440,7 +439,7 @@
return r
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request):
""" Apply the index to query parameters given in the argument,
request
@@ -454,10 +453,10 @@
records. The second object is a tuple containing the names of
all data fields used.
"""
+ record = parseIndexRequest(request, self.id, self.query_options)
+ if record.keys is None:
+ return None
- record = parseIndexRequest(request,self.id,self.query_options)
- if record.keys==None: return None
-
# Changed for 2.4
# We use the default operator that can me managed via the ZMI
Modified: Zope/trunk/lib/python/Products/PluginIndexes/TopicIndex/TopicIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/TopicIndex/TopicIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/TopicIndex/TopicIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -46,7 +46,7 @@
implements(ITopicIndex, IPluggableIndex)
meta_type="TopicIndex"
- query_options = ('query','operator')
+ query_options = ('query', 'operator')
manage_options= (
{'label': 'FilteredSets',
@@ -91,15 +91,14 @@
if self.filteredSets.has_key(filter_id):
return self.filteredSets[filter_id].getIds()
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request):
""" hook for (Z)Catalog
'request' -- mapping type (usually {"topic": "..." }
- 'cid' -- ???
"""
+ record = parseIndexRequest(request, self.id, self.query_options)
+ if record.keys is None:
+ return None
- record = parseIndexRequest(request,self.id,self.query_options)
- if record.keys is None: return None
-
operator = record.get('operator', self.defaultOperator).lower()
if operator == 'or': set_func = union
else: set_func = intersection
Modified: Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/common/UnIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -304,7 +304,7 @@
LOG.debug('Attempt to unindex nonexistent document'
' with id %s' % documentId,exc_info=True)
- def _apply_index(self, request, cid='', type=type):
+ def _apply_index(self, request):
"""Apply the index to query parameters given in the request arg.
The request argument should be a mapping object.
@@ -344,7 +344,8 @@
up in a tuple ala: request = {'id':('',)}
"""
record = parseIndexRequest(request, self.id, self.query_options)
- if record.keys==None: return None
+ if record.keys is None:
+ return None
index = self._index
r = None
Property changes on: Zope/trunk/lib/python/Products/PluginIndexes/common/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Property changes on: Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_UnIndex.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_util.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_util.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_util.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Unit tests for util module.
+
+$Id$
+"""
+
+import unittest
+
+from ZPublisher.HTTPRequest import record as Record
+
+
+class parseIndexRequestTests(unittest.TestCase):
+
+ def _getTargetClass(self):
+ from Products.PluginIndexes.common.util import parseIndexRequest
+
+ return parseIndexRequest
+
+ def _makeOne(self, *args, **kw):
+ return self._getTargetClass()(*args, **kw)
+
+ def test_get_record(self):
+ record = Record()
+ record.query = 'foo'
+ record.level = 0
+ record.operator = 'and'
+ request = {'path': record}
+ parser = self._makeOne(request, 'path', ('query','level','operator'))
+ self.assertEqual(parser.get('keys'), ['foo'])
+ self.assertEqual(parser.get('level'), 0)
+ self.assertEqual(parser.get('operator'), 'and')
+
+ def test_get_dict(self):
+ request = {'path': {'query': 'foo', 'level': 0, 'operator': 'and'}}
+ parser = self._makeOne(request, 'path', ('query','level','operator'))
+ self.assertEqual(parser.get('keys'), ['foo'])
+ self.assertEqual(parser.get('level'), 0)
+ self.assertEqual(parser.get('operator'), 'and')
+
+ def test_get_string(self):
+ request = {'path': 'foo', 'path_level': 0, 'path_operator': 'and'}
+ parser = self._makeOne(request, 'path', ('query','level','operator'))
+ self.assertEqual(parser.get('keys'), ['foo'])
+ self.assertEqual(parser.get('level'), 0)
+ self.assertEqual(parser.get('operator'), 'and')
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(parseIndexRequestTests))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: Zope/trunk/lib/python/Products/PluginIndexes/common/tests/test_util.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: Zope/trunk/lib/python/Products/PluginIndexes/common/util.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/common/util.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/common/util.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -7,20 +7,21 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
#
-#############################################################################
+##############################################################################
+"""PluginIndexes utils.
-__version__ = '$Id$'
+$Id$
+"""
-
from warnings import warn
-from types import StringType,ListType,TupleType,DictType,InstanceType
+from types import InstanceType
from DateTime import DateTime
-SequenceTypes = (TupleType, ListType)
class parseIndexRequest:
+
"""
This class provides functionality to hide the internals of a request
send from the Catalog/ZCatalog to an index._apply_index() method.
@@ -31,7 +32,6 @@
the request directory where the index name is the name of the key.
Additional parameters for an index could be passed as index+"_usage" ...
-
- dictionary-style parameters specify a query for an index as
an entry in the request dictionary where the key corresponds to the
name of the index and the key is a dictionary with the parameters
@@ -43,16 +43,13 @@
other parameters depend on the the index
-
- record-style parameters specify a query for an index as instance of the
Record class. This happens usually when parameters from a web form use
the "record" type e.g. <input type="text" name="path.query:record:string">.
All restrictions of the dictionary-style parameters apply to the record-style
parameters
-
"""
-
ParserException = 'IndexRequestParseError'
def __init__(self, request, iid, options=[]):
@@ -73,13 +70,16 @@
usage_param = iid + '_usage'
if request.has_key(usage_param):
self.usage = request[usage_param]
- warn("\nZCatalog query using '%s' detected.\nUsing query parameters ending with '_usage' is deprecated.\nConsider using record-style parameters instead (see lib/python/Products/PluginIndexes/README.txt for details)" % usage_param, DeprecationWarning)
+ warn("ZCatalog query using '%s' detected.\n"
+ "Using query parameters ending with '_usage' is deprecated.\n"
+ "Consider using record-style parameters instead "
+ "(see lib/python/Products/PluginIndexes/README.txt for "
+ "details)" % usage_param, DeprecationWarning)
param = request[iid]
keys = None
- t = type(param)
- if t is InstanceType and not isinstance(param, DateTime):
+ if isinstance(param, InstanceType) and not isinstance(param, DateTime):
""" query is of type record """
record = param
@@ -90,7 +90,7 @@
"'query' attribute" % self.id)
keys = record.query
- if type(keys) is StringType:
+ if isinstance(keys, str):
keys = [keys.strip()]
for op in options:
@@ -99,11 +99,11 @@
if hasattr(record, op):
setattr(self, op, getattr(record, op))
- elif t is DictType:
+ elif isinstance(param, dict):
""" query is a dictionary containing all parameters """
query = param.get("query", ())
- if type(query) in SequenceTypes:
+ if isinstance(query, (tuple, list)):
keys = query
else:
keys = [ query ]
@@ -117,7 +117,7 @@
else:
""" query is tuple, list, string, number, or something else """
- if t in SequenceTypes:
+ if isinstance(param, (tuple, list)):
keys = param
else:
keys = [param]
@@ -129,21 +129,9 @@
self.keys = keys
-
- def get(self,k,default_v=None):
-
- if hasattr(self,k):
- v = getattr(self,k)
- if v: return v
- else: return default_v
- else:
- return default_v
-
-def test():
-
- r = parseIndexRequest({'path':{'query':"","level":2,"operator":'and'}},'path',['query',"level","operator"])
- for k in dir(r):
- print k,getattr(r,k)
-
-if __name__=="__main__":
- test()
+ def get(self, k, default_v=None):
+ if hasattr(self, k):
+ v = getattr(self, k)
+ if v != '':
+ return v
+ return default_v
Property changes on: Zope/trunk/lib/python/Products/PluginIndexes/common/util.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
- 1.13
Modified: Zope/trunk/lib/python/Products/PluginIndexes/interfaces.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/interfaces.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/PluginIndexes/interfaces.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -43,12 +43,12 @@
def unindex_object(documentId):
"""Remove the documentId from the index."""
- def _apply_index(request, cid=''):
+ def _apply_index(request):
"""Apply the index to query parameters given in 'request'.
The argument should be a mapping object.
- If the request does not contain the needed parametrs, then
+ If the request does not contain the needed parameters, then
None is returned.
If the request contains a parameter with the name of the column
Modified: Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py 2007-01-30 15:11:42 UTC (rev 72261)
+++ Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py 2007-01-30 18:58:05 UTC (rev 72262)
@@ -61,13 +61,12 @@
## Magic class attributes ##
meta_type = 'ZCTextIndex'
+ query_options = ('query',)
manage_options = (
{'label': 'Overview', 'action': 'manage_main'},
)
- query_options = ['query']
-
security = ClassSecurityInfo()
security.declareObjectProtected(manage_zcatalog_indexes)
@@ -204,7 +203,7 @@
if self.index.has_doc(docid):
self.index.unindex_doc(docid)
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request):
"""Apply query specified by request, a mapping containing the query.
Returns two object on success, the resultSet containing the
@@ -216,6 +215,7 @@
record = parseIndexRequest(request, self.id, self.query_options)
if record.keys is None:
return None
+
query_str = ' '.join(record.keys)
if not query_str:
return None
More information about the Zope-Checkins
mailing list