def _DoSubstitute(args, context, callback):
  """Variable substitution, e.g. {foo}"""

  name, formatters = args

  # So we can have {.section is_new}new since {@}{.end}.  Hopefully this idiom
  # is OK.
  if name == '@':
    value = context.Lookup('@')
  else:
    try:
      value = context.Lookup(name)
    except TypeError, e:
      raise EvaluationError(
          'Error evaluating %r in context %r: %r' % (name, context, e))

  for func, args, func_type in formatters:
    try:
      if func_type == ENHANCED_FUNC:
        value = func(value, context, args)
      else:
        value = func(value)
    except __HOLE__:
      raise
    except Exception, e:
      raise EvaluationError(
          'Formatting value %r with formatter %s raised exception: %r' %
          (value, formatters, e), original_exception=e)

  # TODO: Require a string/unicode instance here?
  if value is None:
    raise EvaluationError('Evaluating %r gave None value' % name)
  callback(value)
dataset/ETHPy150Open cloudbuilders/radioedit/jsontemplate.py/_DoSubstitute