Take script input (from script_input above), run the run() function, and
    render the results in the appropriate template

def run_script(module_name):
    '''Take script input (from script_input above), run the run() function, and
    render the results in the appropriate template'''
    filename = ''
    file_stream = ''
    if len(request.files) > 0:
        # Get the name of the uploaded file
        f = request.files['file_upload']

        # Make the filename safe, remove unsupported chars
        filename = secure_filename(f.filename)
        file_stream = f.stream
    try:
        form = werkzeug.datastructures.MultiDict(request.form)
        form['HTTP_AUTHORIZATION'] = get_authorization()
        form['filename'] = filename
        form['file_stream'] = file_stream
        result = registered_modules[module_name].WebAPI().run(form)
    except Exception:
        if app.config['LOCAL_DEV'] == True:
            raise # pass along to be caught by Flask's debugger
        return render_template('error.html',
                               scripts=registered_modules,
                               module_name=module_name,
                               error_message=traceback.format_exc())
    output = result['output']
    if 'output_type' in result:
        output_type = result['output_type']
    else:
        if isinstance(output, basestring):
            output_type = 'simple'
        else:
            output_type = 'table'
    if result['output_type'] == 'custom':
        return render_template('result_custom.html',
                               custom_output=Markup(result['output']),
                               scripts=registered_modules,
                               module_name=module_name)
    elif result['output_type'] == 'simple':
        return render_template('result.html',
                               output=result['output'],
                               scripts=registered_modules,
                               module_name=module_name)
    elif result['output_type'] == 'file':
        return Response(result['output'],
                        mimetype='application/octet-stream',
                        headers={'Content-Disposition':
                                 'attachment;filename='+result['filename']})
    elif result['output_type'] == 'table':
        return render_template('result_table.html',
                               output=result['output'],
                               scripts=registered_modules,
                               module_name=module_name,
                               headers=result['headers'])