From 18a872de604eaeefff7603fd889a8f7baf8fc94e Mon Sep 17 00:00:00 2001 From: makkalot Date: Sun, 8 Jun 2008 15:03:24 +0300 Subject: adding method_name:{args:{},description:..} structure to get_method_args and fixing some stupid bugs --- func/minion/func_arg.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'func/minion/func_arg.py') diff --git a/func/minion/func_arg.py b/func/minion/func_arg.py index 27beb93..b8a01fa 100644 --- a/func/minion/func_arg.py +++ b/func/minion/func_arg.py @@ -18,15 +18,16 @@ class ArgCompatibility(object): #these are the common options can be used with all types __common_options = ('optional','default','description') + __method_options = ('description','args') #making method declarations more generic like method_name:{'args':{...},'description':"bla bla"} #basic types has types also __basic_types={ - 'range':(), + 'range':[1,], 'min':0, 'max':0, 'optional':False, 'description':'', - 'options':(), + 'options':[1,], 'min_length':0, 'max_length':0, 'validator':'', @@ -54,7 +55,7 @@ class ArgCompatibility(object): def _is_type_options_compatible(self,argument_dict): """ - Checks the argument_dict's options and looks inside + Checks the method's argument_dict's options and looks inside self.__valid_args to see if the used option is there @param : argument_dict : current argument to check @@ -63,7 +64,7 @@ class ArgCompatibility(object): """ #did module writer add a key 'type' if not argument_dict.has_key('type') or not self.__valid_args.has_key(argument_dict['type']): - raise IncompatibleTypesException("%s is not in valid options"%argument_dict['type']) + raise IncompatibleTypesException("%s is not in valid options,possible ones are :%s"%(argument_dict['type'],str(self.__valid_args))) # we will use it everytime so not make lookups the_type = argument_dict['type'] @@ -88,6 +89,7 @@ class ArgCompatibility(object): @param : type_dict : The type to examine @return : True or raise IncompatibleTypesException Exception """ + #print "The structure we got is %s:"%(type_dict) for key,value in type_dict.iteritems(): #do we have that type @@ -95,24 +97,42 @@ class ArgCompatibility(object): raise IncompatibleTypesException("%s not in the basic_types"%key) #if type matches and dont match default + #print "The key: %s its value %s and type %s"%(key,value,type(value)) if key!='default' and type(value)!=type(self.__basic_types[key]): - raise IncompatibleTypesException("%s should be %s"%(key,self.__basic_types[key])) + raise IncompatibleTypesException("The %s keyword should be in that type %s"%(key,type(self.__basic_types[key]))) - return True + return True def validate_all(self): """ Validates the output for minion module's get_method_args method - + + The structure that is going to be validated is in that format : + + { + method_name1 : {'args':{...}, + 'description':"wowo"}, + method_name12 : {...} + } + @return : True or raise IncompatibleTypesException Exception """ - + for method in self.__args_to_check.iterkeys(): - for argument in self.__args_to_check[method].itervalues(): - self._is_basic_types_compatible(argument) - self._is_type_options_compatible(argument) + #here we got args or description part + #check if user did submit something not in the __method_options + + for method_option in self.__args_to_check[method].iterkeys(): + if method_option not in self.__method_options: + raise IncompatibleTypesException("There is no option for method_name like %s,possible ones are : %s"%(method_option,str(self.__method_options))) + #check what is inside the args + if method_option == "args": + for argument in self.__args_to_check[method][method_option].itervalues(): + #print argument + self._is_basic_types_compatible(argument) + self._is_type_options_compatible(argument) return True -- cgit