diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index bcb1098f43d5a3..94bb3285962138 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -86,6 +86,22 @@ New Modules Improved Modules ================ +tarfile +------- + +* The default value of parameter *filter* of + :meth:`tarfile.TarFile.extract` and :meth:`tarfile.TarFile.extractall` + is now ``'data'`` to filter extracted tar archives and reject files or + modify their metadata by default. + The previous default was deprecated since Python 3.12. + +shutil +------ + +* The default value of parameter *filter* of :func:`shutil.unpack_archive` + is now ``'data'`` to filter extracted tar archives and reject files or + modify their metadata by default. + The previous default was deprecated since Python 3.12. Optimizations ============= diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 5fc6183ffcf93c..ae7ce428cf7d9d 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2249,13 +2249,7 @@ def _get_filter_function(self, filter): if filter is None: filter = self.extraction_filter if filter is None: - import warnings - warnings.warn( - 'Python 3.14 will, by default, filter extracted tar ' - + 'archives and reject files or modify their metadata. ' - + 'Use the filter argument to control this behavior.', - DeprecationWarning, stacklevel=3) - return fully_trusted_filter + return data_filter if isinstance(filter, str): raise TypeError( 'String names are not supported for ' diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index c9c1097963a885..7405846e5af692 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -736,30 +736,6 @@ def test_extract_directory(self): finally: os_helper.rmtree(DIR) - def test_deprecation_if_no_filter_passed_to_extractall(self): - DIR = pathlib.Path(TEMPDIR) / "extractall" - with ( - os_helper.temp_dir(DIR), - tarfile.open(tarname, encoding="iso8859-1") as tar - ): - directories = [t for t in tar if t.isdir()] - with self.assertWarnsRegex(DeprecationWarning, "Use the filter argument") as cm: - tar.extractall(DIR, directories) - # check that the stacklevel of the deprecation warning is correct: - self.assertEqual(cm.filename, __file__) - - def test_deprecation_if_no_filter_passed_to_extract(self): - dirtype = "ustar/dirtype" - DIR = pathlib.Path(TEMPDIR) / "extractall" - with ( - os_helper.temp_dir(DIR), - tarfile.open(tarname, encoding="iso8859-1") as tar - ): - tarinfo = tar.getmember(dirtype) - with self.assertWarnsRegex(DeprecationWarning, "Use the filter argument") as cm: - tar.extract(tarinfo, path=DIR) - # check that the stacklevel of the deprecation warning is correct: - self.assertEqual(cm.filename, __file__) def test_extractall_pathlike_name(self): DIR = pathlib.Path(TEMPDIR) / "extractall" @@ -3177,11 +3153,7 @@ def setUpClass(cls): tar = tarfile.open(tarname, mode='r', encoding="iso8859-1") cls.control_dir = pathlib.Path(TEMPDIR) / "extractall_ctrl" tar.errorlevel = 0 - with ExitStack() as cm: - if cls.extraction_filter is None: - cm.enter_context(warnings.catch_warnings( - action="ignore", category=DeprecationWarning)) - tar.extractall(cls.control_dir, filter=cls.extraction_filter) + tar.extractall(cls.control_dir, filter=cls.extraction_filter) tar.close() cls.control_paths = set( p.relative_to(cls.control_dir) @@ -4009,14 +3981,6 @@ def test_data_filter(self): self.assertIs(filtered.name, tarinfo.name) self.assertIs(filtered.type, tarinfo.type) - def test_default_filter_warns(self): - """Ensure the default filter warns""" - with ArchiveMaker() as arc: - arc.add('foo') - with warnings_helper.check_warnings( - ('Python 3.14', DeprecationWarning)): - with self.check_context(arc.open(), None): - self.expect_file('foo') def test_change_default_filter_on_instance(self): tar = tarfile.TarFile(tarname, 'r')