Exemple #1
0
def finish_cgi_script(configuration, output_format, ret_code, ret_msg,
                      output_objs):
    """Shared finalization"""

    default_content = 'text/html'
    if 'json' == output_format:
        default_content = 'application/json'
    elif 'html' != output_format:
        default_content = 'text/plain'
    default_headers = [('Content-Type', default_content)]
    start_entry = None
    for entry in output_objs:
        if entry['object_type'] == 'start':
            start_entry = entry
    if not start_entry:
        start_entry = {'object_type': 'start', 'headers': default_headers}
        output_objs = [start_entry] + output_objs
    elif not start_entry.get('headers', []):
        start_entry['headers'] = default_headers
    headers = start_entry['headers']

    output = format_output(configuration, ret_code, ret_msg, output_objs,
                           output_format)

    # Explicit None means error during output formatting - empty string is okay

    if output is None:
        output = 'Error: output could not be correctly delivered!'

    header_out = '\n'.join(["%s: %s" % (key, val) for (key, val) in headers])

    # configuration.logger.debug("raw output:\n%s\n%s" % (header_out, output))

    print header_out
    print ''

    # Print without adding newline

    print output,
Exemple #2
0
def finish_cgi_script(configuration, output_format, ret_code, ret_msg,
                      output_objs):
    """Shared finalization"""

    default_content = 'text/html'
    if 'json' == output_format:
        default_content = 'application/json'
    elif 'html' != output_format:
        default_content = 'text/plain'
    default_headers = [('Content-Type', default_content)]
    start_entry = None
    for entry in output_objs:
        if entry['object_type'] == 'start':
            start_entry = entry
    if not start_entry:
        start_entry = {'object_type': 'start', 'headers': default_headers}
        output_objs = [start_entry] + output_objs
    elif not start_entry.get('headers', []):
        start_entry['headers'] = default_headers
    headers = start_entry['headers']

    output = format_output(configuration, ret_code, ret_msg, output_objs,
                           output_format)
    
    # Explicit None means error during output formatting - empty string is okay

    if output == None:
        output = 'Output could _not_ be extracted!'

    header_out = '\n'.join(["%s: %s" % (key, val) for (key, val) in headers]) 
    
    # configuration.logger.debug("raw output:\n%s\n%s" % (header_out, output))
    
    print header_out
    print ''

    # Print without adding newline

    print output,
Exemple #3
0
    if 'json' == output_format:
        default_content = 'application/json'
    elif 'html' != output_format:
        default_content = 'text/plain'
    default_headers = [('Content-Type', default_content)]
    start_entry = None
    for entry in output_objs:
        if entry['object_type'] == 'start':
            start_entry = entry
    if not start_entry:
        start_entry = {'object_type': 'start', 'headers': default_headers}
        output_objs = [start_entry] + output_objs
    elif not start_entry.get('headers', []):
        start_entry['headers'] = default_headers
    response_headers = start_entry['headers']

    output = format_output(configuration, ret_code, ret_msg, output_objs, output_format)
    if not [i for i in response_headers if 'Content-Length' == i[0]]:
        response_headers.append(('Content-Length', str(len(output))))
    if not output:

        # Error occured during output print

        output = 'Output could _not_ be extracted!'

    start_response(status, response_headers)

    return [output]


Exemple #4
0
                                     client_id, csrf_limit)
        for name in vgrids:
            request = {
                'vgrid_name': [name],
                'request_type': ['vgridmember'],
                'request_text': ['automatic request from importusers script'],
                csrf_field: [csrf_token]
            }
            (output_objs, status) = main(client_id, request)
            if status == returnvalues.OK:
                print 'Request for %s membership in %s sent to owners' % \
                      (client_id, name)
            else:
                print 'Request for %s membership in %s with %s failed:' % \
                      (client_id, name, request)
                output_format = 'text'
                (ret_code, ret_msg) = status
                output = format_output(configuration, ret_code, ret_msg,
                                       output_objs, output_format)

                # Explicit None means error during output formatting

                if output is None:
                    print "ERROR: %s output formatting failed: %s" % \
                          (output_format, output_objs)
                    output = 'Error: output could not be correctly delivered!'
                else:
                    print output

    print '%d new users imported' % len(new_users)