Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMP: fix tarfile deprecation for esasky, follow-up to PR2838 #3082

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
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
Loading