def register_decorators_on_module_funcs(modules, decorators):
'''?decorator?????module??????
?????__nodeco__???False???????????
???????????
eg:
def func():
pass
func.__nodeco__ = True
'''
if not isinstance(modules, (list, tuple)):
modules = [modules]
if not isinstance(decorators, (list, tuple)):
decorators = [decorators]
for m in modules:
for funcname, func in vars(m).iteritems():
if (isinstance(func, types.FunctionType)
and not funcname.startswith('_')
and func.__module__ == m.__name__):
if getattr(func, '__nodeco__', False):
continue
for deco in decorators:
if settings.DEBUG:
log.debug('register %s on %s.%s'
% (deco.__name__, m.__name__, funcname))
func = deco(func)
vars(m)[funcname] = func
评论列表
文章目录