def _DoRepeatedSection(args, context, callback, trace):
    """{.repeated section foo}"""
    
    block = args
    
    items = context.PushSection(block.section_name, block.pre_formatters)
    if items:
        if not isinstance(items, list):
            raise EvaluationError('Expected a list; got %s' % type(items))
        
        last_index = len(items) - 1
        statements = block.Statements()
        alt_statements = block.Statements('alternates with')
        try:
            i = 0
            while True:
                context.Next()
                # Execute the statements in the block for every item in the list.
                # Execute the alternate block on every iteration except the last.  Each
                # item could be an atom (string, integer, etc.) or a dictionary.
                _Execute(statements, context, callback, trace)
                if i != last_index:
                    _Execute(alt_statements, context, callback, trace)
                i += 1
        except StopIteration:
            pass
    
    else:
        _Execute(block.Statements('or'), context, callback, trace)
    
    context.Pop()
def _DoRepeatedSection ( args , context , callback , trace ) : block = args items = context . PushSection ( block . section_name , block . pre_formatters ) if items : if not isinstance ( items , list ) : raise EvaluationError ( 'Expected a list; got %s' % type ( items ) ) last_index = len ( items ) - 1 statements = block . Statements ( ) alt_statements = block . Statements ( 'alternates with' ) try : i = 0 while True : context . Next ( ) _Execute ( statements , context , callback , trace ) if i != last_index : _Execute ( alt_statements , context , callback , trace ) i += 1 except StopIteration : pass else : _Execute ( block . Statements ( 'or' ) , context , callback , trace ) context . Pop ( )
{.repeated section foo}