def _enhook(klass, name):
 if hasattr(klass, ORIG(klass, name)):
  return
 def newfunc(*args, **kw):
  for preMethod in getattr(klass, PRE(klass, name)):
   preMethod(*args, **kw)
  try:
   return getattr(klass, ORIG(klass, name))(*args, **kw)
  finally:
   for postMethod in getattr(klass, POST(klass, name)):
    postMethod(*args, **kw)
 try:
  newfunc.func_name = name
 except TypeError:
  pass
 oldfunc = getattr(klass, name).im_func
 setattr(klass, ORIG(klass, name), oldfunc)
 setattr(klass, PRE(klass, name), [])
 setattr(klass, POST(klass, name), [])
 setattr(klass, name, newfunc)

def _enhook ( klass , name ) : if hasattr ( klass , ORIG ( klass , name ) ) : return def newfunc ( * args , ** kw ) : for preMethod in getattr ( klass , PRE ( klass , name ) ) : preMethod ( * args , ** kw ) try : return getattr ( klass , ORIG ( klass , name ) ) ( * args , ** kw ) finally : for postMethod in getattr ( klass , POST ( klass , name ) ) : postMethod ( * args , ** kw ) try : newfunc . func_name = name except TypeError : pass oldfunc = getattr ( klass , name ) . im_func setattr ( klass , ORIG ( klass , name ) , oldfunc ) setattr ( klass , PRE ( klass , name ) , [ ] ) setattr ( klass , POST ( klass , name ) , [ ] ) setattr ( klass , name , newfunc )
causes a certain method name to be hooked on a class .