def enable_buffering(self, size=5): """Enable buffering. Buffer `size` items before yielding them.""" if size <= 1: raise ValueError('buffer size too small') def generator(next): buf = [] c_size = 0 push = buf.append while 1: try: while c_size < size: c = next() push(c) if c: c_size += 1 except StopIteration: if not c_size: return yield concat(buf) del buf[:] c_size = 0 self.buffered = True self._next = get_next(generator(get_next(self._gen)))
def disable_buffering(self): """Disable the output buffering.""" self._next = get_next(self._gen) self.buffered = False
def firstof(*items): return get_next(ifilter(None, items))()