def addClassAdvisor(callback, depth=2):
 frame = sys._getframe(depth)
 (kind, module, caller_locals, caller_globals) = getFrameInfo(frame)
 previousMetaclass = caller_locals.get('__metaclass__')
 if __python3:
  defaultMetaclass = caller_globals.get('__metaclass__', type)
 else:
  defaultMetaclass = caller_globals.get('__metaclass__', ClassType)
 def advise(name, bases, cdict):
  if ('__metaclass__' in cdict):
   del cdict['__metaclass__']
  if (previousMetaclass is None):
   if bases:
    meta = determineMetaclass(bases)
   else:
    meta = defaultMetaclass
  elif isClassAdvisor(previousMetaclass):
   meta = previousMetaclass
  else:
   meta = determineMetaclass(bases, previousMetaclass)
  newClass = meta(name, bases, cdict)
  return callback(newClass)
 advise.previousMetaclass = previousMetaclass
 advise.callback = callback
 caller_locals['__metaclass__'] = advise

def addClassAdvisor ( callback , depth = 2 ) : frame = sys . _getframe ( depth ) ( kind , module , caller_locals , caller_globals ) = getFrameInfo ( frame ) previousMetaclass = caller_locals . get ( '__metaclass__' ) if __python3 : defaultMetaclass = caller_globals . get ( '__metaclass__' , type ) else : defaultMetaclass = caller_globals . get ( '__metaclass__' , ClassType ) def advise ( name , bases , cdict ) : if ( '__metaclass__' in cdict ) : del cdict [ '__metaclass__' ] if ( previousMetaclass is None ) : if bases : meta = determineMetaclass ( bases ) else : meta = defaultMetaclass elif isClassAdvisor ( previousMetaclass ) : meta = previousMetaclass else : meta = determineMetaclass ( bases , previousMetaclass ) newClass = meta ( name , bases , cdict ) return callback ( newClass ) advise . previousMetaclass = previousMetaclass advise . callback = callback caller_locals [ '__metaclass__' ] = advise
set up callback to be passed the containing class upon creation this function is designed to be called by an "advising" function executed in a class suite .