'Formats the response to the desired output'

def _api_out_as(self, out):

    if (self._api_cmd == 'docs_md'):
        return out['response']['data']
    elif (self._api_cmd == 'download_log'):
        return
    elif (self._api_cmd == 'pms_image_proxy'):
        cherrypy.response.headers['Content-Type'] = 'image/jpeg'
        return out['response']['data']
    if (self._api_out_type == 'json'):
        cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8'
        try:
            if self._api_debug:
                out = json.dumps(out, indent=4, sort_keys=True)
            else:
                out = json.dumps(out)
            if (self._api_callback is not None):
                cherrypy.response.headers['Content-Type'] = 'application/javascript'
                out = (((self._api_callback + '(') + out) + ');')
        except Exception as e:
            logger.info((u'PlexPy    APIv2    ::    ' + traceback.format_exc()))
            out['message'] = traceback.format_exc()
            out['result'] = 'error'
    elif (self._api_out_type == 'xml'):
        cherrypy.response.headers['Content-Type'] = 'application/xml'
        try:
            out = xmltodict.unparse(out, pretty=True)
        except Exception as e:
            logger.error(u'PlexPy    APIv2    ::    Failed    to    parse    xml    result')
            try:
                out['message'] = e
                out['result'] = 'error'
                out = xmltodict.unparse(out, pretty=True)
            except Exception as e:
                logger.error((u'PlexPy    APIv2    ::    Failed    to    parse    xml    result    error    message    %s' % e))
                out = ('<?xml    version="1.0"    encoding="utf-8"?>\n                                                                                                                                <response>\n                                                                                                                                                <message>%s</message>\n                                                                                                                                                <data></data>\n                                                                                                                                                <result>error</result>\n                                                                                                                                </response>\n                                                                                                        ' % e)
    return out
