title: Python: wrap all functions in a library
body: <p>We use a library provided by another internal team.  (Shaky analogy starts now)</p>
  
  <pre><code>from externalTeam import dataCreator
  datacreator.createPizza()
  datacreator.createBurger()
  datacreator.createHotDog()
  </code></pre>
  
  <p>Recently we found a single method of theirs was taking over a minute to execute in certain situations.  To debug this, I had to go into our code and add timeouts around every call of this method.  </p>
  
  <pre><code>import time
  from externalTeam import dataCreator
  start = time.clock()
  datacreator.createPizza()
  stop = time.clock()
  print "It took %s seconds to perform createPizza" % (str(stop-start))
  </code></pre>
  
  <p>In hindsight, that's because we're calling createPizza all over the place, and we don't control createPizza itself (the analogy is starting to break down a little here).  I'd rather just call createPizza in one place, and be able to add a timer around that.  My first thought to accomplish this would be to create a wrap all their methods in my own wrapper class.  That's the opposite of DRY though, and anytime they add another method I'd have to update our library to wrap that as well:</p>
  
  <pre><code>import time
  from externalTeam import dataCreator
  def createPizza(self):
      start = time.clock()
      datacreator.createPizza()
      stop = time.clock()
      print "It took %s seconds to perform createPizza" % (str(stop-start))
  
  def createBurger(self):
      start = time.clock()
      datacreator.createPizza()
      stop = time.clock()
      print "It took %s seconds to perform createBurger" % (str(stop-start))
  
  def createHotDog(self):
      start = time.clock()
      datacreator.createPizza()
      stop = time.clock()
      print "It took %s seconds to perform createHotDog" % (str(stop-start))    
  </code></pre>
  
  <p>What I want is a way to always execute a few lines of code around every function that's being called from dataCreator.  There must be some way to do that through an intermediate class whose methods can be dynamically defined - or rather left undefined, right?</p>