当前位置: 首页>>代码示例>>Python>>正文


Python zipimport.ZipImportError方法代码示例

本文整理汇总了Python中zipimport.ZipImportError方法的典型用法代码示例。如果您正苦于以下问题:Python zipimport.ZipImportError方法的具体用法?Python zipimport.ZipImportError怎么用?Python zipimport.ZipImportError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipimport的用法示例。


在下文中一共展示了zipimport.ZipImportError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _precache_zipimporters

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def _precache_zipimporters(path=None):
    pic = sys.path_importer_cache

    # When measured, despite having the same complexity (O(n)),
    # converting to tuples and then caching the conversion to sets
    # and the set difference is faster than converting to sets
    # and then only caching the set difference.

    req_paths = tuple(path or sys.path)
    cached_paths = tuple(pic)
    new_paths = _cached_set_diff(req_paths, cached_paths)
    for entry_path in new_paths:
        try:
            pic[entry_path] = zipimport.zipimporter(entry_path)
        except zipimport.ZipImportError:
            continue
    return pic 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:spec.py

示例2: get_zip_bytes

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def get_zip_bytes(filename):
    """Get data from `filename` if it is a zip file path.

    Returns the bytestring data read from the zip file, or None if no zip file
    could be found or `filename` isn't in it.  The data returned will be
    an empty string if the file is empty.

    """
    markers = ['.zip'+os.sep, '.egg'+os.sep, '.pex'+os.sep]
    for marker in markers:
        if marker in filename:
            parts = filename.split(marker)
            try:
                zi = zipimport.zipimporter(parts[0]+marker[:-1])
            except zipimport.ZipImportError:
                continue
            try:
                data = zi.get_data(parts[1])
            except IOError:
                continue
            return data
    return None 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:python.py

示例3: assertZipFailure

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def assertZipFailure(self, filename):
        self.assertRaises(zipimport.ZipImportError,
                          zipimport.zipimporter, filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_zipimport.py

示例4: _testBogusZipFile

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def _testBogusZipFile(self):
        test_support.unlink(TESTMOD)
        fp = open(TESTMOD, 'w+')
        fp.write(struct.pack('=I', 0x06054B50))
        fp.write('a' * 18)
        fp.close()
        z = zipimport.zipimporter(TESTMOD)

        try:
            self.assertRaises(TypeError, z.find_module, None)
            self.assertRaises(TypeError, z.load_module, None)
            self.assertRaises(TypeError, z.is_package, None)
            self.assertRaises(TypeError, z.get_code, None)
            self.assertRaises(TypeError, z.get_data, None)
            self.assertRaises(TypeError, z.get_source, None)

            error = zipimport.ZipImportError
            self.assertEqual(z.find_module('abc'), None)

            self.assertRaises(error, z.load_module, 'abc')
            self.assertRaises(error, z.get_code, 'abc')
            self.assertRaises(IOError, z.get_data, 'abc')
            self.assertRaises(error, z.get_source, 'abc')
            self.assertRaises(error, z.is_package, 'abc')
        finally:
            zipimport._zip_directory_cache.clear() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_zipimport.py

示例5: testFileUnreadable

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def testFileUnreadable(self):
        support.unlink(TESTMOD)
        fd = os.open(TESTMOD, os.O_CREAT, 000)
        try:
            os.close(fd)

            with self.assertRaises(zipimport.ZipImportError) as cm:
                zipimport.zipimporter(TESTMOD)
        finally:
            # If we leave "the read-only bit" set on Windows, nothing can
            # delete TESTMOD, and later tests suffer bogus failures.
            os.chmod(TESTMOD, 0o666)
            support.unlink(TESTMOD) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_zipimport.py

示例6: _testBogusZipFile

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def _testBogusZipFile(self):
        support.unlink(TESTMOD)
        fp = open(TESTMOD, 'w+')
        fp.write(struct.pack('=I', 0x06054B50))
        fp.write('a' * 18)
        fp.close()
        z = zipimport.zipimporter(TESTMOD)

        try:
            self.assertRaises(TypeError, z.find_module, None)
            self.assertRaises(TypeError, z.load_module, None)
            self.assertRaises(TypeError, z.is_package, None)
            self.assertRaises(TypeError, z.get_code, None)
            self.assertRaises(TypeError, z.get_data, None)
            self.assertRaises(TypeError, z.get_source, None)

            error = zipimport.ZipImportError
            self.assertEqual(z.find_module('abc'), None)

            self.assertRaises(error, z.load_module, 'abc')
            self.assertRaises(error, z.get_code, 'abc')
            self.assertRaises(OSError, z.get_data, 'abc')
            self.assertRaises(error, z.get_source, 'abc')
            self.assertRaises(error, z.is_package, 'abc')
        finally:
            zipimport._zip_directory_cache.clear() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:test_zipimport.py

示例7: __init__

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def __init__(self, path):
        try:
            self.__zip = zipimport.zipimporter(path)
        except zipimport.ZipImportError, e:
            raise OwnerError('%s: %s' % (str(e), path)) 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:7,代码来源:iu.py

示例8: getmod

# 需要导入模块: import zipimport [as 别名]
# 或者: from zipimport import ZipImportError [as 别名]
def getmod(self, nm, newmod=imp.new_module):
        # We cannot simply use zipimport.load_module here
        # because it both loads (= create module object)
        # and imports (= execute bytecode). Instead, our
        # getmod() functions are supposed to only load the modules.
        # Note that imp.load_module() does the right thing, instead.
        debug('zipimport try: %s within %s' % (nm, self.__zip))
        try:
            bytecode = self.__zip.get_code(nm)
            mod = newmod(nm)
            mod.__file__ = bytecode.co_filename
            if self.__zip.is_package(nm):
                mod.__path__ = [_os_path_join(self.path, nm)]
                subimporter = PathImportDirector(mod.__path__)
                mod.__importsub__ = subimporter.getmod
            if self.path.endswith(".egg"):
                # Fixup some additional special attribute so that
                # pkg_resources works correctly.
                # TODO: couldn't we fix these attributes always,
                # for all zip files?
                mod.__file__ = _os_path_join(
                    _os_path_join(self.path, nm), "__init__.py")
                mod.__loader__ = self.__zip
            mod.__co__ = bytecode
            return mod
        except zipimport.ZipImportError:
            debug('zipimport not found %s' % nm)
            return None


# Define order where to look for Python modules first.
# 1. PYZOwner: look in executable created by PyInstaller.
#    (_pyi_bootstrap.py will insert it (archive.PYZOwner) in front later.)
# 2. ZipOwner: zip files (.egg files)
# 3. DirOwner: file system
# 4. Owner:    module not found 
开发者ID:Lithium876,项目名称:ConTroll_Remote_Access_Trojan,代码行数:38,代码来源:iu.py


注:本文中的zipimport.ZipImportError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。