Beispiel #1
0
def validate_action_params(parameters, dereferencer, app_name, action_name,
                           action_func):
    seen = set()
    for parameter in parameters:
        parameter = deref(parameter, dereferencer)
        name = parameter['name']
        if name in seen:
            raise InvalidApi('Duplicate parameter {0} in api for {1} '
                             'for action {2}'.format(name, app_name,
                                                     action_name))
        seen.add(name)
    if __new_inspection:
        method_params = list(getsignature(action_func).parameters.keys())
    else:
        method_params = getsignature(action_func).args
    if method_params and method_params[0] == 'self':
        method_params.pop(0)
    if not seen == set(method_params):
        only_in_api = seen - set(method_params)
        only_in_definition = set(method_params) - seen
        message = 'Discrepancy between defined parameters in API and in method definition.'
        if only_in_api:
            message += ' Only in API: {0}.'.format(only_in_api)
        if only_in_definition:
            message += ' Only in definition: {0}'.format(only_in_definition)
        raise InvalidApi(message)
Beispiel #2
0
 def _arity(self, f):
     '''
     Return number of non-default position alrguments, if callable.
     '''
     if not callable(f):
         return None
     signature = getsignature(f)
     parameters = signature.parameters.values()
     positionals = [parameter
                    for parameter
                    in parameters
                    if parameter.kind == Parameter.POSITIONAL_OR_KEYWORD and
                       parameter.default == Parameter.empty]
     return len(positionals)
Beispiel #3
0
def get_function_arg_names(func):
    if __new_inspection:
        return list(getsignature(func).parameters.keys())
    else:
        return getsignature(func).args
Beispiel #4
0
def get_function_arg_names(func):
    return list(getsignature(func).parameters.keys())
Beispiel #5
0
def get_function_arg_names(func):
    if __new_inspection:
        return list(getsignature(func).parameters.keys())
    else:
        return getsignature(func).args