def request_parameter(parameter, parameter_type=None, default=None, optional=False):
exp = Experiment(session)<EOL>try:<EOL><INDENT>value = request.values[parameter]<EOL><DEDENT>except KeyError:<EOL><INDENT>if default is not None:<EOL><INDENT>return default<EOL><DEDENT>elif optional:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>".format(<EOL>request.url, request.method, parameter<EOL>)<EOL>return error_response(error_type=msg)<EOL><DEDENT><DEDENT>if parameter_type is None:<EOL><INDENT>return value<EOL><DEDENT>elif parameter_type == "<STR_LIT:int>":<EOL><INDENT>try:<EOL><INDENT>value = int(value)<EOL>return value<EOL><DEDENT>except ValueError:<EOL><INDENT>msg = "<STR_LIT>".format(<EOL>request.url, request.method, parameter, value<EOL>)<EOL>return error_response(error_type=msg)<EOL><DEDENT><DEDENT>elif parameter_type == "<STR_LIT>":<EOL><INDENT>try:<EOL><INDENT>value = exp.known_classes[value]<EOL>return value<EOL><DEDENT>except KeyError:<EOL><INDENT>msg = "<STR_LIT>".format(<EOL>request.url, request.method, value, parameter<EOL>)<EOL>return error_response(error_type=msg)<EOL><DEDENT><DEDENT>elif parameter_type == "<STR_LIT:bool>":<EOL><INDENT>if value in ["<STR_LIT:True>", "<STR_LIT:False>"]:<EOL><INDENT>return value == "<STR_LIT:True>"<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>".format(<EOL>request.url, request.method, parameter, value<EOL>)<EOL>return error_response(error_type=msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>".format(<EOL>request.url, request.method, parameter_type, parameter<EOL>)<EOL>return error_response(error_type=msg)<EOL><DEDENT>
Get a parameter from a request.

    parameter is the name of the parameter you are looking for
    parameter_type is the type the parameter should have
    default is the value the parameter takes if it has not been passed

    If the parameter is not found and no default is specified,
    or if the parameter is found but is of the wrong type
    then a Response object is returned