def write_stream_with_colors_win_py3(stream, outfile, flush):
 color = '\x1b['
 encoding = outfile.encoding
 for chunk in stream:
  if (color in chunk):
   outfile.write(chunk.decode(encoding))
  else:
   outfile.buffer.write(chunk)
  if flush:
   outfile.flush()

def write_stream_with_colors_win_py3 ( stream , outfile , flush ) : color = '\x1b[' encoding = outfile . encoding for chunk in stream : if ( color in chunk ) : outfile . write ( chunk . decode ( encoding ) ) else : outfile . buffer . write ( chunk ) if flush : outfile . flush ( )
like write .