|
13 | 13 | import binascii
|
14 | 14 | import shutil
|
15 | 15 |
|
16 |
| -import tarfile |
| 16 | +import tarfile as esatar |
17 | 17 | import zipfile
|
18 | 18 | from astropy import log
|
19 | 19 | from astropy.coordinates import SkyCoord
|
|
27 | 27 | TARGET_RESOLVERS = ['ALL', 'SIMBAD', 'NED', 'VIZIER']
|
28 | 28 |
|
29 | 29 |
|
| 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 | + |
30 | 36 | # Subclass AuthSession to customize requests
|
31 | 37 | class ESAAuthSession(AuthSession):
|
32 | 38 | """
|
@@ -332,11 +338,11 @@ def extract_file(file_path, output_dir=None):
|
332 | 338 | """
|
333 | 339 | if not output_dir:
|
334 | 340 | 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: |
337 | 343 | return extract_from_tar(tar_ref, file_path, output_dir)
|
338 | 344 | 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: |
340 | 346 | return extract_from_tar(tar, file_path, output_dir)
|
341 | 347 | elif zipfile.is_zipfile(file_path):
|
342 | 348 | return extract_from_zip(file_path, output_dir)
|
|
0 commit comments