def render_config(config, template_renderer, _path=u''):
 if isinstance(config, (str, Template)):
  try:
   return template_renderer(config)
  except Exception as e:
   e.config_path = _path
   raise
 elif isinstance(config, list):
  if _path:
   _path += u'/'
  return [render_config(v, template_renderer, _path=(_path + str(i))) for (i, v) in enumerate(config)]
 elif isinstance(config, dict):
  if _path:
   _path += u'/'
  return {k: render_config(v, template_renderer, _path=(_path + k)) for (k, v) in config.items()}
 else:
  return config

def render_config ( config , template_renderer , _path = u'' ) : if isinstance ( config , ( str , Template ) ) : try : return template_renderer ( config ) except Exception as e : e . config_path = _path raise elif isinstance ( config , list ) : if _path : _path += u'/' return [ render_config ( v , template_renderer , _path = ( _path + str ( i ) ) ) for ( i , v ) in enumerate ( config ) ] elif isinstance ( config , dict ) : if _path : _path += u'/' return { k : render_config ( v , template_renderer , _path = ( _path + k ) ) for ( k , v ) in config . items ( ) } else : return config
recurse through config data structures attempting to render any string fields against a given context .