Python zipfile.LargeZipFile() Examples
The following are 30
code examples of zipfile.LargeZipFile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
zipfile
, or try the search function
.
Example #1
Source File: metatile.py From tilequeue with MIT License | 6 votes |
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
Example #2
Source File: plugins.py From wxGlade with MIT License | 6 votes |
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
Example #3
Source File: adblock.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
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))
Example #4
Source File: test_zipfile.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: test_zipfile64.py From ironpython3 with Apache License 2.0 | 5 votes |
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()
Example #6
Source File: test_zipfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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")
Example #7
Source File: test_zipfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: test_zipfile.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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()
Example #9
Source File: test_zipfile.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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")
Example #10
Source File: test_zipfile.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: test_zipfile64.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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()
Example #12
Source File: test_zipfile.py From medicare-demo with Apache License 2.0 | 5 votes |
def largeFileExceptionTest(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.write, TESTFN, "another"+os.extsep+"name") zipfp.close()
Example #13
Source File: test_zipfile.py From medicare-demo with Apache License 2.0 | 5 votes |
def largeFileExceptionTest2(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.writestr, "another"+os.extsep+"name", self.data) zipfp.close()
Example #14
Source File: test_zipfile.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def largeFileExceptionTest(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.write, TESTFN, "another"+os.extsep+"name") zipfp.close()
Example #15
Source File: test_zipfile.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def largeFileExceptionTest2(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.writestr, "another"+os.extsep+"name", self.data) zipfp.close()
Example #16
Source File: utils.py From truegaze with Apache License 2.0 | 5 votes |
def open_file_as_zip(filename): """ Tries to open the provided file as a zipfile :param filename: file to open :return: zipfile.ZipFile """ try: return zipfile.ZipFile(filename, 'r') except (zipfile.BadZipfile, FileNotFoundError, zipfile.LargeZipFile): return None
Example #17
Source File: test_zipfile.py From android_universal with MIT License | 5 votes |
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()
Example #18
Source File: test_zipfile.py From android_universal with MIT License | 5 votes |
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")
Example #19
Source File: test_zipfile.py From android_universal with MIT License | 5 votes |
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)
Example #20
Source File: test_zipfile.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def largeFileExceptionTest(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.write, TESTFN, "another"+os.extsep+"name") zipfp.close()
Example #21
Source File: test_zipfile.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def largeFileExceptionTest2(self, f, compression): zipfp = zipfile.ZipFile(f, "w", compression) self.assertRaises(zipfile.LargeZipFile, zipfp.writestr, "another"+os.extsep+"name", self.data) zipfp.close()
Example #22
Source File: test_zipfile.py From oss-ftp with MIT License | 5 votes |
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)
Example #23
Source File: droidziprar.py From droidlysis with MIT License | 5 votes |
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
Example #24
Source File: test_package.py From datapackage-py with MIT License | 5 votes |
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
Example #25
Source File: test_zipfile.py From ironpython2 with Apache License 2.0 | 5 votes |
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")
Example #26
Source File: test_zipfile.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: test_zipfile.py From ironpython2 with Apache License 2.0 | 5 votes |
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()
Example #28
Source File: test_zipfile64.py From ironpython2 with Apache License 2.0 | 5 votes |
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()
Example #29
Source File: test_zipfile.py From BinderFilter with MIT License | 5 votes |
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")
Example #30
Source File: test_zipfile.py From BinderFilter with MIT License | 5 votes |
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)