當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。