def method_decorator(decorator):
 def _dec(func):
  def _wrapper(self, *args, **kwargs):
   def bound_func(*args2, **kwargs2):
    return func(self, *args2, **kwargs2)
   return decorator(bound_func)(*args, **kwargs)
  return wraps(func)(_wrapper)
 update_wrapper(_dec, decorator)
 _dec.__name__ = ('method_decorator(%s)' % decorator.__name__)
 return _dec

def method_decorator ( decorator ) : def _dec ( func ) : def _wrapper ( self , * args , ** kwargs ) : def bound_func ( * args2 , ** kwargs2 ) : return func ( self , * args2 , ** kwargs2 ) return decorator ( bound_func ) ( * args , ** kwargs ) return wraps ( func ) ( _wrapper ) update_wrapper ( _dec , decorator ) _dec . __name__ = ( 'method_decorator(%s)' % decorator . __name__ ) return _dec
converts a function decorator into a method decorator .