Skip to content
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

Explicitly pass filter to TarFile.extractall on Python >=3.12 #458

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions pooch/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"""
Post-processing hooks
"""

import abc
import os
import bz2
import gzip
import lzma
import shutil
import sys
from zipfile import ZipFile
from tarfile import TarFile

Expand Down Expand Up @@ -253,13 +255,14 @@ def _extract_file(self, fname, extract_dir):
This method receives an argument for the archive to extract and the
destination path.
"""
filter_kwarg = {} if sys.version_info < (3, 12) else {"filter": "data"}
with TarFile.open(fname, "r") as tar_file:
if self.members is None:
get_logger().info(
"Untarring contents of '%s' to '%s'", fname, extract_dir
)
# Unpack all files from the archive into our new folder
tar_file.extractall(path=extract_dir)
tar_file.extractall(path=extract_dir, **filter_kwarg)
else:
for member in self.members:
get_logger().info(
Expand All @@ -281,7 +284,9 @@ def _extract_file(self, fname, extract_dir):
)
]
# Extract the data file from within the archive
tar_file.extractall(members=subdir_members, path=extract_dir)
tar_file.extractall(
members=subdir_members, path=extract_dir, **filter_kwarg
)


class Decompress: # pylint: disable=too-few-public-methods
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = [
progress = ["tqdm>=4.41.0,<5.0.0"]
sftp = ["paramiko>=2.7.0"]
xxhash = ["xxhash>=1.4.3"]
test = ["pytest-httpserver", "pytest-localftpserver"]

[project.urls]
"Documentation" = "https://www.fatiando.org/pooch"
Expand Down
Loading