1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
3
3
import warnings
4
- from six import BytesIO
4
+ from six import StringIO , BytesIO
5
5
from astropy .io .fits .column import _AsciiColumnFormat
6
6
from astropy .table import Table
7
7
from astropy .io import fits
@@ -62,8 +62,7 @@ def query_mission_list(self, cache=True, get_query_payload=False):
62
62
url = conf .server ,
63
63
cache = cache
64
64
)
65
- data = BytesIO (response .content )
66
- data_str = data .read ().decode ('utf-8' )
65
+ data_str = response .text
67
66
data_str = data_str .replace ('Table xxx does not seem to exist!\n \n \n \n Available tables:\n ' , '' )
68
67
table = Table .read (data_str , format = 'ascii.fixed_width_two_line' ,
69
68
delimiter = '+' , header_start = 1 , position_line = 2 ,
@@ -175,7 +174,7 @@ def query_region_async(self, position, mission, radius,
175
174
# Submit the request
176
175
return self .query_async (request_payload , cache = cache )
177
176
178
- def _old_w3query_fallback (self , content ):
177
+ def _old_w3query_fallback (self , content : bytes ):
179
178
# old w3query (such as that used in ISDC) return very strange fits, with all ints
180
179
181
180
f = fits .open (BytesIO (content ))
@@ -193,21 +192,21 @@ def _old_w3query_fallback(self, content):
193
192
194
193
return Table .read (I )
195
194
196
- def _fallback (self , content ):
195
+ def _fallback (self , text : str ):
197
196
"""
198
197
Blank columns which have to be converted to float or in fail so
199
198
lets fix that by replacing with -1's
200
199
"""
201
200
202
- data = BytesIO ( content )
201
+ data = StringIO ( text )
203
202
header = fits .getheader (data , 1 ) # Get header for column info
204
203
colstart = [y for x , y in header .items () if "TBCOL" in x ]
205
204
collens = [int (float (y [1 :]))
206
205
for x , y in header .items () if "TFORM" in x ]
207
206
208
207
new_table = []
209
208
210
- old_table = content . decode () .split ("END" )[- 1 ].strip ()
209
+ old_table = text .split ("END" )[- 1 ].strip ()
211
210
for line in old_table .split ("\n " ):
212
211
newline = []
213
212
for n , tup in enumerate (zip (colstart , collens ), start = 1 ):
@@ -220,7 +219,7 @@ def _fallback(self, content):
220
219
newline [- 1 ] = "-1" .rjust (clen ) + " "
221
220
new_table .append ("" .join (newline ))
222
221
223
- data = BytesIO ( content .replace (old_table , "\n " .join (new_table )))
222
+ data = StringIO ( text .replace (old_table , "\n " .join (new_table )))
224
223
return Table .read (data , hdu = 1 )
225
224
226
225
def _parse_result (self , response , verbose = False ):
@@ -246,7 +245,7 @@ def _parse_result(self, response, verbose=False):
246
245
return table
247
246
except ValueError :
248
247
try :
249
- return self ._fallback (response .content )
248
+ return self ._fallback (response .text )
250
249
except Exception as e :
251
250
return self ._old_w3query_fallback (response .content )
252
251
@@ -299,9 +298,8 @@ def _args_to_payload(self, **kwargs):
299
298
"""
300
299
# User-facing parameters are lower case, while parameters as passed to the HEASARC service are capitalized according to the HEASARC requirements.
301
300
# The necessary transformations are done in this function.
302
-
303
- # Define the basic query for this object
304
301
302
+ # Define the basic query for this object
305
303
mission = kwargs .pop ('mission' )
306
304
307
305
request_payload = dict (
0 commit comments