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

Casey Duncan casey at zope.com
Tue Apr 27 23:18:42 EDT 2004


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

Modified Files:
	query.py 
Log Message:
implement CartProduct union() and intersection()


=== Packages/pypes/pypes/query.py 1.9 => 1.10 ===
--- Packages/pypes/pypes/query.py:1.9	Wed Apr 21 01:32:09 2004
+++ Packages/pypes/pypes/query.py	Tue Apr 27 23:18:08 2004
@@ -68,14 +68,19 @@
     values of input1 and input2 which are mappings of name => input set. Both
     input1 and input2 should have the same name keys
     """
-    inmap = {}
-    for name, set1 in input1.items():
-        set2 = input2[name]
-        if set1 is not set2:
-            inmap[name] = set1.union(set2)
-        else:
-            inmap[name] = set1
-    return inmap                    
+    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.union(set2)
+            else:
+                inmap[name] = set1
+        return inmap                    
     
 
 class CartProduct:
@@ -121,12 +126,14 @@
         return reduce(mul, [len(self._inputs[nm]) for nm in names])
         
     def union(self, other):
-        assert Set(self.inputMap()) == Set(other.inputMap()), \
-            'cannot union partial results with different inputs'
-        pass
+        inputs = union_input_maps(self.inputMap(), other.inputMap())
+        criteria = self.criteriaExpr() | other.criteriaExpr()
+        return self.__class__(inputs, criteria)
     
     def intersection(self, other):
-        pass            
+        inputs = union_input_maps(self.inputMap(), other.inputMap())
+        criteria = self.criteriaExpr() & other.criteriaExpr()
+        return self.__class__(inputs, criteria)
     
     def iterResult(self, *names):
         """Iterate the cartesian product yielding items from the inputs named




More information about the Zope-CVS mailing list