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


Python zipfile.LargeZipFile方法代码示例

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

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

示例1: open

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def open(self, filename):
        try:
            if self.zipmode:
                if self.verbose:
                    print( "Opening Zip archive "+filename)
                self.handle = zipfile.ZipFile(filename, 'r')
            else:
                if self.verbose:
                    print( "Opening Rar archive "+filename)
                self.handle = rarfile.RarFile(filename, 'r')

        except (struct.error, zipfile.BadZipfile, zipfile.LargeZipFile, IOError) as e:
            if self.verbose:
                print( "Exception caught in ZipFile: %s" % (repr(e)))
            self.handle = None

        return self.handle 
开发者ID:cryptax,项目名称:droidlysis,代码行数:19,代码来源:droidziprar.py


示例2: _get_zipfile_filelist

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def _get_zipfile_filelist(filename):
    "Return the file list of a zip file. The list will be empty if an error occurred"
    zfile = None
    namelist = []
    try:
        try:
            zfile = zipfile.ZipFile(filename)
            namelist = zfile.namelist()
            zfile.close()
        except zipfile.BadZipfile as inst:
            logging.warning( _('ZIP file %s is corrupt (%s). Ignoring ZIP file.'), filename, inst )
            return []
        except zipfile.LargeZipFile as inst:
            logging.warning( _('ZIP file %s is bigger than 4GB (%s). Ignoring ZIP file.'), filename, inst )
            return []
    finally:
        if zfile: zfile.close()

    return namelist 
开发者ID:wxGlade,项目名称:wxGlade,代码行数:21,代码来源:plugins.py


示例3: metatiles_are_equal

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def metatiles_are_equal(tile_data_1, tile_data_2):
    """
    Return True if the two tiles are both zipped metatiles and contain the
    same set of files with the same contents. This ignores the timestamp of
    the individual files in the zip files, as well as their order or any
    other metadata.
    """

    try:
        buf_1 = StringIO.StringIO(tile_data_1)
        buf_2 = StringIO.StringIO(tile_data_2)

        with zipfile.ZipFile(buf_1, mode='r') as zip_1:
            with zipfile.ZipFile(buf_2, mode='r') as zip_2:
                return _metatile_contents_equal(zip_1, zip_2)

    except (StandardError, zipfile.BadZipFile, zipfile.LargeZipFile):
        # errors, such as files not being proper zip files, or missing
        # some attributes or contents that we expect, are treated as not
        # equal.
        pass

    return False 
开发者ID:tilezen,项目名称:tilequeue,代码行数:25,代码来源:metatile.py


示例4: _merge_file

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def _merge_file(self, byte_io: typing.IO[bytes]) -> None:
        """Read and merge host files.

        Args:
            byte_io: The BytesIO object of the completed download.
        """
        error_count = 0
        line_count = 0
        try:
            f = get_fileobj(byte_io)
        except (OSError, zipfile.BadZipFile, zipfile.LargeZipFile,
                LookupError) as e:
            message.error("adblock: Error while reading {}: {} - {}".format(
                byte_io.name, e.__class__.__name__, e))
            return

        for line in f:
            line_count += 1
            try:
                self._blocked_hosts |= self._read_hosts_line(line)
            except UnicodeDecodeError:
                logger.error("Failed to decode: {!r}".format(line))
                error_count += 1

        logger.debug("{}: read {} lines".format(byte_io.name, line_count))
        if error_count > 0:
            message.error("adblock: {} read errors for {}".format(
                error_count, byte_io.name)) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:30,代码来源:adblock.py


示例5: test_should_raise_if_zipfile_raised_LargeZipFile

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def test_should_raise_if_zipfile_raised_LargeZipFile(zipfile_mock, tmpfile):
    zipfile_mock.side_effect = zipfile.LargeZipFile()
    package = Package({}, {})
    with pytest.raises(exceptions.DataPackageException):
        package.save(tmpfile)


# Load from zip 
开发者ID:frictionlessdata,项目名称:datapackage-py,代码行数:10,代码来源:test_package.py


示例6: large_file_exception_test

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def large_file_exception_test(self, f, compression):
        with zipfile.ZipFile(f, "w", compression) as zipfp:
            self.assertRaises(zipfile.LargeZipFile,
                              zipfp.write, TESTFN, "another.name") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_zipfile.py


示例7: large_file_exception_test2

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def large_file_exception_test2(self, f, compression):
        with zipfile.ZipFile(f, "w", compression) as zipfp:
            self.assertRaises(zipfile.LargeZipFile,
                              zipfp.writestr, "another.name", self.data) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_zipfile.py


示例8: test_too_many_files_append

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def test_too_many_files_append(self):
        zipf = zipfile.ZipFile(TESTFN, mode="w", allowZip64=False)
        zipf.debug = 100
        numfiles = 9
        for i in range(numfiles):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=False)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=True)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        numfiles2 = 15
        for i in range(numfiles, numfiles2):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles2)
        zipf.close()

        zipf2 = zipfile.ZipFile(TESTFN, mode="r")
        self.assertEqual(len(zipf2.namelist()), numfiles2)
        for i in range(numfiles2):
            content = zipf2.read("foo%08d" % i)
            self.assertEqual(content, "%d" % (i**3 % 57))
        zipf2.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:test_zipfile.py


示例9: testMoreThan64kFilesAppend

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def testMoreThan64kFilesAppend(self):
        zipf = zipfile.ZipFile(TESTFN, mode="w", allowZip64=False)
        zipf.debug = 100
        numfiles = (1 << 16) - 1
        for i in range(numfiles):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=False)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=True)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        numfiles2 = (1 << 16) * 3//2
        for i in range(numfiles, numfiles2):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles2)
        zipf.close()

        zipf2 = zipfile.ZipFile(TESTFN, mode="r")
        self.assertEqual(len(zipf2.namelist()), numfiles2)
        for i in range(numfiles2):
            self.assertEqual(zipf2.read("foo%08d" % i), "%d" % (i**3 % 57))
        zipf2.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:36,代码来源:test_zipfile64.py


示例10: unzip

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def unzip(src, dst):
    """
    Unzip source into the destination directory
    args:
        src (str): The url to unzip
        dst (str): The absolute destination path
    """
    try:
        zfile = zipfile.ZipFile(src)
        zfile.extractall(dst)
    except (zipfile.BadZipfile, zipfile.LargeZipFile, RuntimeError) as exc:
        logging.warning('EXCEPTION {}'.format(exc))
        increase_fs(dst)
        unzip(src, dst) 
开发者ID:aixoss,项目名称:ansible-playbooks,代码行数:16,代码来源:aix_flrtvc.py


示例11: test_too_many_files_append

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def test_too_many_files_append(self):
        zipf = zipfile.ZipFile(TESTFN, "w", self.compression,
                               allowZip64=False)
        zipf.debug = 100
        numfiles = 9
        for i in range(numfiles):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
                               allowZip64=False)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
                               allowZip64=True)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        numfiles2 = 15
        for i in range(numfiles, numfiles2):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles2)
        zipf.close()

        zipf2 = zipfile.ZipFile(TESTFN, "r", self.compression)
        self.assertEqual(len(zipf2.namelist()), numfiles2)
        for i in range(numfiles2):
            content = zipf2.read("foo%08d" % i).decode('ascii')
            self.assertEqual(content, "%d" % (i**3 % 57))
        zipf2.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:test_zipfile.py


示例12: large_file_exception_test

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def large_file_exception_test(self, f, compression):
        with zipfile.ZipFile(f, "w", compression, allowZip64=False) as zipfp:
            self.assertRaises(zipfile.LargeZipFile,
                              zipfp.write, TESTFN, "another.name") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_zipfile.py


示例13: large_file_exception_test2

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def large_file_exception_test2(self, f, compression):
        with zipfile.ZipFile(f, "w", compression, allowZip64=False) as zipfp:
            self.assertRaises(zipfile.LargeZipFile,
                              zipfp.writestr, "another.name", self.data) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_zipfile.py


示例14: testMoreThan64kFilesAppend

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def testMoreThan64kFilesAppend(self):
        zipf = zipfile.ZipFile(TESTFN, mode="w", allowZip64=False)
        zipf.debug = 100
        numfiles = (1 << 16) - 1
        for i in range(numfiles):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=False)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        with self.assertRaises(zipfile.LargeZipFile):
            zipf.writestr("foo%08d" % numfiles, b'')
        self.assertEqual(len(zipf.namelist()), numfiles)
        zipf.close()

        zipf = zipfile.ZipFile(TESTFN, mode="a", allowZip64=True)
        zipf.debug = 100
        self.assertEqual(len(zipf.namelist()), numfiles)
        numfiles2 = (1 << 16) * 3//2
        for i in range(numfiles, numfiles2):
            zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
        self.assertEqual(len(zipf.namelist()), numfiles2)
        zipf.close()

        zipf2 = zipfile.ZipFile(TESTFN, mode="r")
        self.assertEqual(len(zipf2.namelist()), numfiles2)
        for i in range(numfiles2):
            content = zipf2.read("foo%08d" % i).decode('ascii')
            self.assertEqual(content, "%d" % (i**3 % 57))
        zipf2.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:37,代码来源:test_zipfile64.py


示例15: _load_zip

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import LargeZipFile [as 别名]
def _load_zip(path):
    try:
        z = ZipFile(path, 'r')
    except (BadZipfile, LargeZipFile):
        raise BadZipfile('%s: %s' % (path, sys.exc_info()[1]))
    else:
        return z 
开发者ID:Quantipy,项目名称:quantipy,代码行数:9,代码来源:test_excel.py



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