# Path: ciao_contrib/downloadutils.py
# def retrieve_url(url, timeout=None):
#     """Handle possible problems retrieving the URL contents.
# 
#     Using URLs with the https scheme causes problems for certain OS
#     set ups because CIAO 4.11 does not provide SSL support, but relies
#     on the system libraries to work. This is "supported" by falling
#     over from Python to external tools (curl or wget).
# 
#     Parameters
#     ----------
#     url : str
#         The URL to retrieve.
#     timeout : optional
#         The timeout parameter for the urlopen call; if not
#         None then the value is in seconds.
# 
#     Returns
#     -------
#     response : HTTPResponse instance
#         The response
# 
#     """
# 
#     try:
#         v3("Retrieving URL: {} timeout={}".format(url, timeout))
#         if timeout is None:
#             return urllib.request.urlopen(url)
#         return urllib.request.urlopen(url, timeout=timeout)
# 
#     except urllib.error.URLError as ue:
#         v3("Error opening URL: {}".format(ue))
#         v3("error.reason = {}".format(ue.reason))
# 
#         # Assume this is the error message indicating "no SSL support"
#         # There is a new (in CIAO 4.11) message
#         # "urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)"
#         #
#         # It appears that the reason attribute can be an object, so
#         # for now explicitly convert to a string:
#         reason = str(ue.reason)
#         if reason.find('unknown url type: https') != -1 or \
#            reason.find('CERTIFICATE_VERIFY_FAILED') != -1:
#             return manual_download(url)
# 
#         # There used to be a check on the reason for the error,
#         # converting it into a "user-friendly" message, but this
#         # was error prone (the check itself was faulty) and
#         # potentially hid useful error information. So just
#         # re-raise the error here after logging it.
#         #
#         raise


import numpy as np
import coords.format as coords
import coords.utils as cutils
import ciao_contrib.logger_wrapper as lw
from xml.etree import ElementTree
from collections import OrderedDict
from ciao_contrib.downloadutils import retrieve_url
    """

    url = "https://cxcfps.cfa.harvard.edu/"
    url += "cgi-bin/cda/footprint/get_vo_table.pl"
    url += "?strict=1&POS={},{}&SIZE={}".format(ra, dec, size)

    if instrument is not None:
        url += "&inst="
        url += ",".join([_fconv("instrument", i)
                         for i in set(instrument)])

    return url


def _make_query(url):
    """Query the footprint server and parse the response.

    Parameters
    ----------
    url : str
        The URL for the query; see construct_query

    Returns
    -------
    ans : None or NumPy structured array
        The response, as a NumPy structured array, if there are
        any rows, otherwise None.

    """


# Path: ciao_contrib/downloadutils.py
# def retrieve_url(url, timeout=None):
#     """Handle possible problems retrieving the URL contents.
# 
#     Using URLs with the https scheme causes problems for certain OS
#     set ups because CIAO 4.11 does not provide SSL support, but relies
#     on the system libraries to work. This is "supported" by falling
#     over from Python to external tools (curl or wget).
# 
#     Parameters
#     ----------
#     url : str
#         The URL to retrieve.
#     timeout : optional
#         The timeout parameter for the urlopen call; if not
#         None then the value is in seconds.
# 
#     Returns
#     -------
#     response : HTTPResponse instance
#         The response
# 
#     """
# 
#     try:
#         v3("Retrieving URL: {} timeout={}".format(url, timeout))
#         if timeout is None:
#             return urllib.request.urlopen(url)
#         return urllib.request.urlopen(url, timeout=timeout)
# 
#     except urllib.error.URLError as ue:
#         v3("Error opening URL: {}".format(ue))
#         v3("error.reason = {}".format(ue.reason))
# 
#         # Assume this is the error message indicating "no SSL support"
#         # There is a new (in CIAO 4.11) message
#         # "urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)"
#         #
#         # It appears that the reason attribute can be an object, so
#         # for now explicitly convert to a string:
#         reason = str(ue.reason)
#         if reason.find('unknown url type: https') != -1 or \
#            reason.find('CERTIFICATE_VERIFY_FAILED') != -1:
#             return manual_download(url)
# 
#         # There used to be a check on the reason for the error,
#         # converting it into a "user-friendly" message, but this
#         # was error prone (the check itself was faulty) and
#         # potentially hid useful error information. So just
#         # re-raise the error here after logging it.
#         #
#         raise


# Path: ciao_contrib/cda/search.py
import numpy as np
import coords.format as coords
import coords.utils as cutils
import ciao_contrib.logger_wrapper as lw
from xml.etree import ElementTree
from collections import OrderedDict
from ciao_contrib.downloadutils import retrieve_url

    """

    url = "https://cxcfps.cfa.harvard.edu/"
    url += "cgi-bin/cda/footprint/get_vo_table.pl"
    url += "?strict=1&POS={},{}&SIZE={}".format(ra, dec, size)

    if instrument is not None:
        url += "&inst="
        url += ",".join([_fconv("instrument", i)
                         for i in set(instrument)])

    return url


def _make_query(url):
    """Query the footprint server and parse the response.

    Parameters
    ----------
    url : str
        The URL for the query; see construct_query

    Returns
    -------
    ans : None or NumPy structured array
        The response, as a NumPy structured array, if there are
        any rows, otherwise None.

    """


    rsp = retrieve_url(url)