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