def write_stream(stream, outfile, flush):
 try:
  buf = outfile.buffer
 except AttributeError:
  buf = outfile
 for chunk in stream:
  buf.write(chunk)
  if flush:
   outfile.flush()

def write_stream ( stream , outfile , flush ) : try : buf = outfile . buffer except AttributeError : buf = outfile for chunk in stream : buf . write ( chunk ) if flush : outfile . flush ( )
write the output stream .