Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ def _unpack_tarfile(filename, extract_dir, *, filter=None):
_UNPACK_FORMATS = {
'tar': (['.tar'], _unpack_tarfile, [], "uncompressed tar file"),
'zip': (['.zip'], _unpack_zipfile, [], "ZIP file"),
'whl': (['.whl'], _unpack_zipfile, [], "Wheel file"),
}

if _ZLIB_SUPPORTED:
Expand Down
9 changes: 8 additions & 1 deletion Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2115,12 +2115,13 @@ def check_unpack_archive(self, format, **kwargs):
self.check_unpack_archive_with_converter(format, FakePath, **kwargs)

def check_unpack_archive_with_converter(self, format, converter, **kwargs):
make_format = kwargs.pop("make_format", format)
root_dir, base_dir = self._create_files()
expected = rlistdir(root_dir)
expected.remove('outer')

base_name = os.path.join(self.mkdtemp(), 'archive')
filename = make_archive(base_name, format, root_dir, base_dir)
filename = make_archive(base_name, make_format, root_dir, base_dir)

# let's try to unpack it now
tmpdir2 = self.mkdtemp()
Expand Down Expand Up @@ -2168,6 +2169,12 @@ def test_unpack_archive_zip(self):
with self.assertRaises(TypeError):
self.check_unpack_archive('zip', filter='data')

@support.requires_zlib()
def test_unpack_archive_whl(self):
self.check_unpack_archive('whl', make_format='zip')
with self.assertRaises(TypeError):
self.check_unpack_archive('whl', filter='data', make_format='zip')

def test_unpack_registry(self):

formats = get_unpack_formats()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`shutil` now can unpack wheel packages using the ``whl`` format.
Loading