Skip to content

Commit

Permalink
Reverse back to use None as default form at initialization to allow n…
Browse files Browse the repository at this point in the history
…on remote-data accessing testing
  • Loading branch information
bsipocz committed Mar 29, 2022
1 parent fd9bf0d commit 9163f29
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions astroquery/atomic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AtomicLineListClass(BaseQuery):

def __init__(self):
super(AtomicLineListClass, self).__init__()
self.__default_form_values = self._default_form_values()
self.__default_form_values = None

def query_object(self, *, wavelength_range=None, wavelength_type=None, wavelength_accuracy=None, element_spectrum=None,
minimal_abundance=None, depl_factor=None, lower_level_energy_range=None,
Expand Down Expand Up @@ -179,7 +179,7 @@ def query_object_async(self, *, wavelength_range=None, wavelength_type='', wavel
response : `requests.Response`
The HTTP response returned from the service.
"""
default_values = self.__default_form_values
default_values = self._default_form_values()
wltype = (wavelength_type or default_values.get('air', '')).lower()
if wltype in ('air', 'vacuum'):
air = wltype.capitalize()
Expand Down Expand Up @@ -290,7 +290,7 @@ def _submit_form(self, input_data=None, cache=True):
input_data = {}
# only overwrite payload's values if the ``input_data`` value is not None
# to avoid overwriting of the form's default values
payload = self.__default_form_values.copy()
payload = self._default_form_values().copy()
for k, v in input_data.items():
if v is not None:
payload[k] = v
Expand All @@ -302,14 +302,17 @@ def _submit_form(self, input_data=None, cache=True):
return response

def _default_form_values(self):
response = self._request("GET", url=self.FORM_URL, params={},
timeout=self.TIMEOUT, cache=False)
bs = BeautifulSoup(response.text, features='html5lib')
form = bs.find('form')
default_form_values = self._get_default_form_values(form)
self._form_action_url = urlparse.urljoin(self.FORM_URL, form.get('action'))

return default_form_values
if self.__default_form_values is None:
response = self._request("GET", url=self.FORM_URL, params={},
timeout=self.TIMEOUT, cache=False)
bs = BeautifulSoup(response.text, features='html5lib')
form = bs.find('form')
default_form_values = self._get_default_form_values(form)
self._form_action_url = urlparse.urljoin(self.FORM_URL, form.get('action'))
self.__default_form_values = default_form_values
else:
raise ValueError(self.__default_form_values)
return self.__default_form_values

def _get_default_form_values(self, form):
"""Return the already selected values of a given form (a BeautifulSoup
Expand Down

0 comments on commit 9163f29

Please sign in to comment.