def stream_as_text(stream):
 for data in stream:
  if (not isinstance(data, six.text_type)):
   data = data.decode(u'utf-8', u'replace')
  (yield data)

def stream_as_text ( stream ) : for data in stream : if ( not isinstance ( data , six . text_type ) ) : data = data . decode ( u'utf-8' , u'replace' ) ( yield data )
given a stream of bytes or text .