Create a wrapper class to call a pre and post function around existing functions?
<p>I want to create a class that wraps another class so that when a function is run through the wrapper class a pre and post function is run as well. I want the wrapper class to work with any class without modification.</p>

<p>For example if i have this class.</p>

<pre><code>class Simple(object):
    def one(self):
        print "one"

    def two(self,two):
        print "two" + two

    def three(self):
        print "three"
</code></pre>

<p>I could use it like this...</p>

<pre><code>number = Simple()
number.one()
number.two("2")
</code></pre>

<p>I have so far written this wrapper class...</p>

<pre><code>class Wrapper(object):
    def __init__(self,wrapped_class):
        self.wrapped_class = wrapped_class()

    def __getattr__(self,attr):
        return self.wrapped_class.__getattribute__(attr)

    def pre():
        print "pre"

    def post():
        print "post"
</code></pre>

<p>Which I can call like this...</p>

<pre><code>number = Wrapper(Simple)
number.one()
number.two("2")
</code></pre>

<p>Which can be used the same as above apart from changing the first line.</p>

<p>What I want to happen is when calling a function through the wrapper class the pre function in the wrapper class gets called then the desired function in the wrapped class then the post function. I want to be able to do this without changing the wrapped class and also without changing the way the functions are called, only changing the syntax of how the instance of the class is created. eg number = Simple() vs number = Wrapper(Simple)</p>
