def wrap_output(output, encoding):
 return codecs.getwriter(encoding)((output.buffer if hasattr(output, u'buffer') else output))

def wrap_output ( output , encoding ) : return codecs . getwriter ( encoding ) ( ( output . buffer if hasattr ( output , u'buffer' ) else output ) )
return output with specified encoding .