def find_current_module(depth=1, finddiff=False):
 frm = inspect.currentframe()
 for i in range(depth):
  frm = frm.f_back
  if (frm is None):
   return None
 if finddiff:
  currmod = inspect.getmodule(frm)
  if (finddiff is True):
   diffmods = [currmod]
  else:
   diffmods = []
   for fd in finddiff:
    if inspect.ismodule(fd):
     diffmods.append(fd)
    elif isinstance(fd, six.string_types):
     diffmods.append(__import__(fd))
    elif (fd is True):
     diffmods.append(currmod)
    else:
     raise ValueError(u'invalid entry in finddiff')
  while frm:
   frmb = frm.f_back
   modb = inspect.getmodule(frmb)
   if (modb not in diffmods):
    return modb
   frm = frmb
 else:
  return inspect.getmodule(frm)

def find_current_module ( depth = 1 , finddiff = False ) : frm = inspect . currentframe ( ) for i in range ( depth ) : frm = frm . f_back if ( frm is None ) : return None if finddiff : currmod = inspect . getmodule ( frm ) if ( finddiff is True ) : diffmods = [ currmod ] else : diffmods = [ ] for fd in finddiff : if inspect . ismodule ( fd ) : diffmods . append ( fd ) elif isinstance ( fd , six . string_types ) : diffmods . append ( __import__ ( fd ) ) elif ( fd is True ) : diffmods . append ( currmod ) else : raise ValueError ( u'invalid entry in finddiff' ) while frm : frmb = frm . f_back modb = inspect . getmodule ( frmb ) if ( modb not in diffmods ) : return modb frm = frmb else : return inspect . getmodule ( frm )
determines the module/package from which this function is called .