#NEWLINE# def stream_decode_response_unicode( iterator , r ) : #NEWLINE# #INDENT# 'Stream decodes a iterator.' #NEWLINE# encoding = get_encoding_from_headers ( r . headers ) #NEWLINE# if ( encoding is None ) : #NEWLINE# #INDENT# for item in iterator : #NEWLINE# #INDENT# ( yield item ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# decoder = codecs . getincrementaldecoder ( encoding ) ( errors = 'replace' ) #NEWLINE# for chunk in iterator : #NEWLINE# #INDENT# rv = decoder . decode ( chunk ) #NEWLINE# if rv : #NEWLINE# #INDENT# ( yield rv ) #NEWLINE# #UNINDENT# #UNINDENT# rv = decoder . decode ( '' , final = True ) #NEWLINE# if rv : #NEWLINE# #INDENT# ( yield rv )