title: Implementing the decorator pattern in Python
body: <p>I want to implement the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="noreferrer">decorator pattern</a> in Python, and I wondered if there is a way to write a decorator that just implements the function it wants to modify, without writing boiler-plate for all the functions that are just forwarded to the decorated object. Like so:</p>
  
  <pre><code>class foo(object):
      def f1(self):
          print "original f1"
      def f2(self):
          print "original f2"
  
  class foo_decorator(object):
      def __init__(self, decoratee):
          self._decoratee = decoratee
      def f1(self):
          print "decorated f1"
          self._decoratee.f1()
      def f2(self):              # I would like to leave that part out
          self._decoratee.f2()
  </code></pre>
  
  <p>I would like to have calls to <code>foo_decorator.f2</code> forwarded to <code>decoratee.f2</code> automatically. Is there a way to write a generic method that forwards all unimplemented function-calls to <code>decoratee</code>?</p>