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

Skip to content

gh-102950: Implement PEP 706 – Filter for tarfile.extractall #102953

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 16 commits into from
Apr 24, 2023
Merged
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
Fix the tests to match the PEP update
  • Loading branch information
encukou committed Apr 19, 2023
commit 3796fdfc7c4168c47d655a74234ee0e99a5a8b68
28 changes: 14 additions & 14 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3804,22 +3804,19 @@ def __exit__(self, *exc_info):
def test_errorlevel(self):
def extracterror_filter(tarinfo, path):
raise tarfile.ExtractError('failed with ExtractError')
def tarerror_filter(tarinfo, path):
raise tarfile.ExtractError('failed with base TarError')
def filtererror_filter(tarinfo, path):
raise tarfile.FilterError('failed with FilterError')
def oserror_filter(tarinfo, path):
raise OSError('failed with OSError')
def tarerror_filter(tarinfo, path):
raise tarfile.TarError('failed with base TarError')
def valueerror_filter(tarinfo, path):
raise ValueError('failed with ValueError')

with ArchiveMaker() as arc:
arc.add('file')

# If errorlevel is 0, errors are ignored when using TarFile.extract().

with self.check_context(arc.open(errorlevel=0), tarerror_filter):
self.expect_file('file')
# If errorlevel is 0, errors affected by errorlevel are ignored

with self.check_context(arc.open(errorlevel=0), extracterror_filter):
self.expect_file('file')
Expand All @@ -3830,14 +3827,14 @@ def valueerror_filter(tarinfo, path):
with self.check_context(arc.open(errorlevel=0), oserror_filter):
self.expect_file('file')

with self.check_context(arc.open(errorlevel=0), tarerror_filter):
self.expect_exception(tarfile.TarError)

with self.check_context(arc.open(errorlevel=0), valueerror_filter):
self.expect_exception(ValueError)

# If 1, all fatal errors are raised

with self.check_context(arc.open(errorlevel=1), tarerror_filter):
self.expect_file('file')

with self.check_context(arc.open(errorlevel=1), extracterror_filter):
self.expect_file('file')

Expand All @@ -3847,14 +3844,14 @@ def valueerror_filter(tarinfo, path):
with self.check_context(arc.open(errorlevel=1), oserror_filter):
self.expect_exception(OSError)

with self.check_context(arc.open(errorlevel=1), tarerror_filter):
self.expect_exception(tarfile.TarError)

with self.check_context(arc.open(errorlevel=1), valueerror_filter):
self.expect_exception(ValueError)

# If 2, all non-fatal errors are raised as well.

with self.check_context(arc.open(errorlevel=2), tarerror_filter):
self.expect_exception(tarfile.TarError)

with self.check_context(arc.open(errorlevel=2), extracterror_filter):
self.expect_exception(tarfile.ExtractError)

Expand All @@ -3864,12 +3861,15 @@ def valueerror_filter(tarinfo, path):
with self.check_context(arc.open(errorlevel=2), oserror_filter):
self.expect_exception(OSError)

with self.check_context(arc.open(errorlevel=2), tarerror_filter):
self.expect_exception(tarfile.TarError)

with self.check_context(arc.open(errorlevel=2), valueerror_filter):
self.expect_exception(ValueError)

# We only handle TarError & OSError specially.
# We only handle ExtractionError, FilterError & OSError specially.

with self.check_context(arc.open(errorlevel='boo!'), tarerror_filter):
with self.check_context(arc.open(errorlevel='boo!'), filtererror_filter):
self.expect_exception(TypeError) # errorlevel is not int


Expand Down
0