Skip to content

Commit 98945db

Browse files
committed
MAINT: patching tarfile as we trust ESA files, and need to avoid deprecations
1 parent 571e133 commit 98945db

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

astroquery/esa/utils/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import binascii
1414
import shutil
1515

16-
import tarfile
16+
import tarfile as esatar
1717
import zipfile
1818
from astropy import log
1919
from astropy.coordinates import SkyCoord
@@ -27,6 +27,12 @@
2727
TARGET_RESOLVERS = ['ALL', 'SIMBAD', 'NED', 'VIZIER']
2828

2929

30+
# We do trust the ESA tar files, this is to avoid the new to Python 3.12 deprecation warning
31+
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
32+
if hasattr(esatar, "fully_trusted_filter"):
33+
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)
34+
35+
3036
# Subclass AuthSession to customize requests
3137
class ESAAuthSession(AuthSession):
3238
"""
@@ -332,11 +338,11 @@ def extract_file(file_path, output_dir=None):
332338
"""
333339
if not output_dir:
334340
output_dir = os.path.abspath(file_path)
335-
if tarfile.is_tarfile(file_path):
336-
with tarfile.open(file_path, "r") as tar_ref:
341+
if esatar.is_tarfile(file_path):
342+
with esatar.open(file_path, "r") as tar_ref:
337343
return extract_from_tar(tar_ref, file_path, output_dir)
338344
elif is_gz_file(file_path):
339-
with tarfile.open(file_path, "r:gz") as tar:
345+
with esatar.open(file_path, "r:gz") as tar:
340346
return extract_from_tar(tar, file_path, output_dir)
341347
elif zipfile.is_zipfile(file_path):
342348
return extract_from_zip(file_path, output_dir)

0 commit comments

Comments
 (0)