243 def __next__( self ):
244 """Function implementing the recursive iteration over an AlgSequence
245
246 This is where most of the logic is. The iterator loops over the
247 elements of the AlgSequence that was given to it, one by one. When
248 it finds an element in the AlgSequence that itself is also an
249 AlgSequence, then it creates a helper iterator object that would
250 process that sub-sequence, and continue the iteration using that
251 helper.
252
253 The end result is that the iteration should loop over every
254 algorithm in the sequence and its sub-sequences.
255 """
256
257
258 if self._index >= len( self._sequence ):
259 raise StopIteration()
260
261
262
263 if self._iterator:
264 try:
265 return self._iterator.__next__()
266 except StopIteration:
267
268
269
270 self._index += 1
271 self._iterator = None
272 return self.__next__()
273
274
275
276 element = self._sequence[ self._index ]
277
278
279
280 if isinstance( element, AlgSequence ):
281 self._iterator = AlgSequenceIterator( element )
282 return self.__next__()
283
284
285
286 self._index += 1
287 return element
288
289