From 99d3c0f3382ce2f863fc1db870168b24761673bb Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Wed, 29 Nov 2023 11:26:52 -0800 Subject: [PATCH] Re-worked --- pyvo/dal/sia2.py | 37 ++++++++++++++++++++----------------- pyvo/dal/tests/test_sia2.py | 7 +++++++ pyvo/registry/regtap.py | 5 ++++- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/pyvo/dal/sia2.py b/pyvo/dal/sia2.py index b0181f071..86ddbdc7e 100644 --- a/pyvo/dal/sia2.py +++ b/pyvo/dal/sia2.py @@ -156,7 +156,7 @@ class SIA2Service(DALService, AvailabilityMixin, CapabilityMixin): generally not notice that, though. """ - def __init__(self, baseurl, session=None): + def __init__(self, baseurl, session=None, check_baseurl=True): """ instantiate an SIA2 service @@ -166,6 +166,9 @@ def __init__(self, baseurl, session=None): url - URL of the SIA2service (base or query endpoint) session : object optional session to use for network requests + check_baseurl : bool + True - use the capabilities end point of the service to get the + query end point, False - baseurl is the query end point """ super().__init__(baseurl, session=session) @@ -177,22 +180,22 @@ def __init__(self, baseurl, session=None): if hasattr(self._session, 'update_from_capabilities'): self._session.update_from_capabilities(self.capabilities) - self.query_ep = baseurl # default service query end point - for cap in self.capabilities: - # assumes that the access URL is the same regardless of the - # authentication method except BasicAA which is not supported - # in pyvo. So pick any access url as long as it's not - found = False - if cap.standardid.lower() == SIA2_STANDARD_ID.lower(): - for interface in cap.interfaces: - if interface.accessurls and \ - not (len(interface.securitymethods) == 1 - and interface.securitymethods[0].standardid - == 'ivo://ivoa.net/sso#BasicAA'): - self.query_ep = interface.accessurls[0].content - found = True - break - if found: + self.query_ep = baseurl.strip('&') # default service end point + if check_baseurl: + for cap in self.capabilities: + # assumes that the access URL is the same regardless of the + # authentication method except BasicAA which is not supported + # in pyvo. So pick any access url as long as it's not + if cap.standardid.lower() == SIA2_STANDARD_ID.lower(): + for interface in cap.interfaces: + if interface.accessurls and \ + not (len(interface.securitymethods) == 1 + and interface.securitymethods[0].standardid + == 'ivo://ivoa.net/sso#BasicAA'): + self.query_ep = interface.accessurls[0].content + break + else: + continue break def search(self, pos=None, band=None, time=None, pol=None, diff --git a/pyvo/dal/tests/test_sia2.py b/pyvo/dal/tests/test_sia2.py index 58fd3e980..9d031a863 100644 --- a/pyvo/dal/tests/test_sia2.py +++ b/pyvo/dal/tests/test_sia2.py @@ -95,6 +95,13 @@ def test_capabilities(self): service = SIA2Service('https://example.com/sia/myquery?param=1') assert service.query_ep == 'https://example.com/sia/v2query' + # capabilities checking is bypassed all together with the + # check_baseurl=False flag + service = SIA2Service('https://example.com/sia/myquery?param=1&', + check_baseurl=False) + assert service.query_ep == 'https://example.com/sia/myquery?param=1' + + POSITIONS = [(2, 4, 0.0166 * u.deg), (12, 12.5, 34, 36), (12.0 * u.deg, 34.0 * u.deg, diff --git a/pyvo/registry/regtap.py b/pyvo/registry/regtap.py index f736cb3c3..86d6ad31c 100644 --- a/pyvo/registry/regtap.py +++ b/pyvo/registry/regtap.py @@ -371,7 +371,10 @@ def to_service(self): raise ValueError("PyVO has no support for interfaces with" f" standard id {self.standard_id}.") - return service_class(self.access_url) + if service_class == sia2.SIA2Service: + return service_class(self.access_url, check_baseurl=False) + else: + return service_class(self.access_url) def supports(self, standard_id): """returns true if we believe the interface should be able to talk