Skip to content

Commit

Permalink
Merge pull request #3082 from bsipocz/esasky_tarfile
Browse files Browse the repository at this point in the history
COMP: fix tarfile deprecation for esasky, follow-up to PR2838
  • Loading branch information
bsipocz authored Aug 9, 2024
2 parents dcf0405 + 77a7631 commit 25fc665
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions astroquery/esasky/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import os
import tarfile
import tarfile as esatar
import sys
import re
import warnings
Expand All @@ -27,6 +27,12 @@
from astropy.coordinates.name_resolve import sesame_database


# We do trust the ESA tar files, this is to avoid the new to Python 3.12 deprecation warning
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
if hasattr(esatar, "fully_trusted_filter"):
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)


@async_to_sync
class ESASkyClass(BaseQuery):

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

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

response.raise_for_status()

with tarfile.open(fileobj=BytesIO(response.content)) as tar:
with esatar.open(fileobj=BytesIO(response.content)) as tar:
for member in tar.getmembers():
member_name = member.name.lower()
if ('hspire' in member_name or 'hpacs' in member_name
Expand Down

0 comments on commit 25fc665

Please sign in to comment.