def _Execute(statements, context, callback, trace):
    """Execute a bunch of template statements in a ScopedContext.

  Args:
    callback: Strings are "written" to this callback function.
    trace: Trace object, or None

  This is called in a mutually recursive fashion.
  """
    # Every time we call _Execute, increase this depth
    if trace:
        trace.exec_depth += 1
    for i, statement in enumerate(statements):
        if isinstance(statement, six.string_types):
            callback(statement)
        else:
            # In the case of a substitution, args is a pair (name, formatters).
            # In the case of a section, it's a _Section instance.
            try:
                func, args = statement
                func(args, context, callback, trace)
            except UndefinedVariable as e:
                # Show context for statements
                start = max(0, i - 3)
                end = i + 3
                e.near = statements[start:end]
                e.trace = trace  # Attach caller's trace (could be None)
                raise
Execute a bunch of template statements in a ScopedContext.

  Args:
    callback: Strings are "written" to this callback function.
    trace: Trace object, or None

  This is called in a mutually recursive fashion.