mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-102950: Implement PEP 706 – Filter for tarfile.extractall (GH-102953) (GH-103832)
See [Backporting & Forward Compatibility in PEP 706](https://peps.python.org/pep-0706/#backporting-forward-compatibility). - Backportb52ad18a76
- Backportc8c3956d90
- Remove the DeprecationWarning - Adjust docs - Remove new `__all__` entries
This commit is contained in:
parent
b3faf8ceec
commit
241f2e54a6
8 changed files with 1800 additions and 97 deletions
|
@ -32,6 +32,7 @@ except ImportError:
|
|||
from test import support
|
||||
from test.support import os_helper
|
||||
from test.support.os_helper import TESTFN, FakePath
|
||||
from test.support import warnings_helper
|
||||
|
||||
TESTFN2 = TESTFN + "2"
|
||||
TESTFN_SRC = TESTFN + "_SRC"
|
||||
|
@ -1630,12 +1631,14 @@ class TestArchives(BaseTest, unittest.TestCase):
|
|||
|
||||
### shutil.unpack_archive
|
||||
|
||||
def check_unpack_archive(self, format):
|
||||
self.check_unpack_archive_with_converter(format, lambda path: path)
|
||||
self.check_unpack_archive_with_converter(format, pathlib.Path)
|
||||
self.check_unpack_archive_with_converter(format, FakePath)
|
||||
def check_unpack_archive(self, format, **kwargs):
|
||||
self.check_unpack_archive_with_converter(
|
||||
format, lambda path: path, **kwargs)
|
||||
self.check_unpack_archive_with_converter(
|
||||
format, pathlib.Path, **kwargs)
|
||||
self.check_unpack_archive_with_converter(format, FakePath, **kwargs)
|
||||
|
||||
def check_unpack_archive_with_converter(self, format, converter):
|
||||
def check_unpack_archive_with_converter(self, format, converter, **kwargs):
|
||||
root_dir, base_dir = self._create_files()
|
||||
expected = rlistdir(root_dir)
|
||||
expected.remove('outer')
|
||||
|
@ -1645,36 +1648,47 @@ class TestArchives(BaseTest, unittest.TestCase):
|
|||
|
||||
# let's try to unpack it now
|
||||
tmpdir2 = self.mkdtemp()
|
||||
unpack_archive(converter(filename), converter(tmpdir2))
|
||||
unpack_archive(converter(filename), converter(tmpdir2), **kwargs)
|
||||
self.assertEqual(rlistdir(tmpdir2), expected)
|
||||
|
||||
# and again, this time with the format specified
|
||||
tmpdir3 = self.mkdtemp()
|
||||
unpack_archive(converter(filename), converter(tmpdir3), format=format)
|
||||
unpack_archive(converter(filename), converter(tmpdir3), format=format,
|
||||
**kwargs)
|
||||
self.assertEqual(rlistdir(tmpdir3), expected)
|
||||
|
||||
self.assertRaises(shutil.ReadError, unpack_archive, converter(TESTFN))
|
||||
self.assertRaises(ValueError, unpack_archive, converter(TESTFN), format='xxx')
|
||||
with self.assertRaises(shutil.ReadError):
|
||||
unpack_archive(converter(TESTFN), **kwargs)
|
||||
with self.assertRaises(ValueError):
|
||||
unpack_archive(converter(TESTFN), format='xxx', **kwargs)
|
||||
|
||||
def check_unpack_tarball(self, format):
|
||||
self.check_unpack_archive(format, filter='fully_trusted')
|
||||
self.check_unpack_archive(format, filter='data')
|
||||
with warnings_helper.check_no_warnings(self):
|
||||
self.check_unpack_archive(format)
|
||||
|
||||
def test_unpack_archive_tar(self):
|
||||
self.check_unpack_archive('tar')
|
||||
self.check_unpack_tarball('tar')
|
||||
|
||||
@support.requires_zlib()
|
||||
def test_unpack_archive_gztar(self):
|
||||
self.check_unpack_archive('gztar')
|
||||
self.check_unpack_tarball('gztar')
|
||||
|
||||
@support.requires_bz2()
|
||||
def test_unpack_archive_bztar(self):
|
||||
self.check_unpack_archive('bztar')
|
||||
self.check_unpack_tarball('bztar')
|
||||
|
||||
@support.requires_lzma()
|
||||
@unittest.skipIf(AIX and not _maxdataOK(), "AIX MAXDATA must be 0x20000000 or larger")
|
||||
def test_unpack_archive_xztar(self):
|
||||
self.check_unpack_archive('xztar')
|
||||
self.check_unpack_tarball('xztar')
|
||||
|
||||
@support.requires_zlib()
|
||||
def test_unpack_archive_zip(self):
|
||||
self.check_unpack_archive('zip')
|
||||
with self.assertRaises(TypeError):
|
||||
self.check_unpack_archive('zip', filter='data')
|
||||
|
||||
def test_unpack_registry(self):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue