Skip to content

Commit 94b836e

Browse files
Used _get_password as suggested and changed config file as suggested by astroquery team
1 parent 016172d commit 94b836e

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

astroquery/esa/xmm_newton/core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
import re
1515
from getpass import getpass
1616
from ...utils.tap.core import TapPlus
17-
from ...query import BaseQuery
17+
from ...query import BaseQuery, QueryWithLogin
1818
import shutil
1919
import cgi
2020
from pathlib import Path
2121
import tarfile
2222
import os
23-
from astroquery import log
2423
import configparser
2524

2625
from astropy.io import fits
@@ -111,7 +110,7 @@ def download_data(self, observation_id, *, filename=None, verbose=False,
111110
# create url to access the aio
112111
link = self._create_link(observation_id, **kwargs)
113112

114-
# If the user wants to access proprietary data, ask them for there credentials
113+
# If the user wants to access proprietary data, ask them for their credentials
115114
if prop:
116115
username, password = self._get_username_and_password(credentials_file)
117116
link = f"{link}&AIOUSER={username}&AIOPWD={password}"
@@ -309,12 +308,13 @@ def _request_link(self, link, cache):
309308
def _get_username_and_password(self, credentials_file):
310309
if credentials_file is not None:
311310
self.configuration.read(credentials_file)
312-
username = self.configuration.get('user', 'username')
313-
password = self.configuration.get('user', 'password')
311+
xmm_username = self.configuration.get("xmm_newton", "username")
312+
password = self.configuration.get("xmm_newton", "password")
314313
else:
315-
username = input("Username: ")
316-
password = getpass("Password: ")
317-
return username, password
314+
xmm_username = input("Username: ")
315+
password, password_from_keyring = QueryWithLogin._get_password(self, service_name="xmm_newton",
316+
username=xmm_username, reenter=False)
317+
return xmm_username, password
318318

319319
def _create_filename(self, filename, observation_id, suffixes):
320320
if filename is not None:
@@ -615,9 +615,9 @@ def get_epic_metadata(self, *, target_name=None,
615615
Tables containing the metadata of the target
616616
"""
617617
if not target_name and not coordinates:
618-
raise Exception("Input parameters needed, "
619-
"please provide the name "
620-
"or the coordinates of the target")
618+
raise ValueError("Input parameters needed, "
619+
"please provide the name "
620+
"or the coordinates of the target")
621621

622622
epic_source = {"table": "xsa.v_epic_source",
623623
"column": "epic_source_equatorial_spoint"}
@@ -635,7 +635,7 @@ def get_epic_metadata(self, *, target_name=None,
635635
c = SkyCoord.from_name(target_name, parse=True)
636636

637637
if type(c) is not SkyCoord:
638-
raise Exception("The coordinates must be an "
638+
raise TypeError("The coordinates must be an "
639639
"astroquery.coordinates.SkyCoord object")
640640
if not radius:
641641
radius = 0.1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[user]
1+
[xmm_newton]
22
username=test
33
password=test

astroquery/esa/xmm_newton/tests/test_xmm_newton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def test_request_link_incorrect_credentials(self, mock_request):
553553

554554
def test_get_username_and_password(self):
555555
xsa = XMMNewtonClass(self.get_dummy_tap_handler())
556-
file = data_path("my_config.ini")
556+
file = data_path("dummy_config.ini")
557557
username, password = xsa._get_username_and_password(file)
558558
assert username == "test"
559559
assert password == "test"

astroquery/esa/xmm_newton/tests/test_xmm_newton_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_get_epic_metadata(self):
199199
def test_download_proprietary_data_incorrect_credentials(self):
200200
parameters = {'observation_id': "0762470101",
201201
'prop': 'True',
202-
'credentials_file': "astroquery/esa/xmm_newton/tests/my_config.ini",
202+
'credentials_file': "astroquery/esa/xmm_newton/tests/data/dummy_config.ini",
203203
'level': "PPS",
204204
'name': 'OBSMLI',
205205
'filename': 'single',

docs/esa/xmm_newton.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ For more details of the parameters check the section 3.4 at:
4141
--------------------------------------
4242
To access proprietary data an extra variable is needed in the XMMNewton.download_data method. This variabe is prop which
4343
can be True or False. If True a username and password is needed. A username and password can be passed by adding another
44-
variable to the XMMNewton.download_data method called credentials_file. This variable is a string with the path to a
45-
config.ini file with the desired username and password, e.g. credentials_file = "users/joe.bloggs/config.ini"
46-
47-
Example config.ini file,
44+
variable to the XMMNewton.download_data method called credentials_file. This variable is a string with the path to
45+
~/.astropy/config/astroquery.cfg file. Inside this file add your desired username and password, e.g.
4846

4947
.. code-block::
5048
51-
[user]
52-
username = test
53-
password = test
49+
[xmm_newton]
50+
username = your_username
51+
password = your_password
5452
5553
If the credentials_file variable is not provided the method will ask for the username and password to be added manually
5654
from the commandline

0 commit comments

Comments
 (0)