diff --git a/pyvo/registry/regtap.py b/pyvo/registry/regtap.py index 65aeb6fe3..ee269fafc 100644 --- a/pyvo/registry/regtap.py +++ b/pyvo/registry/regtap.py @@ -199,20 +199,27 @@ def get_summary(self): This is mainly intended for interactive use, where people would like to inspect the matches in, perhaps, notebooks. + + This returns a column access_url for backwards compatibilty. Do + not use what you find there in new code. Use get_service on the + records themselves instead. """ return table.Table([ list(range(len(self))), [r.short_name for r in self], [r.res_title for r in self], [r.res_description for r in self], - [", ".join(sorted(r.access_modes())) for r in self]], - names=("index", "short_name", "title", "description", "interfaces"), + [", ".join(sorted(r.access_modes())) for r in self], + [r.get_unique_access_url() for r in self]], + names=("index", "short_name", "title", "description", + "interfaces", "access_url"), descriptions=( "Index to access the resource within self", "Short name", "Resource title", "Resource description", - "Access modes offered")) + "Access modes offered", + "Unique access URL (or None for multi-interface records)")) @functools.lru_cache(maxsize=None) def _get_ivo_index(self): @@ -534,6 +541,19 @@ def access_url(self): " may change in the future.")) return access_urls[0] + def get_unique_access_url(self): + """ + return the access URL of this resource in case it is uniquely + defined. + + This is for legacy code that assumes there is just one + access URL. It will return None if Resource has zero or more than + one interfaces. + """ + access_urls = list(sorted(set(self["access_urls"]))) + if len(access_urls)==1: + return access_urls[0] + @property def standard_id(self): """ diff --git a/pyvo/registry/tests/test_regtap.py b/pyvo/registry/tests/test_regtap.py index e55ace251..c134e53ae 100644 --- a/pyvo/registry/tests/test_regtap.py +++ b/pyvo/registry/tests/test_regtap.py @@ -316,13 +316,15 @@ def test_to_table(multi_interface_fixture, capabilities): t = regtap.search( ivoid="ivo://org.gavo.dc/flashheros/q/ssa").get_summary() assert (set(t.columns.keys()) - == {'index', 'short_name', 'title', 'description', 'interfaces'}) + == {'index', 'short_name', 'title', 'description', + 'interfaces', 'access_url'}) assert t["index"][0] == 0 assert t["title"][0] == 'Flash/Heros SSAP' assert (t["description"][0][:40] == 'Spectra from the Flash and Heros Echelle') assert (t["interfaces"][0] == 'datalink#links-1.0, soda#sync-1.0, ssa, tap#aux, web') + assert (t["access_url"][0] is None) @pytest.fixture()