Skip to content

Commit 3a556bb

Browse files
committed
add ALMA query validator - validates everything now! keywords AND
values
1 parent 67527ff commit 3a556bb

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

astroquery/alma/core.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,41 @@ def query_async(self, payload, cache=True, public=True, science=True):
128128
if science:
129129
payload['scan_intent-asu'] = '=*TARGET*'
130130

131-
self._validate_payload(payload)
131+
self.validate_query(payload)
132132

133133
response = self._request('GET', url, params=payload,
134134
timeout=self.TIMEOUT, cache=cache)
135135
response.raise_for_status()
136136

137137
return response
138+
139+
def validate_query(self, payload, cache=True):
140+
"""
141+
Use the ALMA query validator service to check whether the keywords are
142+
valid
143+
"""
144+
145+
# Check that the keywords specified are allowed
146+
self._validate_payload(payload)
147+
148+
vurl = self._get_dataarchive_url() + '/aq/validate'
149+
150+
bad_kws = {}
151+
152+
for kw in payload:
153+
vpayload = {'field':kw,
154+
kw: payload[kw]}
155+
response = self._request('GET', vurl, params=vpayload, cache=cache,
156+
timeout=self.TIMEOUT)
157+
158+
if response.content:
159+
bad_kws[kw] = response.content
160+
161+
if bad_kws:
162+
raise InvalidQueryError("Invalid query parameters: "
163+
"{0}".format(bad_kws))
164+
165+
138166

139167
def _get_dataarchive_url(self):
140168
"""

0 commit comments

Comments
 (0)