def _get_typed_arg_value(self, given_value, param_def, strict): """Returns a service operation argument value, based on a given value and param schema definition. """ param_type = param_def["type"] if isinstance(given_value, unicode): # Convert all unicode to str in UTF-8 given_value = given_value.encode( "utf8") # Make all unicode into str if isinstance(given_value, IonObjectBase) and ( given_value._get_type() == param_type or param_type in given_value._get_extends()): return given_value elif is_ion_object_dict(given_value) and ( param_type == "NoneType" or hasattr(objects, param_type)): return self.create_ion_object(given_value) elif param_type in ("str", "bool", "int", "float", "list", "dict", "NoneType"): arg_val = get_typed_value(given_value, targettype=param_type, strict=strict) return arg_val else: raise BadRequest("Cannot convert param value to type %s" % param_type)
def create_parameter_list(request_type, service_name, target_client,operation, json_params): param_list = {} method_args = inspect.getargspec(getattr(target_client,operation)) for arg in method_args[0]: if arg == 'self' or arg == 'headers': continue # skip self and headers from being set if not json_params: if request.args.has_key(arg): param_type = get_message_class_in_parm_type(service_name, operation, arg) if param_type == 'str': param_list[arg] = convert_unicode(request.args[arg]) else: param_list[arg] = ast.literal_eval(convert_unicode(request.args[arg])) else: if json_params[request_type]['params'].has_key(arg): #TODO - Potentially remove these conversions whenever ION objects support unicode # UNICODE strings are not supported with ION objects object_params = convert_unicode(json_params[request_type]['params'][arg]) if is_ion_object_dict(object_params): param_list[arg] = create_ion_object(object_params) else: #Not an ION object so handle as a simple type then. param_list[arg] = convert_unicode(json_params[request_type]['params'][arg]) return param_list
def create_parameter_list(request_type, service_name, target_client,operation, json_params): param_list = {} method_args = inspect.getargspec(getattr(target_client,operation)) for arg in method_args[0]: if arg == 'self' or arg == 'headers': continue # skip self and headers from being set if not json_params: if request.args.has_key(arg): param_type = get_message_class_in_parm_type(service_name, operation, arg) if param_type == 'str': if isinstance(request.args[arg], unicode): param_list[arg] = str(request.args[arg].encode('utf8')) else: param_list[arg] = str(request.args[arg]) else: param_list[arg] = ast.literal_eval(str(request.args[arg])) else: if json_params[request_type]['params'].has_key(arg): object_params = json_params[request_type]['params'][arg] if is_ion_object_dict(object_params): param_list[arg] = create_ion_object(object_params) else: #Not an ION object so handle as a simple type then. if isinstance(json_params[request_type]['params'][arg], unicode): param_list[arg] = str(json_params[request_type]['params'][arg].encode('utf8')) else: param_list[arg] = json_params[request_type]['params'][arg] return param_list
def create_parameter_list(request_type, service_name, target_client, operation, json_params): #This is a bit of a hack - should use decorators to indicate which parameter is the dict that acts like kwargs optional_args = request.args.to_dict(flat=True) param_list = {} method_args = inspect.getargspec(getattr(target_client, operation)) for (arg_index, arg) in enumerate(method_args[0]): if arg == 'self': continue # skip self if not json_params: if request.args.has_key(arg): #Keep track of which query_string_parms are left after processing del optional_args[arg] #Handle strings differently because of unicode if isinstance(method_args[3][arg_index - 1], str): if isinstance(request.args[arg], unicode): param_list[arg] = str(request.args[arg].encode('utf8')) else: param_list[arg] = str(request.args[arg]) else: param_list[arg] = ast.literal_eval(str(request.args[arg])) else: if json_params[request_type]['params'].has_key(arg): object_params = json_params[request_type]['params'][arg] if is_ion_object_dict(object_params): param_list[arg] = create_ion_object(object_params) else: #Not an ION object so handle as a simple type then. if isinstance(json_params[request_type]['params'][arg], unicode): param_list[arg] = str(json_params[request_type] ['params'][arg].encode('utf8')) else: param_list[arg] = json_params[request_type]['params'][ arg] #Send any optional_args if there are any and allowed if len(optional_args) > 0 and 'optional_args' in method_args[0]: param_list['optional_args'] = dict() for arg in optional_args: #Only support basic strings for these optional params for now param_list['optional_args'][arg] = str(request.args[arg]) return param_list
def _extract_payload_data(self): request_obj = None if request.headers.get("content-type", "").startswith(CONT_TYPE_JSON): if request.data: request_obj = json_loads(request.data) elif request.form: # Form encoded if GATEWAY_ARG_JSON in request.form: payload = request.form[GATEWAY_ARG_JSON] request_obj = json_loads(str(payload)) if request_obj and is_ion_object_dict(request_obj): request_obj = self.create_ion_object(request_obj) return request_obj
def create_parameter_list(request_type, service_name, target_client, operation, json_params): # This is a bit of a hack - should use decorators to indicate which parameter is the dict that acts like kwargs optional_args = request.args.to_dict(flat=True) param_list = {} method_args = inspect.getargspec(getattr(target_client, operation)) for (arg_index, arg) in enumerate(method_args[0]): if arg == "self": continue # skip self if not json_params: if request.args.has_key(arg): # Keep track of which query_string_parms are left after processing del optional_args[arg] # Handle strings differently because of unicode if isinstance(method_args[3][arg_index - 1], str): if isinstance(request.args[arg], unicode): param_list[arg] = str(request.args[arg].encode("utf8")) else: param_list[arg] = str(request.args[arg]) else: param_list[arg] = ast.literal_eval(str(request.args[arg])) else: if json_params[request_type]["params"].has_key(arg): object_params = json_params[request_type]["params"][arg] if is_ion_object_dict(object_params): param_list[arg] = create_ion_object(object_params) else: # Not an ION object so handle as a simple type then. if isinstance(json_params[request_type]["params"][arg], unicode): param_list[arg] = str(json_params[request_type]["params"][arg].encode("utf8")) else: param_list[arg] = json_params[request_type]["params"][arg] # Send any optional_args if there are any and allowed if len(optional_args) > 0 and "optional_args" in method_args[0]: param_list["optional_args"] = dict() for arg in optional_args: # Only support basic strings for these optional params for now param_list["optional_args"][arg] = str(request.args[arg]) return param_list
def _get_typed_arg_value(self, given_value, param_def, strict): """Returns a service operation argument value, based on a given value and param schema definition. """ param_type = param_def["type"] if isinstance(given_value, unicode): # Convert all unicode to str in UTF-8 given_value = given_value.encode("utf8") # Make all unicode into str if isinstance(given_value, IonObjectBase) and (given_value._get_type() == param_type or param_type in given_value._get_extends()): return given_value elif is_ion_object_dict(given_value) and (param_type == "NoneType" or hasattr(objects, param_type)): return self.create_ion_object(given_value) elif param_type in ("str", "bool", "int", "float", "list", "dict", "NoneType"): arg_val = get_typed_value(given_value, targettype=param_type, strict=strict) return arg_val else: raise BadRequest("Cannot convert param value to type %s" % param_type)
def create_parameter_list(request_type, service_name, target_client, operation, json_params): param_list = {} method_args = inspect.getargspec(getattr(target_client, operation)) for arg in method_args[0]: if arg == 'self' or arg == 'headers': continue # skip self and headers from being set if not json_params: if request.args.has_key(arg): param_type = get_message_class_in_parm_type( service_name, operation, arg) if param_type == 'str': if isinstance(request.args[arg], unicode): param_list[arg] = str(request.args[arg].encode('utf8')) else: param_list[arg] = str(request.args[arg]) else: param_list[arg] = ast.literal_eval(str(request.args[arg])) else: if json_params[request_type]['params'].has_key(arg): object_params = json_params[request_type]['params'][arg] if is_ion_object_dict(object_params): param_list[arg] = create_ion_object(object_params) else: #Not an ION object so handle as a simple type then. if isinstance(json_params[request_type]['params'][arg], unicode): param_list[arg] = str(json_params[request_type] ['params'][arg].encode('utf8')) else: param_list[arg] = json_params[request_type]['params'][ arg] return param_list