Skip to content
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
21 changes: 8 additions & 13 deletions python/grass/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@ def extract_tar(name, directory, tmpdir):
extract_dir = os.path.join(tmpdir, "extract_dir")
Path(extract_dir).mkdir()

# Extraction filters were added in Python 3.12,
# and backported to 3.8.17, 3.9.17, 3.10.12, and 3.11.4
# See
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
# and https://peps.python.org/pep-0706/
# In Python 3.12, using `filter=None` triggers a DepreciationWarning,
# and in Python 3.14, `filter='data'` will be the default
if hasattr(tarfile, "data_filter"):
tar.extractall(path=extract_dir, filter="data")
else:
# Remove this when no longer needed
debug(_("Extracting may be unsafe; consider updating Python"))
tar.extractall(path=extract_dir)
# The 'data' extraction filter was added in Python 3.12 and backported
# to 3.11.4 (PEP 706). Refuse to extract without it rather
# than extracting unsafely.
if not hasattr(tarfile, "data_filter"):
raise DownloadError(
_("Extracting may be unsafe; upgrade Python to 3.11.4 or newer")
)
tar.extractall(path=extract_dir, filter="data")

files = os.listdir(extract_dir)
_move_extracted_files(
Expand Down
19 changes: 6 additions & 13 deletions scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,19 +1835,12 @@ def extract_tar(name, directory, tmpdir):
extract_dir = os.path.join(tmpdir, "extract_dir")
Path(extract_dir).mkdir()

# Extraction filters were added in Python 3.12,
# and backported to 3.8.17, 3.9.17, 3.10.12, and 3.11.4
# See
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
# and https://peps.python.org/pep-0706/
# In Python 3.12, using `filter=None` triggers a DepreciationWarning,
# and in Python 3.14, `filter='data'` will be the default
if hasattr(tarfile, "data_filter"):
tar.extractall(path=extract_dir, filter="data")
else:
# Remove this when no longer needed
gs.warning(_("Extracting may be unsafe; consider updating Python"))
tar.extractall(path=extract_dir)
# The 'data' extraction filter was added in Python 3.12 and backported
# to 3.11.4 (PEP 706). Refuse to extract without it rather
# than extracting unsafely.
if not hasattr(tarfile, "data_filter"):
gs.fatal(_("Extracting may be unsafe; upgrade Python to 3.11.4 or newer"))
tar.extractall(path=extract_dir, filter="data")

files = os.listdir(extract_dir)
move_extracted_files(extract_dir=extract_dir, target_dir=directory, files=files)
Expand Down
18 changes: 6 additions & 12 deletions scripts/r.unpack/r.unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,12 @@ def main():
)

# extract data
# Extraction filters were added in Python 3.12,
# and backported to 3.8.17, 3.9.17, 3.10.12, and 3.11.4
# See https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
# and https://peps.python.org/pep-0706/
# In Python 3.12, using `filter=None` triggers a DepreciationWarning,
# and in Python 3.14, `filter='data'` will be the default
if hasattr(tarfile, "data_filter"):
tar.extractall(filter="data")
else:
# Remove this when no longer needed
grass.warning(_("Extracting may be unsafe; consider updating Python"))
tar.extractall()
# The 'data' extraction filter was added in Python 3.12 and backported to
# 3.11.4 (PEP 706). Refuse to extract without it rather than
# extracting unsafely.
if not hasattr(tarfile, "data_filter"):
grass.fatal(_("Extracting may be unsafe; upgrade Python to 3.11.4 or newer"))
tar.extractall(filter="data")
tar.close()
os.chdir(data_names[0])

Expand Down
18 changes: 6 additions & 12 deletions scripts/v.unpack/v.unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,12 @@ def main():
shutil.rmtree(new_dir, True)

# extract data
# Extraction filters were added in Python 3.12,
# and backported to 3.8.17, 3.9.17, 3.10.12, and 3.11.4
# See https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
# and https://peps.python.org/pep-0706/
# In Python 3.12, using `filter=None` triggers a DepreciationWarning,
# and in Python 3.14, `filter='data'` will be the default
if hasattr(tarfile, "data_filter"):
tar.extractall(filter="data")
else:
# Remove this when no longer needed
grass.warning(_("Extracting may be unsafe; consider updating Python"))
tar.extractall()
# The 'data' extraction filter was added in Python 3.12 and backported to
# 3.11.4 (PEP 706). Refuse to extract without it rather than
# extracting unsafely.
if not hasattr(tarfile, "data_filter"):
grass.fatal(_("Extracting may be unsafe; upgrade Python to 3.11.4 or newer"))
tar.extractall(filter="data")
tar.close()
if Path(data_name, "coor").exists():
pass
Expand Down
Loading