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