Python pkgutil 模块,ImpLoader() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用pkgutil.ImpLoader()

项目:figura    作者:shx2    | 项目源码 | 文件源码
def _pl_find_on_path(self, fullname, path=None):
        subname = fullname.split(".")[-1]
        if self.path is None and subname != fullname:
            return None

        path = os.path.realpath(self.path)
        for (fp, ispkg) in FLS:
            for loader in self._loader_handlers:
                composed_path = fp % (('%s' + SEP + '%s') % (path, subname), loader.suffix)
                if os.path.isdir(composed_path):
                    raise IOError("Invalid: Directory name ends in recognized suffix")
                if os.path.isfile(composed_path):
                    return PolyLoader(fullname, composed_path, ispkg)

        # Fall back onto Python's own methods.
        try:
            file, filename, etc = imp.find_module(subname, [path])
        except ImportError as e:
            return None
        return pkgutil.ImpLoader(fullname, file, filename, etc)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def find_module(self, fullname, path=None):
        # this duplicates most of ImpImporter.find_module
        subname = fullname.split(".")[-1]
        if subname != fullname and self.path is None:
            return None
        if self.path is None:
            path = None
        else:
            path = [os.path.realpath(self.path)]
        try:
            file, filename, etc = imp.find_module(subname, path)
        except ImportError:
            return None
        if file and etc[2] == imp.PY_SOURCE:
            outfilename = maybe_2to3(filename, modname=fullname)
            if outfilename != filename:
                file.close()
                filename = outfilename
                file = open(filename, 'rb')
        return ImpLoader(fullname, file, filename, etc)


# setup the hook
项目:polyloader    作者:elfsternberg    | 项目源码 | 文件源码
def _pl_find_on_path(self, fullname, path=None):
        subname = fullname.split(".")[-1]
        if self.path is None and subname != fullname:
            return None

        path = os.path.realpath(self.path)
        for (fp, ispkg) in FLS:
            for loader in self._loader_handlers:
                composed_path = fp % (('%s' + SEP + '%s') % (path, subname), loader.suffix)
                if os.path.isdir(composed_path):
                    raise IOError("Invalid: Directory name ends in recognized suffix")
                if os.path.isfile(composed_path):
                    return PolyLoader(fullname, composed_path, ispkg)

        # Fall back onto Python's own methods.
        try:
            file, filename, etc = imp.find_module(subname, [path])
        except ImportError as e:
            return None
        return pkgutil.ImpLoader(fullname, file, filename, etc)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_loader_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpLoader("", "", "", "")
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_loader_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpLoader("", "", "", "")
项目:insights-core    作者:RedHatInsights    | 项目源码 | 文件源码
def find_module(self, fullname, paths=None):
        """ Returns a FavaLoader for fava files and a pkgutil.ImpLoader
            for standard python files. The ImpLoader is a PEP-302 wrapper
            for python's regular import machinery.
        """
        name = fullname.split(".")[-1]
        filename = os.path.join(self.path, name + self.ext)
        if os.path.exists(filename):
            return FavaLoader(filename)
        return pkgutil.ImpLoader(fullname, *imp.find_module(name, [self.path]))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_loader_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpLoader("", "", "", "")