Skip to content

Commit d547642

Browse files
committed
Simplify function calls for query parsing.
1 parent 634ef4e commit d547642

File tree

1 file changed

+20
-44
lines changed

1 file changed

+20
-44
lines changed

astroquery/jplhorizons/core.py

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,26 +1098,39 @@ def vectors_async(self, get_query_payload=False,
10981098

10991099
# ---------------------------------- parser functions
11001100

1101-
def _parse_horizons(self, src):
1101+
def _parse_result(self, response, verbose=None):
11021102
"""
1103-
Routine for parsing data from JPL Horizons
1103+
Parse query result to a `~astropy.table.Table` object.
11041104
11051105
11061106
Parameters
11071107
----------
11081108
1109-
src : list
1110-
raw response from server
1109+
response : `~requests.Response`
1110+
Response from server.
11111111
11121112
11131113
Returns
11141114
-------
11151115
1116-
data : `astropy.Table`
1116+
data : `~astropy.table.Table`
11171117
11181118
"""
11191119

1120-
self.raw_response = src
1120+
self.last_response = response
1121+
try:
1122+
response.raise_for_status()
1123+
except HTTPError:
1124+
# don't cache any HTTP errored queries (especially when the API is down!)
1125+
try:
1126+
self._last_query.remove_cache_file(self.cache_location)
1127+
except OSError:
1128+
# this is allowed: if `cache` was set to False, this
1129+
# won't be needed
1130+
pass
1131+
raise
1132+
1133+
self.raw_response = response.text
11211134

11221135
# return raw response, if desired
11231136
if self.return_raw:
@@ -1126,7 +1139,7 @@ def _parse_horizons(self, src):
11261139
return self.raw_response
11271140

11281141
# split response by line break
1129-
src = src.split('\n')
1142+
src = response.text.split('\n')
11301143

11311144
data_start_idx = 0
11321145
data_end_idx = 0
@@ -1315,43 +1328,6 @@ def _parse_horizons(self, src):
13151328

13161329
return data
13171330

1318-
def _parse_result(self, response, verbose=None):
1319-
"""
1320-
Routine for managing parser calls;
1321-
1322-
This routine decides based on `self.query_type` which parser
1323-
has to be used.
1324-
1325-
1326-
Parameters
1327-
----------
1328-
1329-
response : string
1330-
raw response from server
1331-
1332-
1333-
Returns
1334-
-------
1335-
1336-
data : `astropy.Table`
1337-
1338-
"""
1339-
1340-
self.last_response = response
1341-
try:
1342-
response.raise_for_status()
1343-
except HTTPError:
1344-
# don't cache any HTTP errored queries (especially when the API is down!)
1345-
try:
1346-
self._last_query.remove_cache_file(self.cache_location)
1347-
except OSError:
1348-
# this is allowed: if `cache` was set to False, this
1349-
# won't be needed
1350-
pass
1351-
raise
1352-
data = self._parse_horizons(response.text)
1353-
return data
1354-
13551331

13561332
# the default tool for users to interact with is an instance of the Class
13571333
Horizons = HorizonsClass()

0 commit comments

Comments
 (0)