2424import astropy .io .votable as votable
2525
2626from ..exceptions import (RemoteServiceError , TableParseError ,
27- InvalidQueryError )
27+ InvalidQueryError , LoginError )
2828from ..utils import commons , system_tools
2929from ..utils .process_asyncs import async_to_sync
3030from ..query import QueryWithLogin
@@ -38,6 +38,7 @@ class AlmaClass(QueryWithLogin):
3838
3939 TIMEOUT = conf .timeout
4040 archive_url = conf .archive_url
41+ USERNAME = conf .username
4142
4243 def __init__ (self ):
4344 super (AlmaClass , self ).__init__ ()
@@ -394,7 +395,31 @@ def _parse_result(self, response, verbose=False):
394395 table = first_table .to_table (use_names_over_ids = True )
395396 return table
396397
397- def _login (self , username , store_password = False ):
398+ def _login (self , username = None , store_password = False ,
399+ reenter_password = False ):
400+ """
401+ Login to the ALMA Science Portal.
402+
403+ Parameters
404+ ----------
405+ username : str, optional
406+ Username to the ALMA Science Portal. If not given, it should be
407+ specified in the config file.
408+ store_password : bool, optional
409+ Stores the password securely in your keyring. Default is False.
410+ reenter_password : bool, optional
411+ Asks for the password even if it is already stored in the
412+ keyring. This is the way to overwrite an already stored passwork
413+ on the keyring. Default is False.
414+ """
415+
416+ if username is None :
417+ if self .USERNAME == "" :
418+ raise LoginError ("If you do not pass a username to login(), "
419+ "you should configure a default one!" )
420+ else :
421+ username = self .USERNAME
422+
398423 # Check if already logged in
399424 loginpage = self ._request ("GET" , "https://asa.alma.cl/cas/login" ,
400425 cache = False )
@@ -404,8 +429,12 @@ def _login(self, username, store_password=False):
404429 return True
405430
406431 # Get password from keyring or prompt
407- password_from_keyring = keyring .get_password ("astroquery:asa.alma.cl" ,
408- username )
432+ if reenter_password is False :
433+ password_from_keyring = keyring .get_password (
434+ "astroquery:asa.alma.cl" , username )
435+ else :
436+ password_from_keyring = None
437+
409438 if password_from_keyring is None :
410439 if system_tools .in_ipynb ():
411440 log .warn ("You may be using an ipython notebook:"
0 commit comments