Commit e6c28658 by Michael DeHaan

Add in some code to pre-template datastructures prior to template usage. This…

Add in some code to pre-template datastructures prior to template usage.  This prevents a certain class of error
where filter evaluations can happen too early due to the template engine recursion being a bit limited.

Addresses #4662
parent ad5731b4
...@@ -310,8 +310,32 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis ...@@ -310,8 +310,32 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
utils.deprecated("Legacy variable substitution, such as using ${foo} or $foo instead of {{ foo }} is currently valid but will be phased out and has been out of favor since version 1.2. This is the last of legacy features on our deprecation list. You may continue to use this if you have specific needs for now","1.5") utils.deprecated("Legacy variable substitution, such as using ${foo} or $foo instead of {{ foo }} is currently valid but will be phased out and has been out of favor since version 1.2. This is the last of legacy features on our deprecation list. You may continue to use this if you have specific needs for now","1.5")
return result return result
def fix_ds(basedir, vars, original, depth=0):
''' used to massage the input directory to avoid surprises later and minimize more complex recursive problems '''
while (depth < 20):
depth = depth + 1
vars2 = _fix_ds(basedir, vars, original, depth=depth)
if vars2 == vars:
return vars
vars = vars2
return vars
def _fix_ds(basedir, vars, original, depth=0):
if isinstance(vars, dict):
return dict([ (k, fix_ds(basedir, v, original, depth=depth+1)) for (k,v) in vars.iteritems() ])
if isinstance(vars, (dict, tuple)):
return [ fix_ds(basedir, x,original, depth=depth+1) for x in vars ]
if isinstance(vars, basestring) and "{{" in vars and not "|" in vars:
return lightweight_var_template(basedir, vars, original)
return vars
def lightweight_var_template(basedir, input, vars):
return template_from_string(basedir, input, vars, fail_on_undefined=False, lookups=True, filters=True)
def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True, lookups=True): def template(basedir, input_value, vars, lookup_fatal=True, depth=-1, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True, lookups=True):
vars = fix_ds(basedir, vars, vars.copy())
last_time = input_value last_time = input_value
result = None result = None
changed = True changed = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment