def make_substitutions(conf): """ Substitute occurences of ${foo} with conf[foo], recursively, in all the values of the conf dict. Note that the Java code may also substitute Java properties in, which this code does not have. """ r = re.compile(CONF_VARIABLE_REGEX) def sub(s, depth=0): # Malformed / malicious confs could make this loop infinitely if depth > 100: logging.warn( "Max recursion depth exceeded when substituting jobconf value: %s" % s) return s m = r.search(s) if m: for g in [g for g in m.groups() if g in conf]: substr = "${%s}" % g s = s.replace(substr, sub(conf[g], depth + 1)) return s for k, v in conf.items(): conf[k] = sub(v) return conf
def make_substitutions(conf): """ Substitute occurences of ${foo} with conf[foo], recursively, in all the values of the conf dict. Note that the Java code may also substitute Java properties in, which this code does not have. """ r = re.compile(CONF_VARIABLE_REGEX) def sub(s, depth=0): # Malformed / malicious confs could make this loop infinitely if depth > 100: logging.warn("Max recursion depth exceeded when substituting jobconf value: %s" % s) return s m = r.search(s) if m: for g in [g for g in m.groups() if g in conf]: substr = "${%s}" % g s = s.replace(substr, sub(conf[g], depth + 1)) return s for k, v in conf.items(): conf[k] = sub(v) return conf