Nicolas Girard napisaƂ(a):
>     prepend(C.f,pre)
This wraps f, returns wrapped and binds it to C.f (but the
method.__name__ is still wrapped).
>     append(C.f,post)
This wraps wrapped (the one previously returned), returns wrapped (a
new one) and binds it to C.wrapped (since that is what its
method.__name__ says).
>     C().f()
If you try C().wrapped() it works as expected.

So the problem is in retaining the function name. Try:

def append(method,bottom):
    def wrapped(*args, **kwargs):
        res = method(*args, **kwargs)
        return bottom(res,*args, **kwargs)
    wrapped.__name__ = method.__name__
    setattr(method.im_class,method.__name__,wrapped)

def prepend(method,top):
    def wrapped(*args, **kwargs):
        top(*args, **kwargs)
        return method(*args, **kwargs)
    wrapped.__name__ = method.__name__
    setattr(method.im_class,method.__name__,wrapped)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to