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

Skip to content

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

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 8 commits into from
May 17, 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
Downgrade to Python 3.6
  • Loading branch information
encukou committed May 16, 2023
commit c737a47f8dd8fcb9b140430780273de4fcb48c56
3 changes: 2 additions & 1 deletion Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,8 @@ def unpack_archive(filename, extract_dir=None, format=None, *, filter=None):
raise ReadError("Unknown archive format '{0}'".format(filename))

func = _UNPACK_FORMATS[format][1]
kwargs = dict(_UNPACK_FORMATS[format][2]) | filter_kwargs
kwargs = dict(_UNPACK_FORMATS[format][2])
kwargs.update(filter_kwargs)
func(filename, extract_dir, **kwargs)


Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from test import support
from test.support import TESTFN, FakePath
from test.support import warnings_helper

TESTFN2 = TESTFN + "2"
TESTFN_SRC = TESTFN + "_SRC"
Expand Down Expand Up @@ -1495,7 +1494,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(
with support.check_warnings(
('The default', RuntimeWarning)):
self.check_unpack_archive(format)

Expand Down
12 changes: 5 additions & 7 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from test import support
from test.support import script_helper
from test.support import warnings_helper

# Check for our compression modules.
try:
Expand Down Expand Up @@ -2739,8 +2738,7 @@ def setUpClass(cls):
tar.errorlevel = 0
with ExitStack() as cm:
if cls.extraction_filter is None:
cm.enter_context(warnings.catch_warnings(
action="ignore", category=DeprecationWarning))
cm.enter_context(warnings.catch_warnings())
tar.extractall(cls.control_dir, filter=cls.extraction_filter)
tar.close()
cls.control_paths = set(
Expand Down Expand Up @@ -2870,8 +2868,8 @@ def test_list(self):
for attr_names in ({'mtime'}, {'mode'}, {'uid'}, {'gid'},
{'uname'}, {'gname'},
{'uid', 'uname'}, {'gid', 'gname'}):
with (self.subTest(attr_names=attr_names),
tarfile.open(tarname, encoding="iso8859-1") as tar):
with self.subTest(attr_names=attr_names), \
tarfile.open(tarname, encoding="iso8859-1") as tar:
tio_prev = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
with support.swap_attr(sys, 'stdout', tio_prev):
tar.list()
Expand Down Expand Up @@ -3062,7 +3060,7 @@ def expect_file(self, name, type=None, symlink_to=None, mode=None):
if type is None and isinstance(name, str) and name.endswith('/'):
type = tarfile.DIRTYPE
if symlink_to is not None:
got = (self.destdir / name).readlink()
got = pathlib.Path(os.readlink(self.destdir / name))
expected = pathlib.Path(symlink_to)
# The symlink might be the same (textually) as what we expect,
# but some systems change the link to an equivalent path, so
Expand Down Expand Up @@ -3379,7 +3377,7 @@ def test_default_filter_warns(self):
"""Ensure the default filter warns"""
with ArchiveMaker() as arc:
arc.add('foo')
with warnings_helper.check_warnings(
with support.check_warnings(
('Python 3.14', DeprecationWarning)):
with self.check_context(arc.open(), None):
self.expect_file('foo')
Expand Down
0