Skip to content

Commit

Permalink
Merge pull request #590 from bsipocz/BUG_session_handling_in_registry
Browse files Browse the repository at this point in the history
BUG: better session handling in registry
  • Loading branch information
msdemlei authored and bsipocz committed Oct 14, 2024
1 parent 4e541ef commit 3309dbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Bug Fixes

- Added `'sia1'` as servicetype for registry searches. [#583]

- Adding ``session`` kwarg to allow to pass a session along when turning
an Interface into a service via ``Interface.to_service``. [#590]


1.5.2 (2024-05-22)
==================
Expand Down
26 changes: 16 additions & 10 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def __repr__(self):
return (f"Interface({self.access_url!r}, standard_id={self.standard_id!r},"
f" intf_type={self.type!r}, intf_role={self.role!r})")

def to_service(self):
def to_service(self, *, session=None):
if self.type == "vr:webbrowser":
return _BrowserService(self.access_url)

Expand All @@ -412,9 +412,9 @@ def to_service(self):
f" standard id {self.standard_id}.")

if service_class == sia2.SIA2Service:
return service_class(self.access_url, check_baseurl=False)
return service_class(self.access_url, check_baseurl=False, session=session)
else:
return service_class(self.access_url)
return service_class(self.access_url, session=session)

def supports(self, standard_id):
"""returns true if we believe the interface should be able to talk
Expand Down Expand Up @@ -768,7 +768,8 @@ def get_interface(self,

def get_service(self,
service_type: str = None,
lax: bool = True):
lax: bool = True,
session: object = None):
"""
return an appropriate DALService subclass for this resource that
can be used to search the resource using service_type.
Expand Down Expand Up @@ -803,6 +804,10 @@ def get_service(self,
function choose the first matching capability by default
Pass lax=False to instead raise a DALQueryError.
session : object
optional requests session to use to communicate with the service
constructed.
Returns
-------
`pyvo.dal.DALService`
Expand All @@ -813,7 +818,7 @@ def get_service(self,
opening a web browser on the access URL.
"""
return self.get_interface(service_type, lax, std_only=True
).to_service()
).to_service(session=session)

@property
def service(self):
Expand Down Expand Up @@ -843,15 +848,16 @@ def search(self, *args, **keys):
the DAL service type would expect. See the documentation for the
appropriate service type:
============ =========================================
============ ===========================================
Service type Use the argument syntax for
============ =========================================
============ ===========================================
catalog :py:meth:`pyvo.dal.scs.SCSService.search`
image :py:meth:`pyvo.dal.sia.SIAService.search`
spectrum :py:meth:`pyvo.dal.ssa.SSAService.search`
sia :py:meth:`pyvo.dal.sia.SIAService.search`
sia2 :py:meth:`pyvo.dal.sia2.SIA2Service.search`
ssa :py:meth:`pyvo.dal.ssa.SSAService.search`
line :py:meth:`pyvo.dal.sla.SLAService.search`
database *not yet supported*
============ =========================================
============ ===========================================
Raises
------
Expand Down

0 comments on commit 3309dbb

Please sign in to comment.