8000 [3.9] gh-102950: Implement PEP 706 – Filter for tarfile.extractall (GH-102953) by encukou · Pull Request #104382 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] gh-102950: Implement PEP 706 – Filter for tarfile.extractall (GH-102953) #104382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove the DeprecationWarning
  • Loading branch information
encukou committed May 11, 2023
commit 2948293fea14bc83bee66d251752d88beed2d889
5 changes: 0 additions & 5 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,11 +2200,6 @@ def _get_filter_function(self, filter):
if filter is None:
filter = self.extraction_filter
if filter is None:
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)
return fully_trusted_filter
if isinstance(filter, str):
raise TypeError(
Expand Down
10000
3 changes: 1 addition & 2 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,7 @@ def check_unpack_archive_with_converter(self, format, converter, **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_warnings(
('The default', RuntimeWarning)):
with warnings_helper.check_no_warnings(self):
self.check_unpack_archive(format)

def test_unpack_archive_tar(self):
Expand Down
15 changes: 5 additions & 10 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import io
from hashlib import sha256
from contextlib import contextmanager, ExitStack
from contextlib import contextmanager
from random import Random
import pathlib
import shutil
Expand Down Expand Up @@ -2921,11 +2921,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)
Expand Down Expand Up @@ -3559,12 +3555,11 @@ 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"""
def test_default_filter_warns_not(self):
"""Ensure the default filter does not warn (like in 3.12)"""
with ArchiveMaker() as arc:
arc.add('foo')
with warnings_helper.ch 4CB2 eck_warnings(
('Python 3.14', DeprecationWarning)):
with warnings_helper.check_no_warnings(self):
with self.check_context(arc.open(), None):
self.expect_file('foo')

Expand Down
0