sys.path_importer_cache.get

Here are the examples of the python api sys.path_importer_cache.get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: PyClassLessons Source File: resources.py
def finder_for_path(path):
    """
    Return a resource finder for a path, which should represent a container.

    :param path: The path.
    :return: A :class:`ResourceFinder` instance for the path.
    """
    result = None
    # calls any path hooks, gets importer into cache
    pkgutil.get_importer(path)
    loader = sys.path_importer_cache.get(path)
    finder = _finder_registry.get(type(loader))
    if finder:
        module = _dummy_module
        module.__file__ = os.path.join(path, '')
        module.__loader__ = loader
        result = finder(module)
    return result

Example 2

Project: signedimp Source File: bootstrap.py
Function: get_importer
    def _get_importer(self,path,cached=True):
        """Get the importer for the given sys.path item.

        This emulates the standard handling of sys.path_hooks, with the added
        bonus of returning a DefaultImporter instance if no hook is found.
        """
        importer = None
        if cached:
            importer = sys.path_importer_cache.get(path,None)
        if importer is None:
            for importer_class in sys.path_hooks:
                try:
                    importer = importer_class(path)
                except ImportError:
                    pass
                else:
                    break
            else:
                importer = _get_default_importer(path)
            sys.path_importer_cache[path] = importer
        return importer