0001class Continue:
0002    """
0003    This class is a singleton (never meant to be instantiated) that
0004    represents a kind of no-op return from a class.
0005    """
0006    def __init__(self):
0007        assert False, (
0008            "Continue cannot be instantiated (use the class object "
0009            "itself)")
0010
0011def wrap_func(func):
0012    name = func.__name__
0013    def replacement_func(actor, *args, **kw):
0014        # @@: It's really more of an "inner_value" than "next_method"
0015        kw['next_method'] = func
0016        result = raise_event('start_%s' % name, actor, *args, **kw)
0017        del kw['next_method']
0018        if result is Continue:
0019            value = func(actor, *args, **kw)
0020        else:
0021            return result
0022        result = raise_event('end_%s' % name, actor, value, *args, **kw)
0023        if result is Continue:
0024            return value
0025        return result
0026    replacement_func.__name__ = name
0027    return replacement_func
0028
0029def raise_event(name, actor, *args, **kw):
0030    for listener in actor.listeners:
0031        value = listener(name, actor, *args, **kw)
0032        if value is not Continue:
0033            return value
0034    return Continue