Skip to content

Commit 77a7631

Browse files
committed
COMP: fix tarfile deprecation for esasky, follow-up to PR2838
1 parent dcf0405 commit 77a7631

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

astroquery/esasky/core.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
import os
5-
import tarfile
5+
import tarfile as esatar
66
import sys
77
import re
88
import warnings
@@ -27,6 +27,12 @@
2727
from astropy.coordinates.name_resolve import sesame_database
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
@async_to_sync
3137
class ESASkyClass(BaseQuery):
3238

@@ -1526,7 +1532,7 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
15261532
if file_name == "":
15271533
file_name = self._extract_file_name_from_url(product_url)
15281534
if file_name.lower().endswith(self.__TAR_STRING):
1529-
with tarfile.open(fileobj=BytesIO(response.content)) as tar:
1535+
with esatar.open(fileobj=BytesIO(response.content)) as tar:
15301536
for member in tar.getmembers():
15311537
tar.extract(member, directory_path)
15321538
maps.append(self._open_fits(Path(directory_path, member.name), verbose=verbose))
@@ -1574,7 +1580,7 @@ def _get_herschel_map(self, product_url, directory_path, cache, verbose=False):
15741580
stream=True, headers=self._get_header())
15751581
response.raise_for_status()
15761582

1577-
with tarfile.open(fileobj=BytesIO(response.content)) as tar:
1583+
with esatar.open(fileobj=BytesIO(response.content)) as tar:
15781584
for member in tar.getmembers():
15791585
member_name = member.name.lower()
15801586
if 'hspire' in member_name or 'hpacs' in member_name:
@@ -1592,7 +1598,7 @@ def _get_herschel_spectra(self, product_url, directory_path, cache, verbose=Fals
15921598

15931599
response.raise_for_status()
15941600

1595-
with tarfile.open(fileobj=BytesIO(response.content)) as tar:
1601+
with esatar.open(fileobj=BytesIO(response.content)) as tar:
15961602
for member in tar.getmembers():
15971603
member_name = member.name.lower()
15981604
if ('hspire' in member_name or 'hpacs' in member_name

0 commit comments

Comments
 (0)