[Zope-CVS] CVS: Packages/pypes/pypes - query.py:1.16
Casey Duncan
casey at zope.com
Wed May 26 00:33:20 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv11671
Modified Files:
query.py
Log Message:
Finish ActualizedResult tests
Finish Join.iterResult() so that it can handle names not joined
=== Packages/pypes/pypes/query.py 1.15 => 1.16 ===
--- Packages/pypes/pypes/query.py:1.15 Fri May 14 00:38:29 2004
+++ Packages/pypes/pypes/query.py Wed May 26 00:32:48 2004
@@ -158,20 +158,32 @@
criteria = self.criteriaExpr() & other.criteriaExpr()
return self.__class__(inputs, criteria)
- def iterResult(self, *names):
+ def iterResult(self, *names, **static):
"""Iterate the cartesian product yielding items from the inputs named
where the criteria is satisfied. If a single name is specified, yield
each matching item from the input. If multiple names are specified,
yield tuples of the matching items from the cooresponding named inputs.
+
+ Static values may be passed as keyword args. The arg name matches an
+ input name, and the value must be a member of the input set. Static
+ inputs are not iterated, but are returned in every result. They are
+ useful when using a cart product inside of another iterator which
+ handles iterating those values itself.
"""
+ for name, obj in static.items():
+ assert obj in self._inputs[name], 'static input not in product'
criteria = self._criteria
# Prime the input iterators and get the first row
row = {}
input_iters = []
for name, ipt in self._inputs.items():
- obj_iter = iter(ipt) # XXX won't work with input iters
- input_iters.append((name, obj_iter))
- row[name] = obj_iter.next()
+ if name not in static:
+ obj_iter = iter(ipt)
+ input_iters.append((name, obj_iter))
+ row[name] = obj_iter.next()
+ else:
+ input_iters.append(None)
+ row[name] = static[name]
# Create output factory from input names
if len(names) == 1:
out, = names
@@ -188,6 +200,10 @@
while True:
try:
name, obj_iter = input_iters[i]
+ except TypeError:
+ # Static value, skip it
+ i += 1
+ continue
except IndexError:
break
while True:
@@ -408,6 +424,22 @@
return join(
self._inputs[self._left_name], self._left_func,
self._inputs[self._right_name], self._right_func)
+
+ def _iterJoinOtherProduct(self, names, joined):
+ # Yield iterators of products for each join pair
+ product = CartProduct(self._inputs, self._criteria)
+ joined = {}
+ has_left = self._left_name in joined
+ has_right = self._right_name in joined
+ # Iterate the joined results and pass them as static values
+ # to the full product's results
+ for left, right in self._iterJoin(self.reverse):
+ if has_left:
+ joined[self._left_name] = left
+ if has_right:
+ joined[self._right_name] = right
+ for row in product.iterResult(*names, **joined):
+ yield row
def iterResult(self, *names):
if len(names) == 2 and names == (self._left_name, self._right_name):
@@ -436,7 +468,7 @@
raise RuntimeError('Bug in join result tranformation')
return imap(output, self._iterJoin(self.reverse))
else:
- raise NotImplementedError
+ return self._iterJoinOtherProduct(names, joined_names)
class ActualizedResult:
More information about the Zope-CVS
mailing list