Skip to content

Commit

Permalink
solved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsarmiento committed May 24, 2022
1 parent b66f849 commit 239bf98
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions astroquery/esa/xmm_newton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
import re
from getpass import getpass
from ...utils.tap.core import TapPlus
from ...query import BaseQuery
from ...query import BaseQuery, QueryWithLogin
import shutil
import cgi
from pathlib import Path
import tarfile
import os
from astroquery import log
import configparser

from astropy.io import fits
from . import conf, config
from . import conf
from astroquery import log
from astropy.coordinates import SkyCoord
from ...exceptions import LoginError
Expand All @@ -39,12 +38,11 @@ class XMMNewtonClass(BaseQuery):
TIMEOUT = conf.TIMEOUT

def __init__(self, tap_handler=None):
super(XMMNewtonClass, self).__init__()
super().__init__()
self.configuration = configparser.ConfigParser()

if tap_handler is None:
self._tap = TapPlus(url="https://nxsa.esac.esa.int"
"/tap-server/tap")
self._tap = TapPlus(url="https://nxsa.esac.esa.int/tap-server/tap")
else:
self._tap = tap_handler
self._rmf_ftp = str("http://sasdev-xmm.esac.esa.int/pub/ccf/constituents/extras/responses/")
Expand Down Expand Up @@ -103,23 +101,16 @@ def download_data(self, observation_id, *, filename=None, verbose=False,
file format, optional, by default all formats
values: ASC, ASZ, FTZ, HTM, IND, PDF, PNG
Returns
-------
None if not verbose. It downloads the observation indicated
If verbose returns the filename
"""
"""
Here we change the log level so that it is above 20, this is to stop a log.debug in query.py. this debug
reveals the url being sent which in turn reveals the users username and password
"""
previouslevel = log.getEffectiveLevel()
log.setLevel(21)

# create url to access the aio
link = self._create_link(observation_id, **kwargs)

# If the user wants to access proprietary data, ask them for there credentials
# If the user wants to access proprietary data, ask them for their credentials
if prop:
username, password = self._get_username_and_password(credentials_file)
link = f"{link}&AIOUSER={username}&AIOPWD={password}"
Expand All @@ -131,16 +122,23 @@ def download_data(self, observation_id, *, filename=None, verbose=False,
params = self._request_link(link, cache)
r_filename = params["filename"]
suffixes = Path(r_filename).suffixes
print(suffixes)

# get desired filename
filename = self._create_filename(filename, observation_id, suffixes)

self._download_file(link, filename, head_safe=True, cache=cache)
"""
If prop we change the log level so that it is above 20, this is to stop a log.debug (line 431) in query.py.
This debug reveals the url being sent which in turn reveals the users username and password
"""
if prop:
previouslevel = log.getEffectiveLevel()
log.setLevel(21)
self._download_file(link, filename, head_safe=True, cache=cache)
log.setLevel(previouslevel)
else:
self._download_file(link, filename, head_safe=True, cache=cache)

if verbose:
log.info(f"Wrote {link} to {filename}")
log.setLevel(previouslevel)

def get_postcard(self, observation_id, *, image_type="OBS_EPIC",
filename=None, verbose=False):
Expand Down Expand Up @@ -308,14 +306,15 @@ def _request_link(self, link, cache):
return params

def _get_username_and_password(self, credentials_file):
if credentials_file != None:
if credentials_file is not None:
self.configuration.read(credentials_file)
username = self.configuration.get('user', 'username')
password = self.configuration.get('user', 'password')
xmm_username = self.configuration.get("xmm_newton", "username")
password = self.configuration.get("xmm_newton", "password")
else:
username = input("Username: ")
password = getpass("Password: ")
return username, password
xmm_username = input("Username: ")
password, password_from_keyring = QueryWithLogin._get_password(self, service_name="xmm_newton",
username=xmm_username, reenter=False)
return xmm_username, password

def _create_filename(self, filename, observation_id, suffixes):
if filename is not None:
Expand Down Expand Up @@ -616,9 +615,9 @@ def get_epic_metadata(self, *, target_name=None,
Tables containing the metadata of the target
"""
if not target_name and not coordinates:
raise Exception("Input parameters needed, "
"please provide the name "
"or the coordinates of the target")
raise ValueError("Input parameters needed, "
"please provide the name "
"or the coordinates of the target")

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

if type(c) is not SkyCoord:
raise Exception("The coordinates must be an "
raise TypeError("The coordinates must be an "
"astroquery.coordinates.SkyCoord object")
if not radius:
radius = 0.1
Expand Down Expand Up @@ -776,4 +775,4 @@ def get_epic_lightcurve(self, filename, source_number, *,
return ret


XMMNewton = XMMNewtonClass()
XMMNewton = XMMNewtonClass()

0 comments on commit 239bf98

Please sign in to comment.