PyObject * pycbc_HttpResult__maybe_raise(pycbc_HttpResult *self) { if (maybe_raise(self)) { return NULL; } Py_RETURN_NONE; }
/** * Fetches a bunch of results from the network. Returns False when * no more results remain. */ PyObject * pycbc_HttpResult__fetch(pycbc_HttpResult *self) { lcb_error_t err; PyObject *ret = NULL; if (-1 == pycbc_oputil_conn_lock(self->parent)) { return NULL; } if (!self->htreq) { ret = Py_None; Py_INCREF(ret); goto GT_RET; } if (self->parent->flags & PYCBC_CONN_F_ASYNC) { PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "_fetch() should not be called with an async " "connection"); goto GT_RET; } else if (self->parent->pipeline_queue) { PYCBC_EXC_WRAP(PYCBC_EXC_PIPELINE, 0, "HTTP requests cannot be executed in pipeline context"); } if (!self->rowsbuf) { self->rowsbuf = PyList_New(0); } err = pycbc_oputil_wait_common(self->parent); if (err != LCB_SUCCESS) { PYCBC_EXCTHROW_WAIT(err); goto GT_RET; } else { if (maybe_raise(self)) { goto GT_RET; } ret = self->rowsbuf; self->rowsbuf = NULL; } if (!pycbc_assert(self->parent->nremaining == 0)) { fprintf(stderr, "Remaining count unexpected. Adjusting"); self->parent->nremaining = 0; } GT_RET: pycbc_oputil_conn_unlock(self->parent); return ret; }
/** * Fetches a bunch of results from the network. Returns False when * no more results remain. */ PyObject * pycbc_HttpResult__fetch(pycbc_HttpResult *self) { lcb_error_t err; PyObject *ret = NULL; if (-1 == pycbc_oputil_conn_lock(self->parent)) { return NULL; } if (!self->htreq) { ret = Py_None; Py_INCREF(ret); goto GT_RET; } if (!self->rowsbuf) { self->rowsbuf = PyList_New(0); } err = pycbc_oputil_wait_common(self->parent); if (err != LCB_SUCCESS) { PYCBC_EXCTHROW_WAIT(err); goto GT_RET; } else { if (maybe_raise(self)) { goto GT_RET; } ret = self->rowsbuf; self->rowsbuf = NULL; } if (!pycbc_assert(self->parent->nremaining == 0)) { fprintf(stderr, "Remaining count unexpected. Adjusting"); self->parent->nremaining = 0; } GT_RET: pycbc_oputil_conn_unlock(self->parent); return ret; }
PyObject * pycbc_Connection__http_request(pycbc_Connection *self, PyObject *args, PyObject *kwargs) { int rv; int method; int reqtype; unsigned short value_format = 0; lcb_error_t err; const char *body = NULL; PyObject *ret = NULL; PyObject *quiet_O = NULL; PyObject *chunked_O = NULL; PyObject *fetch_headers_O = Py_False; pycbc_strlen_t nbody = 0; const char *path = NULL; const char *content_type = NULL; pycbc_HttpResult *htres; lcb_http_request_t l_htreq; lcb_http_cmd_t htcmd = { 0 }; static char *kwlist[] = { "type", "method", "path", "content_type", "post_data", "response_format", "quiet", "fetch_headers", "chunked", NULL }; rv = PyArg_ParseTupleAndKeywords(args, kwargs, "iis|zz#HOOO", kwlist, &reqtype, &method, &path, &content_type, &body, &nbody, &value_format, &quiet_O, &fetch_headers_O, &chunked_O); if (!rv) { PYCBC_EXCTHROW_ARGS(); return NULL; } if (-1 == pycbc_oputil_conn_lock(self)) { return NULL; } htres = pycbc_httpresult_new(self); htres->key = pycbc_SimpleStringZ(path); htres->format = value_format; htres->htflags = 0; if (quiet_O != NULL && quiet_O != Py_None && PyObject_IsTrue(quiet_O)) { htres->htflags |= PYCBC_HTRES_F_QUIET; } if (fetch_headers_O && PyObject_IsTrue(fetch_headers_O)) { htres->headers = PyDict_New(); } if (chunked_O && PyObject_IsTrue(chunked_O)) { htcmd.v.v0.chunked = 1; htres->rctx = lcbex_vrow_create(); htres->rctx->callback = http_vrow_callback; htres->rctx->user_cookie = htres; htres->htflags |= PYCBC_HTRES_F_CHUNKED; } htcmd.v.v1.body = body; htcmd.v.v1.nbody = nbody; htcmd.v.v1.content_type = content_type; htcmd.v.v1.path = path; htcmd.v.v1.npath = strlen(path); htcmd.v.v1.method = method; err = lcb_make_http_request(self->instance, htres, reqtype, &htcmd, &l_htreq); if (err != LCB_SUCCESS) { PYCBC_EXCTHROW_SCHED(err); goto GT_DONE; } htres->htreq = l_htreq; if (htcmd.v.v0.chunked) { ret = (PyObject*)htres; htres = NULL; goto GT_DONE; } self->nremaining++; err = pycbc_oputil_wait_common(self); if (err != LCB_SUCCESS) { self->nremaining--; PYCBC_EXCTHROW_WAIT(err); goto GT_DONE; } if (maybe_raise(htres)) { goto GT_DONE; } ret = (PyObject*)htres; htres = NULL; GT_DONE: Py_XDECREF(htres); pycbc_oputil_conn_unlock(self); return ret; }