in source/s3_meta_request.c [217:286]
static void s_s3_request_on_finish(
struct aws_s3_meta_request *meta_request,
const struct aws_s3_meta_request_result *meta_request_result,
void *user_data) {
(void)meta_request;
struct s3_meta_request_binding *request_binding = user_data;
if (request_binding->recv_file) {
fclose(request_binding->recv_file);
request_binding->recv_file = NULL;
}
/*************** GIL ACQUIRE ***************/
PyGILState_STATE state;
if (aws_py_gilstate_ensure(&state)) {
return; /* Python has shut down. Nothing matters anymore, but don't crash */
}
PyObject *header_list = NULL;
PyObject *result = NULL;
if (request_binding->input_body) {
/* close the input file stream now, request has finished, we will not read from there anymore */
aws_input_stream_destroy(request_binding->input_body);
request_binding->input_body = NULL;
}
if (request_binding->size_transferred) {
/* report the remaining progress */
result =
PyObject_CallMethod(request_binding->py_core, "_on_progress", "(K)", request_binding->size_transferred);
if (!result) {
PyErr_WriteUnraisable(request_binding->py_core);
} else {
Py_DECREF(result);
}
request_binding->size_transferred = 0;
}
struct aws_byte_buf error_body;
AWS_ZERO_STRUCT(error_body);
/* Get the header and body of the error */
if (meta_request_result->error_response_headers) {
header_list = s_get_py_headers(meta_request_result->error_response_headers);
if (!header_list) {
PyErr_WriteUnraisable(request_binding->py_core);
goto done;
}
}
if (meta_request_result->error_response_body) {
error_body = *(meta_request_result->error_response_body);
}
result = PyObject_CallMethod(
request_binding->py_core,
"_on_finish",
"(iOy#)",
meta_request_result->error_code,
header_list ? header_list : Py_None,
(const char *)(error_body.buffer),
(Py_ssize_t)error_body.len);
if (result) {
Py_DECREF(result);
} else {
/* Callback might fail during application shutdown */
PyErr_WriteUnraisable(request_binding->py_core);
}
done:
Py_XDECREF(header_list);
PyGILState_Release(state);
/*************** GIL RELEASE ***************/
}