Skip to content

Commit 2455808

Browse files
committed
ENH: Adding BaseVOQuery baseclass to serve as a minimal base class for VO modules
1 parent 6eefe6d commit 2455808

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

astroquery/query.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import astropy.utils.data
2222
from astropy.utils import deprecated
2323

24+
import pyvo
25+
2426
from astroquery import version, log, cache_conf
2527
from astroquery.utils import system_tools
2628

@@ -175,18 +177,35 @@ def login(*args, **kwargs):
175177
return newcls
176178

177179

180+
class BaseVOQuery:
181+
"""
182+
Bare minimum base query that sets the Session header to include both astroquery and pyvo.
183+
Use in modules that rely on PyVO, either on its own or in combination with ``BaseQuery`` (be mindful
184+
about resolution order of base classes!).
185+
"""
186+
def __init__(self):
187+
super().__init__()
188+
self._session = requests.Session()
189+
self._session.headers['User-Agent'] = (
190+
f"astroquery/{version.version} pyVO/{pyvo.__version__} Python/{platform.python_version()} "
191+
f"({platform.system()}) "
192+
f"{self._session.headers['User-Agent']}")
193+
194+
self.name = self.__class__.__name__.split("Class")[0]
195+
196+
178197
class BaseQuery(metaclass=LoginABCMeta):
179198
"""
180199
This is the base class for all the query classes in astroquery. It
181200
is implemented as an abstract class and must not be directly instantiated.
182201
"""
183202

184203
def __init__(self):
185-
S = self._session = requests.Session()
204+
self._session = requests.Session()
186205
self._session.hooks['response'].append(self._response_hook)
187-
S.headers['User-Agent'] = (
206+
self._session.headers['User-Agent'] = (
188207
f"astroquery/{version.version} Python/{platform.python_version()} ({platform.system()}) "
189-
f"{S.headers['User-Agent']}")
208+
f"{self._session.headers['User-Agent']}")
190209

191210
self.name = self.__class__.__name__.split("Class")[0]
192211
self._cache_location = None

0 commit comments

Comments
 (0)