Skip to content

Commit

Permalink
Workaround for tarfile imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Sep 25, 2023
1 parent 0f2774c commit 10526fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions astroquery/esa/jwst/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import gzip
import os
import shutil
import tarfile
import tarfile as esatar
import zipfile
from datetime import datetime, timezone
from urllib.parse import urlencode
Expand Down Expand Up @@ -41,8 +41,8 @@

# 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(tarfile, "fully_trusted_filter"):
tarfile.TarFile.extraction_filter = staticmethod(tarfile.fully_trusted_filter)
if hasattr(esatar, "fully_trusted_filter"):
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)


class JwstClass(BaseQuery):
Expand Down Expand Up @@ -1043,8 +1043,8 @@ def __check_file_number(self, output_dir, output_file_name,
files.append(os.path.join(r, file))

def __extract_file(self, output_file_full_path, output_dir, files):
if tarfile.is_tarfile(output_file_full_path):
with tarfile.open(output_file_full_path) as tar_ref:
if esatar.is_tarfile(output_file_full_path):
with esatar.open(output_file_full_path) as tar_ref:
tar_ref.extractall(path=output_dir)
elif zipfile.is_zipfile(output_file_full_path):
with zipfile.ZipFile(output_file_full_path, 'r') as zip_ref:
Expand Down
12 changes: 6 additions & 6 deletions astroquery/esa/xmm_newton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
import shutil
from pathlib import Path
import tarfile
import tarfile as esatar
import os
import configparser
from email.message import Message
Expand All @@ -31,8 +31,8 @@

# 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(tarfile, "fully_trusted_filter"):
tarfile.TarFile.extraction_filter = staticmethod(tarfile.fully_trusted_filter)
if hasattr(esatar, "fully_trusted_filter"):
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)


class XMMNewtonClass(BaseQuery):
Expand Down Expand Up @@ -412,7 +412,7 @@ def get_epic_spectra(self, filename, source_number, *,
if path != "" and os.path.exists(path):
_path = path
try:
with tarfile.open(filename, "r") as tar:
with esatar.open(filename, "r") as tar:
ret = {}
for member in tar.getmembers():
paths = os.path.split(member.name)
Expand Down Expand Up @@ -558,7 +558,7 @@ def get_epic_images(self, filename, band=[], instrument=[],
log.warning("Invalid instrument %s" % inst)
instrument.remove(inst)
try:
with tarfile.open(filename, "r") as tar:
with esatar.open(filename, "r") as tar:
ret = {}
for member in tar.getmembers():
paths = os.path.split(member.name)
Expand Down Expand Up @@ -734,7 +734,7 @@ def get_epic_lightcurve(self, filename, source_number, *,
_path = path

try:
with tarfile.open(filename, "r") as tar:
with esatar.open(filename, "r") as tar:
ret = {}
for member in tar.getmembers():
paths = os.path.split(member.name)
Expand Down

0 comments on commit 10526fc

Please sign in to comment.