def mod_import(module):
 if (not module):
  return None
 if isinstance(module, types.ModuleType):
  mod = module
 else:
  try:
   mod = __import__(module, fromlist=['None'])
  except ImportError as ex:
   if (str(ex) != 'Import by filename is not supported.'):
    raise
   if (not os.path.isabs(module)):
    module = os.path.abspath(module)
   (path, filename) = module.rsplit(os.path.sep, 1)
   modname = re.sub('\\.py$', '', filename)
   try:
    result = imp.find_module(modname, [path])
   except ImportError:
    logger.log_trace(("Could not find module '%s' (%s.py) at path '%s'" % (modname, modname, path)))
    return
   try:
    mod = imp.load_module(modname, *result)
   except ImportError:
    logger.log_trace(("Could not find or import module %s at path '%s'" % (modname, path)))
    mod = None
   result[0].close()
 return mod

def mod_import ( module ) : if ( not module ) : return None if isinstance ( module , types . ModuleType ) : mod = module else : try : mod = __import__ ( module , fromlist = [ 'None' ] ) except ImportError as ex : if ( str ( ex ) != 'Import by filename is not supported.' ) : raise if ( not os . path . isabs ( module ) ) : module = os . path . abspath ( module ) ( path , filename ) = module . rsplit ( os . path . sep , 1 ) modname = re . sub ( '\\.py$' , '' , filename ) try : result = imp . find_module ( modname , [ path ] ) except ImportError : logger . log_trace ( ( "Could not find module '%s' (%s.py) at path '%s'" % ( modname , modname , path ) ) ) return try : mod = imp . load_module ( modname , * result ) except ImportError : logger . log_trace ( ( "Could not find or import module %s at path '%s'" % ( modname , path ) ) ) mod = None result [ 0 ] . close ( ) return mod
a generic python module loader .