def test_datasets(self): records = DALResults.from_result_url( 'http://example.com/query/dataset') record = records[0] assert record.getdataurl() == 'http://example.com/querydata/image.fits' dataset = record.getdataset() HDUList.fromstring(dataset.read())
def mime_object_maker(url, mimetype, session=None): """ return a data object suitable for the mimetype given. this will either return a astropy fits object or a pyvo DALResults object, a PIL object for conventional images or string for text content. Parameters ---------- url : str the object download url mimetype : str the content mimetype session : object optional session to use for network requests """ session = use_session(session) mimetype = mimeparse.parse_mime_type(mimetype) if mimetype[0] == 'text': return session.get(url).text if mimetype[1] == 'fits' or mimetype[1] == 'x-fits': response = session.get(url) return HDUList.fromstring(response.content) if mimetype[0] == 'image': from PIL import Image from io import BytesIO response = session.get(url) bio = BytesIO(response.content) return Image.open(bio) if mimetype[1] == 'x-votable' or mimetype[1] == 'x-votable+xml': # As soon as there are some kind of recursive data structures, # things start to get messy if mimetype[2].get('content', None) == 'datalink': from .adhoc import DatalinkResults return DatalinkResults.from_result_url(url) else: from .query import DALResults return DALResults.from_result_url(url)
def mime_object_maker(url, mimetype): """ return a data object suitable for the mimetype given. this will either return a astropy fits object or a pyvo DALResults object, a PIL object for conventional images or string for text content. Parameters ---------- url : str the object download url mimetype : str the content mimetype """ mimetype = mimeparse.parse_mime_type(mimetype) if mimetype[0] == 'text': return s.get(url).text if mimetype[1] == 'fits' or mimetype[1] == 'x-fits': r = s.get(url) return HDUList.fromstring(r.content) if mimetype[0] == 'image': from PIL import Image from io import BytesIO r = s.get(url) b = BytesIO(r.content) return Image.open(b) if mimetype[1] == 'x-votable' or mimetype[1] == 'x-votable+xml': # As soon as there are some kind of recursive data structures, # things start to get really f*cked up if mimetype[2].get('content', None) == 'datalink': from .adhoc import DatalinkResults return DatalinkResults.from_result_url(url) else: from .query import DALResults return DALResults.from_result_url(url)