Beispiel #1
0
 def __iter__(self):
     while self.__sources:
         for i in range(len(self.__sources)-1, -1, -1): #iterate from back
             cursrc = self.__sources[i]
             # now return up to __batchsize from cursrc
             try:
                 for n in range(self.__batchsize):
                     yield next(cursrc)
             except StopIteration:
                 # we're done with this source and can delete it since
                 # we iterate the list as we do
                 del self.__sources[i]
     raise StopIteration()
Beispiel #2
0
    def __iter__(self):
        iter1 = self.__src1.__iter__()
        iter2 = self.__src2.__iter__()

        row1 = next(iter1)
        keyval1 = row1[self.__key1]
        rows2 = self.__getnextrows(iter2)
        keyval2 = rows2[0][self.__key2]

        while True:  # At one point there will be a StopIteration
            if keyval1 == keyval2:
                # Output rows
                for part in rows2:
                    resrow = row1.copy()
                    resrow.update(part)
                    yield resrow
                row1 = next(iter1)
                keyval1 = row1[self.__key1]
            elif keyval1 < keyval2:
                row1 = next(iter1)
                keyval1 = row1[self.__key1]
            else:  # k1 > k2
                rows2 = self.__getnextrows(iter2)
                keyval2 = rows2[0][self.__key2]
Beispiel #3
0
 def __getnextrows(self, iter):
     res = []
     keyval = None
     if self.__next is not None:
         res.append(self.__next)
         keyval = self.__next[self.__key2]
         self.__next = None
     while True:
         try:
             row = next(iter)
         except StopIteration:
             if res:
                 return res
             else:
                 raise
         if keyval is None:
             keyval = row[self.__key2]  # for the first row in this round
         if row[self.__key2] == keyval:
             res.append(row)
         else:
             self.__next = row
             return res
Beispiel #4
0
 def getnextseqval(*ignored):
     return next(generator)