[Zope-Checkins] CVS: Zope2 - util.py:1.1.2.6
Andreas Jung
andreas@digicool.com
Wed, 23 May 2001 10:04:14 -0400
Update of /cvs-repository/Zope2/lib/python/Products/PluginIndexes/common
In directory yetix:/work/sandboxes/ajung-dropin-registry/lib/python/Products/PluginIndexes/common
Modified Files:
Tag: ajung-dropin-registry
util.py
Log Message:
now handles also dictionary parameters
--- Updated File util.py in package Zope2 --
--- util.py 2001/05/22 17:38:14 1.1.2.5
+++ util.py 2001/05/23 14:03:50 1.1.2.6
@@ -86,7 +86,7 @@
__version__ = '$Id$'
import re
-from types import StringType,ListType,TupleType
+from types import StringType,ListType,TupleType,DictType
class parseIndexRequest:
@@ -101,7 +101,6 @@
"""
self.id = iid
- self.usage = None
self.keys = None
self.operator = None
@@ -115,21 +114,11 @@
keys = request[iid]
- if repr(type(keys)).find('instance')==-1:
- """ query is tuple, list or string """
- if type(keys) in [TupleType,ListType]:
- self.keys = keys
- else:
- self.keys = [keys]
+ # This check checks if the object is an instance of
+ # Record - This check is lame and should be fixed !
- params = filter(lambda x,id=self.id: x.startswith(id+'_') , request.keys())
- params = map(lambda x,id=self.id: x[len(id)+1:],params)
- for p in params:
- setattr(self,p,request[self.id+'_'+p])
-
-
- else:
+ if repr(type(keys)).find('instance') != -1:
""" query is of type record """
record = keys
@@ -147,6 +136,34 @@
if not k in ['query','operator']:
setattr(self,k,getattr(record,k))
+ elif type(keys)==DictType:
+ """ query is a dictionary containing all parameters """
+
+ query = keys.get("query",[])
+ if type(query) in [TupleType,ListType]:
+ self.keys = query
+ else:
+ self.keys = [ query ]
+
+ for k,v in keys.items():
+ if k in ["query"]: continue
+ setattr(self,k,v)
+
+
+ else:
+ """ query is tuple, list or string """
+
+ if type(keys) in [TupleType,ListType]:
+ self.keys = keys
+ else:
+ self.keys = [keys]
+
+ params = filter(lambda x,id=self.id: x.startswith(id+'_') , request.keys())
+ params = map(lambda x,id=self.id: x[len(id)+1:],params)
+ for p in params:
+ setattr(self,p,request[self.id+'_'+p])
+
+
def get(self,k,default_v):
@@ -156,3 +173,9 @@
else: return default_v
else:
return default_v
+
+
+r = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path')
+for k in dir(r):
+ print k,getattr(r,k)
+