find the module on sys.path or 'path' based on sys.path_hooks and
        sys.path_importer_cache.
971992
def find_spec(cls, fullname, path=None, target=None):
        """"""
        if path is None:
            path = sys.path
        spec = cls._get_spec(fullname, path, target)
        if spec is None:
            return None
        elif spec.loader is None:
            namespace_path = spec.submodule_search_locations
            if namespace_path:
                # We found at least one namespace path.  Return a
                #  spec which can create the namespace package.
                spec.origin = 'namespace'
                spec.submodule_search_locations = _NamespacePath(fullname, namespace_path, cls._get_spec)
                return spec
            else:
                return None
        else:
            return spec
1113462
def _locate_settings(settings=''):
    ""

    import imp
    import sys
    sys.path.append(os.getcwd())
    settings = settings or os.getenv('DJANGO_SETTINGS_MODULE')
    if settings:
        parts = settings.split('.')
        f = imp.find_module(parts[0])[1]
        args = [f] + parts[1:]
        path = os.path.join(*args)
        path = path + '.py'
        if os.path.exists(path):
            return path
1049131
def _init():
    
    global finder

    if finder is None:
        finder = ModuleFinder()

    if finder not in sys.meta_path:
        sys.meta_path.insert(0, finder)
1221306
def load_modules_from_path(path):
    
    # Check and fix the path
    if path[-1:] != '/':
        path += '/'

    # Get a list of files in the directory, if the directory exists
    if not os.path.exists(path):
        raise OSError("Directory does not exist: %s" % path)

    # Add path to the system path
    sys.path.append(path)
    # Load all the files in path
    for f in os.listdir(path):
        # Ignore anything that isn't a .py file
        if len(f) > 3 and f[-3:] == '.py':
            modname = f[:-3]
            # Import the module
            __import__(modname, globals(), locals(), ['*'])
1269845
def _find_module(mod_name):
    
    path = None
    for part in mod_name.split('.'):
        if path is not None:
            path = [path]
        file, path, description = imp.find_module(part, path)
        if file is not None:
            file.close()
    return path, description
2777
def lookup(self, module_name):
        
        for search_path in self._paths:
            module_path = os.path.join(search_path, module_name)
            new_module_name, module_file = self._lookup(module_path, module_name)
            if module_file:
                return new_module_name, module_file
        return None, None
47514
def find_modules(module_path):
    
    if module_path.is_file():
        if module_path.suffix == '.py':
            yield module_path
    elif module_path.is_dir():
        pyfiles = glob.glob('{}/**/*.py'.format(module_path), recursive=True)
        yield from (Path(pyfile) for pyfile in pyfiles)
230202
def load_path_with_default(self, path, default_constructor):
        '''
        
        '''
        try:
            imported_obj = self.load_path(path)
        except (ImportError, ConfigurationError):
            imported_obj = default_constructor(path)
        else:
            # Ugly but seemingly expedient way to check a module was an
            # namespace type module
            if (isinstance(imported_obj, ModuleType) and
                    imported_obj.__spec__.origin == 'namespace'):
                imported_obj = default_constructor(path)
        return imported_obj
374157
def cache_py2_modules():
    
    if len(sys.py2_modules) != 0:
        return
    assert not detect_hooks()
    import urllib
    sys.py2_modules['urllib'] = urllib

    import email
    sys.py2_modules['email'] = email

    import pickle
    sys.py2_modules['pickle'] = pickle
349533
def identify_modules(*args, **kwargs):
    
    if len(args) == 1:
        path_template = "%(file)s"
        error_template = "Module '%(mod)s' not found (%(error)s)"
    else:
        path_template = "%(mod)s: %(file)s"
        error_template = "%(mod)s: not found (%(error)s)"

    for modulename in args:
        try:
            filepath = identify_filepath(modulename, **kwargs)
        except ModuleNotFound:
            exc = sys.exc_info()[1]
            sys.stderr.write(error_template % {
                'mod': modulename,
                'error': str(exc),
            })
            sys.stderr.write('\n')
        else:
            print(path_template % {
                'mod': modulename,
                'file': filepath
            })
310587
def find_third_party_modules ():
    """"""
    parent = os.path.dirname(os.path.dirname(__file__))
    third_party = os.path.join(parent, "third_party")
    if os.path.isdir(third_party):
        sys.path.append(os.path.join(third_party, "dnspython"))
659596
def get_function_by_path(dotted_function_module_path):
    
    # Separate the module path from the function name.
    module_path, function_name = tuple(dotted_function_module_path.rsplit('.', 1))

    module = import_module(module_path)
    return getattr(module, function_name)
390825
def module_path():
    

    if we_are_frozen():
        return os.path.dirname(
                unicode(sys.executable, sys.getfilesystemencoding()))

    return os.path.dirname(unicode(__file__, sys.getfilesystemencoding()))
850197
def load_module(module_name, module_path):
    """"""
    if sys.version_info >= (3,0):
        import pyximport
        pyximport.install()
        sys.path.append(module_path)
        return __import__(module_name)
    else:
        import imp
        module_info = imp.find_module(module_name, [module_path])
        return imp.load_module(module_name, *module_info)
1160693
def GetPythonLibraryDirectoryPath():
  """"""
  path = sysconfig.get_python_lib(True)
  _, _, path = path.rpartition(sysconfig.PREFIX)

  if path.startswith(os.sep):
    path = path[1:]

  return path
660224
def find_spec(self, fullname, path, target=None):
        ''''''
        if not path:
            path = [os.getcwd()]
        if "." in fullname:
            name = fullname.split(".")[-1]
        else:
            name = fullname
        for entry in path:
            if os.path.isdir(os.path.join(entry, name)):
                # this module has child modules
                filename = os.path.join(entry, name, "__init__.py")
                submodule_locations = [os.path.join(entry, name)]
            else:
                filename = os.path.join(entry, name + ".py")
                submodule_locations = None
            if not os.path.exists(filename):
                continue

            return spec_from_file_location(fullname, filename,
                                           loader=MyLoader(filename),
                                           submodule_search_locations=submodule_locations)
        return None
846277
def find_module(cls, fullname, path=None):
        
        spec = cls.find_spec(fullname, path)
        if spec is None:
            return None
        elif spec.loader is None and spec.submodule_search_locations:
            # Here we need to create a namespace loader to handle namespaces since python2 doesn't...
            return NamespaceLoader2(spec.name, spec.submodule_search_locations)
        else:
            return spec.loader