[Zope-Checkins] CVS: Zope2 - util.py:1.1.2.7

Andreas Jung andreas@digicool.com
Wed, 23 May 2001 10:20:04 -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:
added doc string



--- Updated File util.py in package Zope2 --
--- util.py	2001/05/23 14:03:50	1.1.2.6
+++ util.py	2001/05/23 14:19:53	1.1.2.7
@@ -85,13 +85,46 @@
 
 __version__ = '$Id$'
 
+
 import re
 from types import StringType,ListType,TupleType,DictType
 
 class parseIndexRequest:
+    """
+    This class provides functionality to hide the internals of a request
+    send from the Catalog/ZCatalog to an index._apply_index() method.
+
+    The class understands the following type of parameters:
+
+    - old-style parameters where the query for an index as value inside
+      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
+      passed to the index. 
+
+      Allowed keys of the parameter dictionary:
+
+      'query'  - contains the query (either string, list or tuple) (required)
+
+      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): 
         """ parse a request  from the ZPublisher and return a uniform
         datastructure back to the _apply_index() method of the index
@@ -102,7 +135,6 @@
 
         self.id         = iid
         self.keys       = None
-        self.operator   = None
 
         if not request.has_key(iid): return
 
@@ -125,7 +157,8 @@
             if hasattr(record,'query'):           
                 keys = record.query
             else:
-                raise self.ParserException,"record for '%s' *must* contain a 'query' attribute" % self.id
+                raise self.ParserException,\
+                   "record for '%s' *must* contain a 'query' attribute" % self.id
             
             if type(keys)== StringType:
                 self.keys = [keys.strip()]
@@ -157,15 +190,17 @@
                 self.keys  = keys
             else:
                 self.keys = [keys]
+
+            params = filter(lambda x,id=self.id: x.startswith(id+'_') , \
+                        request.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):
+    def get(self,k,default_v=None):
         
         if hasattr(self,k):
             v = getattr(self,k)
@@ -174,8 +209,11 @@
         else:
             return default_v
 
+def test():
 
-r  = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path')
-for k in dir(r):
-    print k,getattr(r,k)
+    r  = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path')
+    for k in dir(r):
+        print k,getattr(r,k)
 
+if __name__=="__main__":
+    test()