Minor bug/sloppiness.
To make up, upgrading to a well behaved decorator.

from turbogears.decorator import decorator

def compose(*decorators):
    """ Compose decorators. """
    def entangle(func):
        composition = reduce(lambda f, g: g(f), decorators, func)
        def call(func, *args, **kw):
            return composition(*args, **kw)
        return decorator(call)(func)
    return entangle

Simon Belak wrote:

Something like this?

def compose(*decorators):
    """ Compose decorators. """
    def entangle(func):
        composition = reduce(lambda f, g: g(f), decorators, func)
        def call(*args, **kw):
            return aggregate(*args, **kw)
        return call
    return entangle

example:

def d1(a, b):
    def entangle(f):
        def call(*args, **kw):
            print "d1", a, b
            f(*args, **kw)
        return call
    return entangle

def d2(a, b):
    def entangle(f):
        def call(*args, **kw):
            print "d2", a, b
            f(*args, **kw)
        return call
    return entangle

@compose(d1(1,2), d2("baz", "bar"))
def foo():
    print "foo"

foo()


Cheers,
Simon


Reply via email to