Skip to content

Commit 10526fc

Browse files
committed
Workaround for tarfile imports
1 parent 0f2774c commit 10526fc

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

astroquery/esa/jwst/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import gzip
1414
import os
1515
import shutil
16-
import tarfile
16+
import tarfile as esatar
1717
import zipfile
1818
from datetime import datetime, timezone
1919
from urllib.parse import urlencode
@@ -41,8 +41,8 @@
4141

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

4747

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

10451045
def __extract_file(self, output_file_full_path, output_dir, files):
1046-
if tarfile.is_tarfile(output_file_full_path):
1047-
with tarfile.open(output_file_full_path) as tar_ref:
1046+
if esatar.is_tarfile(output_file_full_path):
1047+
with esatar.open(output_file_full_path) as tar_ref:
10481048
tar_ref.extractall(path=output_dir)
10491049
elif zipfile.is_zipfile(output_file_full_path):
10501050
with zipfile.ZipFile(output_file_full_path, 'r') as zip_ref:

astroquery/esa/xmm_newton/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
import shutil
1313
from pathlib import Path
14-
import tarfile
14+
import tarfile as esatar
1515
import os
1616
import configparser
1717
from email.message import Message
@@ -31,8 +31,8 @@
3131

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

3737

3838
class XMMNewtonClass(BaseQuery):
@@ -412,7 +412,7 @@ def get_epic_spectra(self, filename, source_number, *,
412412
if path != "" and os.path.exists(path):
413413
_path = path
414414
try:
415-
with tarfile.open(filename, "r") as tar:
415+
with esatar.open(filename, "r") as tar:
416416
ret = {}
417417
for member in tar.getmembers():
418418
paths = os.path.split(member.name)
@@ -558,7 +558,7 @@ def get_epic_images(self, filename, band=[], instrument=[],
558558
log.warning("Invalid instrument %s" % inst)
559559
instrument.remove(inst)
560560
try:
561-
with tarfile.open(filename, "r") as tar:
561+
with esatar.open(filename, "r") as tar:
562562
ret = {}
563563
for member in tar.getmembers():
564564
paths = os.path.split(member.name)
@@ -734,7 +734,7 @@ def get_epic_lightcurve(self, filename, source_number, *,
734734
_path = path
735735

736736
try:
737-
with tarfile.open(filename, "r") as tar:
737+
with esatar.open(filename, "r") as tar:
738738
ret = {}
739739
for member in tar.getmembers():
740740
paths = os.path.split(member.name)

0 commit comments

Comments
 (0)