'Context for manually setting counter of seq number.
:init: init value'

@classmethod
@contextlib.contextmanager
def counter(cls, init=0):

    if (not hasattr(ctx, 'counter')):
        ctx.counter = 0
    old = ctx.counter
    ctx.counter = init
    try:
        (yield)
    finally:
        ctx.counter = old
