def getFunctionForExecuteMessage(self, jsonMessage, objectToRead):
        if 'field' not in jsonMessage:
            raise MalformedMessageException("missing 'field'")

        field = jsonMessage['field']

        if not isinstance(field, str):
            raise MalformedMessageException("fieldname was not a string")

        field = intern(field)

        try:
            funDef = getattr(getObjectClass(objectToRead), field)
        except:
            raise InvalidFieldException()

        funDef = getattr(getObjectClass(objectToRead), field)

        if not Decorators.isFunctionToExpose(funDef):
            raise InvalidFunctionException()

        if Decorators.functionExpectsCallback(funDef):
            if Decorators.functionExpectsExpandedArgs(funDef):
                def caller(x, callback, arg):
                    if isinstance(arg, list):
                        return getattr(x,field)(callback, *arg)
                    else:
                        return getattr(x,field)(callback, **arg)
                return caller
            else:
                return lambda x, callback, *args: getattr(x, field)(callback, *args)
        else:
            if Decorators.functionExpectsExpandedArgs(funDef):
                def caller(x, callback, arg):
                    try:
                        if isinstance(arg, list):
                            callback(getattr(x,field)(*arg))
                        else:
                            callback(getattr(x,field)(**arg))
                    except Exception as e:
                        callback(e)

                return caller
            else:
                def caller(x, callback, *args):
                    try:
                        callback(getattr(x, field)(*args))
                    except Exception as e:
                        callback(e)
                return caller
dataset/ETHPy150Open ufora/ufora/ufora/BackendGateway/SubscribableWebObjects/MessageProcessor.py/MessageProcessor.getFunctionForExecuteMessage/original