Skip to content

Commit

Permalink
Enabling access url/format sensing in datalink for SIA1 and SSAP.
Browse files Browse the repository at this point in the history
This also now compares utypes case-insensitively in getbyutype as
required by the SSAP standard.

All this is ugly VO legacy, but I am rather confident that one of these
days we will be glad we have these heuristics in.
  • Loading branch information
msdemlei committed Sep 25, 2024
1 parent 9dbd2db commit 0fcf7e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
12 changes: 8 additions & 4 deletions pyvo/dal/adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ def _guess_access_format(row):
if "access_format" in row:
return row["access_format"]

access_format = row.getbyutype("obscore:access.format")
access_format = row.getbyutype("obscore:access.format"
) or row.getbyutype("ssa:Access.Format")
if access_format:
return access_format

access_format = row.getbyucd("meta.code.mime")
access_format = row.getbyucd("meta.code.mime"
) or row.getbyucd("VOX:Image_Format")
if access_format:
return access_format

Expand All @@ -251,11 +253,13 @@ def _guess_access_url(row):
if "access_url" in row:
return row["access_url"]

access_url = row.getbyutype("obscore:access.reference")
access_url = row.getbyutype("obscore:access.reference"
) or row.getbyutype("ssa:Access.Reference")
if access_url:
return access_url

access_url = row.getbyucd("meta.ref.url")
access_url = row.getbyucd("meta.ref.url"
) or row.getbyucd("VOX:Image_AccessReference")
if access_url:
return access_url

Expand Down
3 changes: 2 additions & 1 deletion pyvo/dal/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ def fieldname_with_utype(self, utype):
return the field name that has a given UType value or None if the UType
is not found.
"""
utype = utype.lower()
try:
iterchain = (
self.getdesc(fieldname) for fieldname in self.fieldnames)
iterchain = (field for field in iterchain if field.utype == utype)
iterchain = (field for field in iterchain if (field.utype or "").lower() == utype)
return next(iterchain).name
except StopIteration:
return None
Expand Down
20 changes: 17 additions & 3 deletions pyvo/dal/tests/test_datalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,24 @@ def test_sia2_record(self):

def test_sia1_record(self):
res = testing.create_dalresults([
{"name": "access_url", "datatype": "char", "arraysize": "*",
{"name": "product", "datatype": "char", "arraysize": "*",
"ucd": "VOX:Image_AccessReference"},
{"name": "access_format", "datatype": "char", "arraysize": "*",
"utype": "VOX:Image_Format"},],
{"name": "mime", "datatype": "char", "arraysize": "*",
"ucd": "VOX:Image_Format"},],
[("http://example.com/datalink.xml",
"application/x-votable+xml;content=datalink")],
resultsClass=TAPResults)
links = list(res.iter_datalinks())
assert len(links) == 1
assert (next(links[0].bysemantics("#this"))["access_url"]
== "http://dc.zah.uni-heidelberg.de/getproduct/flashheros/data/ca90/f0011.mt")

def test_ssap_record(self):
res = testing.create_dalresults([
{"name": "product", "datatype": "char", "arraysize": "*",
"utype": "ssa:access.reference"},
{"name": "mime", "datatype": "char", "arraysize": "*",
"utype": "ssa:access.format"},],
[("http://example.com/datalink.xml",
"application/x-votable+xml;content=datalink")],
resultsClass=TAPResults)
Expand Down

0 comments on commit 0fcf7e7

Please sign in to comment.