def render_values(mapping=None, context=None, allow_undefined=False):
 if ((not context) or (not mapping)):
  return mapping
 super_context = {}
 super_context['__context'] = context
 super_context.update(context)
 env = get_jinja_environment(allow_undefined=allow_undefined)
 rendered_mapping = {}
 for (k, v) in six.iteritems(mapping):
  reverse_json_dumps = False
  if (isinstance(v, dict) or isinstance(v, list)):
   v = json.dumps(v)
   reverse_json_dumps = True
  else:
   v = str(v)
  try:
   LOG.info('Rendering string %s. Super context=%s', v, super_context)
   rendered_v = env.from_string(v).render(super_context)
  except Exception as e:
   e.key = k
   e.value = v
   raise e
  if (rendered_v == v):
   rendered_mapping[k] = mapping[k]
   continue
  if reverse_json_dumps:
   rendered_v = json.loads(rendered_v)
  rendered_mapping[k] = rendered_v
 LOG.info('Mapping: %s, rendered_mapping: %s, context: %s', mapping, rendered_mapping, context)
 return rendered_mapping

def render_values ( mapping = None , context = None , allow_undefined = False ) : if ( ( not context ) or ( not mapping ) ) : return mapping super_context = { } super_context [ '__context' ] = context super_context . update ( context ) env = get_jinja_environment ( allow_undefined = allow_undefined ) rendered_mapping = { } for ( k , v ) in six . iteritems ( mapping ) : reverse_json_dumps = False if ( isinstance ( v , dict ) or isinstance ( v , list ) ) : v = json . dumps ( v ) reverse_json_dumps = True else : v = str ( v ) try : LOG . info ( 'Rendering string %s. Super context=%s' , v , super_context ) rendered_v = env . from_string ( v ) . render ( super_context ) except Exception as e : e . key = k e . value = v raise e if ( rendered_v == v ) : rendered_mapping [ k ] = mapping [ k ] continue if reverse_json_dumps : rendered_v = json . loads ( rendered_v ) rendered_mapping [ k ] = rendered_v LOG . info ( 'Mapping: %s, rendered_mapping: %s, context: %s' , mapping , rendered_mapping , context ) return rendered_mapping
render an incoming mapping using context provided in context using jinja2 .