def __callInits(self, funcs, kwargs): # Iterate functions and pass existing arguments. for class_, func in funcs: args = portable_getargspec(func)[0] #filter those arguments that this __post_init__ receives func_kwargs = dict(filter(lambda x: x[0] in args, kwargs.items())) try: #call the __post_init__ function func(self, **func_kwargs) except TypeError as error: # Extract the traceback of the exception tb_list = traceback.extract_tb(sys.exc_info()[2]) # File where the error occurred error_file = self.__cleanFile(tb_list[-1][0]) # if the error was calling func, then report accordingly. if error_file == self.__cleanFile(__file__): # The problems is calling func. # Get this traceback tb_list = traceback.extract_stack() # Create proper message to report the __post_init__ location. new_message = self.__reportLocalError(tb_list, class_, func, error) else: # The problem is not calling func. # Format the message so that the location is not lost in the report. new_message = self.__reportOutsideError(tb_list, class_, error) raise TypeError(new_message)
def _getMethodTypeNode(self, class_, class_namespace, decorator_class): methods_node = AutoTemplateAstNode() instance = self._getClassInstance(class_) exposed_methods = instance.exposedMethods(decorator_class) if len(exposed_methods): for method_name in exposed_methods: mt_node = TranslationAstNode('methods.%s' % decorator_class.__name__) method = getattr(instance, method_name) if hasattr(method, 'method'): #TODO should look for getDecoratedMethod method = method.method method_args = portable_getargspec(method)[0][1:] cmd_string = class_namespace + '.' + method_name mt_node.translate(METHOD_NAME=method_name, ARGS=self._getArgsJs(method_args), KWARGS=self._getKwargsJs(method_args), RPC_METHOD=cmd_string,) methods_node.translate(method_name, mt_node) return methods_node else: return None