CasJobsTask#

class astropathdb.db_io.dbconnect.CasJobsTask#

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 CasJobsUrllib3Client to submit low level requests with this API. Preferably, please use AstroDB to create a database connection.

CasJobsTask Methods#

get_taskname(task_id)

Get the CasJobs task name for a local or SciServer compute client.

set_headers(accept_format)

Set the token and 'Accept' in _headers for next requests.

format_data(sql, task_id)

Format sql and task_id as a JSON request body.

CasJobsTask References#

Method Reference#

static get_taskname(task_id)#

Get the CasJobs task name for a local or SciServer compute client.

Parameters:

task_id (str) – The task id (ex: ‘executeQuery’).

Returns:

'Compute.SciScript-Python.CasJobs.<task_id>' in a SciServer compute environment, otherwise 'SciScript-Python.CasJobs.<task_id>'.

Return type:

str

method set_headers(accept_format)#

Set the token and ‘Accept’ in _headers for next requests.

Parameters:

accept_format (str) – The output format name. See query() for the output formats.

Return type:

None

static format_data(sql, task_id)#

Format sql and task_id as a JSON request body.

Parameters:
  • sql (str) – The SQL query to pass.

  • task_id (str) – The task name for the query.

Returns:

The JSON-encoded request body.

Return type:

bytes

Private Attribute Reference#

attribute _headers: dict[str, str]#

Headers for the CasJobs request.

‘Content-Type’ is always ‘application/json’. The ‘X-Auth-Token’ and ‘Accept’ headers are set by set_headers() before each request.

Private Property Reference#

property _token#
Type:

str

Return 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.

Return type:

str

Private Method Reference#

static __format_to_accept_header(accept_format)#

Map an output accept_format to its ‘Accept’ header value.

Simplified SciScript-Python lookup. Formats parsed by _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.

Parameters:

accept_format (str) – The output format name.

Returns:

The ‘Accept’ header value.

Raises:

CasJobsInvalidFormatError – accept_format is not a known format.

Return type:

str

static _format_response(responses, accept_format)#

Parse CasJobs result sets, based loosely on SciScript-Python logic.

See query() for the output formats. Unparsed formats return the result set dictionaries unchanged.

Parameters:
  • responses (list[dict]) – The result set dictionaries from the response.

  • accept_format (str) – The output format name.

Returns:

The result sets in the accept_format output format.

Return type:

list[dict] | tuple[list, list] | DataFrame | list[DataFrame]