class BeforeAfterWrapper(object):
    def __init__(self, wrapped_self, method_to_wrap_name, context_manager):
        self.wrapped_self = wrapped_self
        self.method_to_wrap_name = method_to_wrap_name
        self.orig_method = getattr(self.wrapped_self, self.method_to_wrap_name)
        self.context_manager = context_manager
        setattr(self.wrapped_self, self.method_to_wrap_name, self.wrap)

    def wrap(self, *a, **kw):
        with self.context_manager:
            return self.orig_method(*a, **kw)

@@ -510,8 +510,733 @@
 , **kw)%0A
+%0A%0Aclass DelegatingProxy(object):%0A    %22%22%22%0A    Proxy for accessing the wrapped object's attributes, while allowing%0A    overwriting specific methods%0A    %22%22%22%0A    def __init__(self, wrapped):%0A        self.__dict__%5B'wrapped'%5D = wrapped%0A%0A    def __getattr__(self, item):%0A        return getattr(self.wrapped, item)%0A%0A    def __setattr__(self, name, value):%0A        return setattr(self.wrapped, name, value)%0A%0A    def __delattr__(self, name):%0A        return delattr(self.wrapped, name)%0A%0A    def __eq__(self, other):%0A        return self.wrapped == other%0A%0A    def __ne__(self, other):%0A        return self.wrapped != other%0A%0A    def __len__(self):%0A        return len(self.wrapped)%0A%0A    def __iter__(self):%0A        return iter(self.wrapped)%0A

introduce DelegatingProxy object