Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: better session handling in registry #590

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Deprecations and Removals

- 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
30 changes: 20 additions & 10 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def __repr__(self):
f"description={self.capability_description!r}, "
f"url={self.access_url!r})")

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

Expand All @@ -434,9 +434,13 @@ def to_service(self):
if service_class == sia2.SIA2Service:
return service_class(self.access_url,
capability_description=self.capability_description,
check_baseurl=False)
check_baseurl=False,
session=session)
else:
return service_class(self.access_url, capability_description=self.capability_description)
return service_class(
self.access_url,
capability_description=self.capability_description,
session=session)

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

def get_service(self, service_type: str = None, *,
lax: bool = False,
keyword: str = None):
keyword: str = None,
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 @@ -849,6 +854,10 @@ def get_service(self, service_type: str = None, *,
service. Use list_interfaces to find such a unique description
fragment.

session : object
optional requests session to use to communicate with the service
constructed.

Returns
-------
`pyvo.dal.DALService`
Expand All @@ -863,7 +872,7 @@ def get_service(self, service_type: str = None, *,
list_interfaces : return a list with all the available services.
"""
return self.get_interface(service_type=service_type, lax=lax, std_only=True,
keyword=keyword).to_service()
keyword=keyword).to_service(session=session)

@property
def service(self):
Expand Down Expand Up @@ -931,15 +940,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
Loading