Skip to content

Commit

Permalink
feat: add keyword to retrieve full list of services or interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Dec 7, 2023
1 parent a035576 commit 54bd363
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
1.5 (unreleased)
================

- Methods ``pyvo.registry.get_interface`` and ``pyvo.registry.get_service`` got a new keyword
(respectively ``all_interfaces`` and ``all_services``) to return the list of matching
services or interfaces rather than the first item. [#505]

- Made SIA2Service accept access urls without finding them in the service capabilities [#500]

- Add intersect modes for the spatial constraint in the registry module ``pyvo.registry.Spatial`` [#495]
Expand Down
26 changes: 21 additions & 5 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@ def access_modes(self):
def get_interface(self,
service_type: str,
lax: bool = True,
std_only: bool = False):
std_only: bool = False,
all_interfaces: bool = False):
"""returns a regtap.Interface class for service_type.
Parameters
Expand All @@ -688,6 +689,10 @@ def get_interface(self,
Only return interfaces declared as "std". This is what you
want when you want to construct pyVO service objects later.
This parameter is ignored for the "web" service type.
all_interfaces : bool, False
Returns a list of all interfaces corresponding to the service
type instead of a single one.
"""
if service_type == "web":
# this works very much differently in the Registry
Expand All @@ -708,6 +713,10 @@ def get_interface(self,
if not candidates:
raise ValueError(
"No matching interface.")

if all_interfaces:
return candidates

if len(candidates) > 1 and not lax:
raise ValueError("Multiple matching interfaces found."
" Perhaps pass in service_type or use a Servicetype"
Expand All @@ -717,12 +726,13 @@ def get_interface(self,

def get_service(self,
service_type: str = None,
lax: bool = True):
lax: bool = True,
all_services: bool = False):
"""
return an appropriate DALService subclass for this resource that
can be used to search the resource using service_type.
Raise a ValueError if the service_type is not offerend on
Raise a ValueError if the service_type is not offered on
the resource (or no standard service is offered). With
lax=False, also raise a ValueError if multiple interfaces
exist for the given service_type.
Expand Down Expand Up @@ -752,6 +762,10 @@ def get_service(self,
function choose the first matching capability by default
Pass lax=False to instead raise a DALQueryError.
all_services : bool, False
If set to True, returns a list of services corresponding to
the service type.
Returns
-------
`pyvo.dal.DALService`
Expand All @@ -761,8 +775,10 @@ def get_service(self,
an opaque service object that has a ``search()`` method simply
opening a web browser on the access URL.
"""
return self.get_interface(service_type, lax, std_only=True
).to_service()
services = self.get_interface(service_type, lax, std_only=True, all_interfaces=all_services)
if all_services:
return [service.to_service() for service in services]
return services.to_service()

@property
def service(self):
Expand Down
2 changes: 2 additions & 0 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ def test_nonunique_lax(self):

assert (rsc.get_service("tap")._baseurl
== "http://a")
assert (rsc.get_service("tap", all_services=True)[1]._baseurl
== "http://b")

def test_nonstd_ignored(self):
rsc = _makeRegistryRecord(
Expand Down

0 comments on commit 54bd363

Please sign in to comment.