Maybe not quite a pythonic approach, but why wouldn't we extract flush_output from the constructor (pushing it into _flush_output that would take code and buffered as arguments)?