diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipfile.py | 11 | ||||
-rw-r--r-- | Lib/zipfile.py | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 99d599e..f812188 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -9,6 +9,7 @@ import subprocess import sys import time import unittest +import unittest.mock as mock import zipfile @@ -1766,6 +1767,16 @@ class OtherTests(unittest.TestCase): fp.seek(0, os.SEEK_SET) self.assertEqual(fp.tell(), 0) + @requires_bz2 + def test_decompress_without_3rd_party_library(self): + data = b'PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + zip_file = io.BytesIO(data) + with zipfile.ZipFile(zip_file, 'w', compression=zipfile.ZIP_BZIP2) as zf: + zf.writestr('a.txt', b'a') + with mock.patch('zipfile.bz2', None): + with zipfile.ZipFile(zip_file) as zf: + self.assertRaises(RuntimeError, zf.extract, 'a.txt') + def tearDown(self): unlink(TESTFN) unlink(TESTFN2) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index c2c5b6a..97a5ebf 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -703,6 +703,7 @@ def _get_compressor(compress_type, compresslevel=None): def _get_decompressor(compress_type): + _check_compression(compress_type) if compress_type == ZIP_STORED: return None elif compress_type == ZIP_DEFLATED: |