Exemple #1
0
def _check_macro(value, module_files=None, meta_dir=None):
    if module_files is None:
        module_files = _get_module_files(meta_dir)
    if not module_files:
        return
    try:
        macros = rose.variable.array_split(value, only_this_delim=",")
    except Exception as exc:
        return INVALID_SYNTAX.format(exc)
    for macro in macros:
        macro_name = macro
        method = None
        if (macro.endswith("." + rose.macro.VALIDATE_METHOD)
                or macro.endswith("." + rose.macro.TRANSFORM_METHOD)):
            macro_name, method = macro.rsplit(".", 1)
        try:
            macro_obj = rose.resource.import_object(macro_name, module_files,
                                                    _import_err_handler)
        except Exception as exc:
            return INVALID_IMPORT.format(macro, type(exc).__name__, exc)
        if macro_obj is None:
            return INVALID_OBJECT.format(macro)
        elif method is not None:
            if not hasattr(macro_obj, method):
                return INVALID_OBJECT.format(method)
Exemple #2
0
def _check_macro(value, module_files=None, meta_dir=None):
    if module_files is None:
        module_files = _get_module_files(meta_dir)
    if not module_files:
        return
    try:
        macros = rose.variable.array_split(value, only_this_delim=",")
    except Exception as exc:
        return INVALID_SYNTAX.format(exc)
    for macro in macros:
        macro_name = macro
        method = None
        if (macro.endswith("." + rose.macro.VALIDATE_METHOD) or
                macro.endswith("." + rose.macro.TRANSFORM_METHOD)):
            macro_name, method = macro.rsplit(".", 1)
        try:
            macro_obj = rose.resource.import_object(
                macro_name, module_files, _import_err_handler)
        except Exception as exc:
            return INVALID_IMPORT.format(macro, type(exc).__name__, exc)
        if macro_obj is None:
            return INVALID_OBJECT.format(macro)
        elif method is not None:
            if not hasattr(macro_obj, method):
                return INVALID_OBJECT.format(method)