:class:`~.CasJobsTask` =========================================================================================================================================== .. py:class:: astropathdb.db_io.dbconnect.CasJobsTask :single-line-parameter-list: Builds various ``CasJobs`` header formats and handles responses. Most logic is simplified and reused from the ``SciScript-Python``. This is NOT a user facing class, use :class:`.CasJobsUrllib3Client` to submit low level requests with this API. Preferably, please use :class:`.AstroDB` to create a database connection. :class:`~.astropathdb.db_io.dbconnect.CasJobsTask` *Methods* ------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.dbconnect.CasJobsTask.get_taskname astropathdb.db_io.dbconnect.CasJobsTask.set_headers astropathdb.db_io.dbconnect.CasJobsTask.format_data :class:`~.astropathdb.db_io.dbconnect.CasJobsTask` *References* ------------------------------------------------------------------------------------------------------------------------------------------- .. py:currentmodule:: astropathdb.db_io.dbconnect.CasJobsTask *Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: get_taskname(task_id) :single-line-parameter-list: :staticmethod: Get the ``CasJobs`` task name for a local or SciServer compute client. :param task_id: The task id (ex: 'executeQuery'). :returns: ``'Compute.SciScript-Python.CasJobs.'`` in a SciServer compute environment, otherwise ``'SciScript-Python.CasJobs.'``. .. py:method:: set_headers(accept_format) :single-line-parameter-list: Set the token and 'Accept' in :attr:`~.CasJobsTask._headers` for next requests. :param accept_format: The output format name. See :meth:`~.SciBase.query` for the output formats. .. py:method:: format_data(sql, task_id) :single-line-parameter-list: :staticmethod: Format ``sql`` and ``task_id`` as a JSON request body. :param sql: The SQL query to pass. :param task_id: The task name for the query. :returns: The JSON-encoded request body. *Private Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: _headers :type: dict[str, str] Headers for the ``CasJobs`` request. 'Content-Type' is always 'application/json'. The 'X-Auth-Token' and 'Accept' headers are set by :meth:`~.CasJobsTask.set_headers` before each request. *Private Property Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:property:: _token :type: str Gets the token and validates that it is not empty. Note that we always require a token... for some reason ``CasJobs`` will still pass the query and lets the server kick back an error in the ``executeQuery`` function. :returns: The authentication token from ``Authentication.getToken``. :raises CasJobsLoginError: No SciServer login token is set. *Private Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: __format_to_accept_header(accept_format) :single-line-parameter-list: :staticmethod: Map an output ``accept_format`` to its 'Accept' header value. Simplified ``SciScript-Python`` lookup. Formats parsed by :meth:`~.CasJobsTask._format_response` map to "application/json+array". The ``SciScript-Python`` text ("csv", "readable", "StringIO") and fits ("fits", "BytesIO") formats map to "text/plain" and "application/fits"; their responses are not parsed by this client. :param accept_format: The output format name. :returns: The 'Accept' header value. :raises CasJobsInvalidFormatError: ``accept_format`` is not a known format. .. py:method:: _format_response(responses, accept_format) :single-line-parameter-list: :staticmethod: Parse ``CasJobs`` result sets, based loosely on ``SciScript-Python`` logic. See :meth:`~.SciBase.query` for the output formats. Unparsed formats return the result set dictionaries unchanged. :param responses: The result set dictionaries from the response. :param accept_format: The output format name. :returns: The result sets in the ``accept_format`` output format.