A generator class with a buffer. This allows multiple inspections of the stream issued by a generator. For example this is used by MaxMunchGen.

class cpip.util.BufGen.BufGen(theGen)

A generator class with a buffer.


Implements indexing and slicing. Negative indexes will raise an IndexError.

Parameters:key (int) – The index.
Returns:str – The buffer corresponding to the key.
Raises:IndexError, StopIteration

Constructor with a generator as an argument.

Parameters:theGen (generator) – The generator to use.

list of weak references to the object (if defined)


Yield objects from the generator via the buffer.


Returns the length of the existing buffer. NOTE: This may not be the final length as the generator might not be exhausted just yet.

replace(theIdx, theLen, theValueS)

Replaces within the buffer starting at theIdx removing theLen objects and replacing them with theValueS.


Returns a buffer slice of length sliceLen.

exception cpip.util.BufGen.ExceptionBufGen

Exception specialisation for BufGen.