Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---------

- Fix NASA ADS, which had an internal syntax error (#602)
- Bugifx in NRAO queries: telescope config was parsed incorrectly (#629)
- IBE - added new module for locating data from PTF, WISE, and 2MASS from IRSA.
See <http://irsa.ipac.caltech.edu/ibe/> for more information about IBE and
<http://www.ptf.caltech.edu/page/ibe> for more information about PTF survey
Expand Down
23 changes: 13 additions & 10 deletions astroquery/nrao/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def _args_to_payload(self, **kwargs):
@prepend_docstr_noreturns(_args_to_payload.__doc__)
def query_async(self,
get_query_payload=False,
cache=True,
**kwargs):
"""
Returns
Expand All @@ -209,10 +210,8 @@ def query_async(self,

if get_query_payload:
return request_payload
response = commons.send_request(Nrao.DATA_URL,
request_payload,
Nrao.TIMEOUT,
request_type='POST')
response = self._request('POST', self.DATA_URL, params=request_payload,
timeout=self.TIMEOUT, cache=cache)
return response

@prepend_docstr_noreturns(_args_to_payload.__doc__)
Expand Down Expand Up @@ -244,11 +243,8 @@ def query_region_async(self, coordinates, radius=1 * u.deg,
def _parse_result(self, response, verbose=False):
if not verbose:
commons.suppress_vo_warnings()
# fix to replace non standard datatype 'integer' in returned VOTable
# with 'int' to make it parsable by astropy.io.votable
integer_re = re.compile(r'datatype="integer"')
content = response.text
new_content = integer_re.sub(r'datatype="int"', content)

new_content = response.text

# these are pretty bad hacks, but also needed...
days_re = re.compile(r'unit="days" datatype="double"')
Expand All @@ -257,10 +253,17 @@ def _parse_result(self, response, verbose=False):
degrees_re = re.compile(r'unit="degrees" datatype="double"')
new_content = degrees_re.sub(r'unit="degrees" datatype="char" '
'arraysize="*"', new_content)
telconfig_re = re.compile(r'datatype="char" name="Telescope:config"')
new_content = telconfig_re.sub(r'datatype="unicodeChar" '
'name="Telescope:config" '
' arraysize="*" ', new_content)

datatype_mapping = {'integer':'long'}

try:
tf = six.BytesIO(new_content.encode())
first_table = votable.parse(tf, pedantic=False).get_first_table()
first_table = votable.parse(tf, pedantic=False,
datatype_mapping=datatype_mapping).get_first_table()
try:
table = first_table.to_table(use_names_over_ids=True)
except TypeError:
Expand Down
21 changes: 6 additions & 15 deletions astroquery/nrao/tests/test_nrao.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,20 @@ def parse_coordinates_mock_return(c):
return mp


@pytest.fixture
def patch_get(request):
mp = request.getfuncargvalue("monkeypatch")
mp.setattr(requests, 'get', get_mockreturn)
return mp


@pytest.fixture
def patch_post(request):
mp = request.getfuncargvalue("monkeypatch")
mp.setattr(requests, 'post', post_mockreturn)
mp.setattr(requests.Session, 'request', post_mockreturn)
return mp


def get_mockreturn(url, params=None, timeout=10, **kwargs):
filename = data_path(DATA_FILES['votable'])
content = open(filename, 'rb').read()
return MockResponse(content, **kwargs)


def post_mockreturn(url, data=None, timeout=10, **kwargs):
def post_mockreturn(self, method, url, data=None, timeout=10, files=None,
params=None, headers=None, **kwargs):
if method != 'POST':
raise ValueError("A 'post request' was made with method != POST")
filename = data_path(DATA_FILES['votable'])
content = open(filename, 'rb').read()
content = open(filename, "rb").read()
return MockResponse(content, **kwargs)


Expand Down