24
24
from . import conf
25
25
from astroquery import log
26
26
from astropy .coordinates import SkyCoord
27
+ from ...exceptions import LoginError
27
28
28
29
29
30
__all__ = ['XMMNewton' , 'XMMNewtonClass' ]
@@ -47,7 +48,7 @@ def __init__(self, tap_handler=None):
47
48
self ._rmf_ftp = str ("http://sasdev-xmm.esac.esa.int/pub/ccf/constituents/extras/responses/" )
48
49
49
50
def download_data (self , observation_id , * , filename = None , verbose = False ,
50
- ** kwargs ):
51
+ cache = True , ** kwargs ):
51
52
"""
52
53
Download data from XMM-Newton
53
54
@@ -110,10 +111,17 @@ def download_data(self, observation_id, *, filename=None, verbose=False,
110
111
if verbose :
111
112
log .info (link )
112
113
113
- response = self ._request ('GET' , link , save = False , cache = True )
114
+ # we can cache this HEAD request - the _download_file one will check
115
+ # the file size and will never cache
116
+ response = self ._request ('HEAD' , link , save = False , cache = cache )
114
117
115
118
# Get original extension
116
- _ , params = cgi .parse_header (response .headers ['Content-Disposition' ])
119
+ if 'Content-Type' in response .headers and 'text' not in response .headers ['Content-Type' ]:
120
+ _ , params = cgi .parse_header (response .headers ['Content-Disposition' ])
121
+ else :
122
+ error = "Data protected by proprietary rights. Please check your credentials"
123
+ raise LoginError (error )
124
+
117
125
r_filename = params ["filename" ]
118
126
suffixes = Path (r_filename ).suffixes
119
127
@@ -122,9 +130,7 @@ def download_data(self, observation_id, *, filename=None, verbose=False,
122
130
123
131
filename += "" .join (suffixes )
124
132
125
- log .info ("Copying file to {0}..." .format (filename ))
126
- with open (filename , 'wb' ) as f :
127
- f .write (response .content )
133
+ self ._download_file (link , filename , head_safe = True , cache = cache )
128
134
129
135
if verbose :
130
136
log .info ("Wrote {0} to {1}" .format (link , filename ))
0 commit comments