[Zope-CVS] CVS: Packages/pypes/pypes - query.py:1.11

Casey Duncan casey at zope.com
Thu Apr 29 22:45:14 EDT 2004


Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv21252

Modified Files:
	query.py 
Log Message:
Add intersect_input_map() function


=== Packages/pypes/pypes/query.py 1.10 => 1.11 ===
--- Packages/pypes/pypes/query.py:1.10	Tue Apr 27 23:18:08 2004
+++ Packages/pypes/pypes/query.py	Thu Apr 29 22:45:06 2004
@@ -81,7 +81,27 @@
             else:
                 inmap[name] = set1
         return inmap                    
-    
+
+
+def intersect_input_maps(input1, input2):
+    """Create an input map dict whose values are the intersection of the
+    cooresponding values of input1 and input2 which are mappings of name =>
+    input set. Both input1 and input2 should have the same name keys 
+    """
+    assert Set(input1) == Set(input2), \
+        'cannot union results with different inputs'
+    if input1 is input2:
+        return input1.copy()
+    else:
+        inmap = {}
+        for name, set1 in input1.items():
+            set2 = input2[name]
+            if set1 is not set2:
+                inmap[name] = set1.intersection(set2)
+            else:
+                inmap[name] = set1
+        return inmap                    
+
 
 class CartProduct:
     """Cartesian product of one or more inputs to a query. Allows lazy 
@@ -131,7 +151,7 @@
         return self.__class__(inputs, criteria)
     
     def intersection(self, other):
-        inputs = union_input_maps(self.inputMap(), other.inputMap())
+        inputs = intersect_input_maps(self.inputMap(), other.inputMap())
         criteria = self.criteriaExpr() & other.criteriaExpr()
         return self.__class__(inputs, criteria)
     




More information about the Zope-CVS mailing list