def _replace_by(module_function, package=__package__, warn=False):
 try:
  from importlib import import_module
 except ImportError:
  warnings.warn('could not import module importlib')
  return (lambda func: func)
 def decorate(func, module_function=module_function, warn=warn):
  try:
   (module, function) = module_function.split('.')
   if package:
    module = import_module(('.' + module), package=package)
   else:
    module = import_module(module)
   (func, oldfunc) = (getattr(module, function), func)
   globals()[('__old_' + func.__name__)] = oldfunc
  except Exception:
   if warn:
    warnings.warn(('failed to import %s' % module_function))
  return func
 return decorate

def _replace_by ( module_function , package = __package__ , warn = False ) : try : from importlib import import_module except ImportError : warnings . warn ( 'could not import module importlib' ) return ( lambda func : func ) def decorate ( func , module_function = module_function , warn = warn ) : try : ( module , function ) = module_function . split ( '.' ) if package : module = import_module ( ( '.' + module ) , package = package ) else : module = import_module ( module ) ( func , oldfunc ) = ( getattr ( module , function ) , func ) globals ( ) [ ( '__old_' + func . __name__ ) ] = oldfunc except Exception : if warn : warnings . warn ( ( 'failed to import %s' % module_function ) ) return func return decorate
try replace decorated function by module .