def applyrules(rules, d, var={}): ret = {} if type(rules) == types.ListType: for r in rules: rr = applyrules(r, d, var) ret = dictappend(ret, rr) if '_break' in rr: break return ret if '_check' in rules and (not rules['_check'](var)): return ret if 'need' in rules: res = applyrules({'needs': rules['need']}, d, var) if 'needs' in res: cfuncs.append_needs(res['needs']) for k in rules.keys(): if k == 'separatorsfor': ret[k] = rules[k] continue if type(rules[k]) == str: ret[k] = replace(rules[k], d) elif type(rules[k]) == types.ListType: ret[k] = [] for i in rules[k]: ar = applyrules({k: i}, d, var) if k in ar: ret[k].append(ar[k]) elif k[0] == '_': continue elif type(rules[k]) == types.DictType: ret[k] = [] for k1 in rules[k].keys(): if type(k1) == types.FunctionType and k1(var): if type(rules[k][k1]) == types.ListType: for i in rules[k][k1]: if type(i) == types.DictType: res = applyrules({'supertext': i}, d, var) if 'supertext' in res: i = res['supertext'] else: i = '' ret[k].append(replace(i, d)) else: i = rules[k][k1] if type(i) == types.DictType: res = applyrules({'supertext': i}, d) if 'supertext' in res: i = res['supertext'] else: i = '' ret[k].append(replace(i, d)) else: errmess('applyrules: ignoring rule %s.\n' % ` rules[k] `) if type(ret[k]) == types.ListType: if len(ret[k]) == 1: ret[k] = ret[k][0] if ret[k] == []: del ret[k] return ret
def applyrules(rules, d, var={}): ret = {} if type(rules) == types.ListType: for r in rules: rr = applyrules(r, d, var) ret = dictappend(ret, rr) if "_break" in rr: break return ret if "_check" in rules and (not rules["_check"](var)): return ret if "need" in rules: res = applyrules({"needs": rules["need"]}, d, var) if "needs" in res: cfuncs.append_needs(res["needs"]) for k in rules.keys(): if k == "separatorsfor": ret[k] = rules[k] continue if type(rules[k]) == str: ret[k] = replace(rules[k], d) elif type(rules[k]) == types.ListType: ret[k] = [] for i in rules[k]: ar = applyrules({k: i}, d, var) if k in ar: ret[k].append(ar[k]) elif k[0] == "_": continue elif type(rules[k]) == types.DictType: ret[k] = [] for k1 in rules[k].keys(): if type(k1) == types.FunctionType and k1(var): if type(rules[k][k1]) == types.ListType: for i in rules[k][k1]: if type(i) == types.DictType: res = applyrules({"supertext": i}, d, var) if "supertext" in res: i = res["supertext"] else: i = "" ret[k].append(replace(i, d)) else: i = rules[k][k1] if type(i) == types.DictType: res = applyrules({"supertext": i}, d) if "supertext" in res: i = res["supertext"] else: i = "" ret[k].append(replace(i, d)) else: errmess("applyrules: ignoring rule %s.\n" % ` rules[k] `) if type(ret[k]) == types.ListType: if len(ret[k]) == 1: ret[k] = ret[k][0] if ret[k] == []: del ret[k] return ret
def applyrules(rules,d,var={}): ret={} if type(rules)==types.ListType: for r in rules: rr=applyrules(r,d,var) ret=dictappend(ret,rr) if '_break' in rr: break return ret if '_check' in rules and (not rules['_check'](var)): return ret if 'need' in rules: res = applyrules({'needs':rules['need']},d,var) if 'needs' in res: cfuncs.append_needs(res['needs']) for k in rules.keys(): if k=='separatorsfor': ret[k]=rules[k]; continue if type(rules[k])==str: ret[k]=replace(rules[k],d) elif type(rules[k])==types.ListType: ret[k]=[] for i in rules[k]: ar=applyrules({k:i},d,var) if k in ar: ret[k].append(ar[k]) elif k[0]=='_': continue elif type(rules[k])==types.DictType: ret[k]=[] for k1 in rules[k].keys(): if type(k1)==types.FunctionType and k1(var): if type(rules[k][k1])==types.ListType: for i in rules[k][k1]: if type(i)==types.DictType: res=applyrules({'supertext':i},d,var) if 'supertext' in res: i=res['supertext'] else: i='' ret[k].append(replace(i,d)) else: i=rules[k][k1] if type(i)==types.DictType: res=applyrules({'supertext':i},d) if 'supertext' in res: i=res['supertext'] else: i='' ret[k].append(replace(i,d)) else: errmess('applyrules: ignoring rule %s.\n'%`rules[k]`) if type(ret[k])==types.ListType: if len(ret[k])==1: ret[k]=ret[k][0] if ret[k]==[]: del ret[k] return ret