static PyObject * keyop_common(pycbc_Bucket *self, PyObject *args, PyObject *kwargs, int optype, int argopts) { int rv; Py_ssize_t ncmds = 0; pycbc_seqtype_t seqtype; PyObject *casobj = NULL; PyObject *is_quiet = NULL; PyObject *kobj = NULL; char persist_to = 0, replicate_to = 0; struct pycbc_common_vars cv = PYCBC_COMMON_VARS_STATIC_INIT; static char *kwlist[] = { "keys", "cas", "quiet", "persist_to", "replicate_to", NULL }; rv = PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOBB", kwlist, &kobj, &casobj, &is_quiet, &persist_to, &replicate_to); if (!rv) { PYCBC_EXCTHROW_ARGS(); return NULL; } if (argopts & PYCBC_ARGOPT_MULTI) { rv = pycbc_oputil_check_sequence(kobj, 1, &ncmds, &seqtype); if (rv < 0) { return NULL; } if (casobj && PyObject_IsTrue(casobj)) { PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "Can't pass CAS for multiple keys"); } } else { ncmds = 1; } rv = pycbc_common_vars_init(&cv, self, argopts, ncmds, 0); if (rv < 0) { return NULL; } if (argopts & PYCBC_ARGOPT_MULTI) { rv = pycbc_oputil_iter_multi(self, seqtype, kobj, &cv, optype, handle_single_keyop, NULL); } else { rv = handle_single_keyop(self, &cv, optype, kobj, casobj, NULL, NULL, NULL); } if (rv < 0) { goto GT_DONE; } if (optype == PYCBC_CMD_DELETE) { rv = pycbc_handle_durability_args(self, &cv.mres->dur, persist_to, replicate_to); if (rv == 1) { cv.mres->mropts |= PYCBC_MRES_F_DURABILITY; } else if (rv == -1) { goto GT_DONE; } if (pycbc_maybe_set_quiet(cv.mres, is_quiet) == -1) { goto GT_DONE; } } if (-1 == pycbc_common_vars_wait(&cv, self)) { goto GT_DONE; } GT_DONE: pycbc_common_vars_finalize(&cv, self); return cv.ret; }
static PyObject * keyop_common(pycbc_Connection *self, PyObject *args, PyObject *kwargs, int optype, int argopts) { int rv; int ii; Py_ssize_t ncmds = 0; pycbc_seqtype_t seqtype; PyObject *casobj = NULL; PyObject *ret = NULL; PyObject *is_quiet = NULL; PyObject *kobj = NULL; pycbc_MultiResult *mres = NULL; lcb_error_t err; struct pycbc_common_vars cv = PYCBC_COMMON_VARS_STATIC_INIT; static char *kwlist[] = { "keys", "cas", "quiet", NULL }; rv = PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO", kwlist, &kobj, &casobj, &is_quiet); if (!rv) { PYCBC_EXCTHROW_ARGS(); return NULL; } if (argopts & PYCBC_ARGOPT_MULTI) { rv = pycbc_oputil_check_sequence(kobj, 1, &ncmds, &seqtype); if (rv < 0) { return NULL; } if (casobj && PyObject_IsTrue(casobj)) { PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "Can't pass CAS for multiple keys"); } } else { ncmds = 1; } rv = pycbc_common_vars_init(&cv, ncmds, sizeof(lcb_remove_cmd_t), 0); if (rv < 0) { return NULL; } if (argopts & PYCBC_ARGOPT_MULTI) { Py_ssize_t dictpos = 0; PyObject *curseq, *iter = NULL; curseq = pycbc_oputil_iter_prepare(seqtype, kobj, &iter, &dictpos); if (!curseq) { goto GT_DONE; } for (ii = 0; ii < ncmds; ii++) { PyObject *curkey = NULL, *curvalue = NULL; rv = pycbc_oputil_sequence_next(seqtype, curseq, &dictpos, ii, &curkey, &curvalue); if (rv < 0) { goto GT_ITER_DONE; } rv = handle_single_keyop(self, curkey, curvalue, ii, optype, &cv); Py_XDECREF(curkey); Py_XDECREF(curvalue); if (rv < 0) { goto GT_ITER_DONE; } } GT_ITER_DONE: Py_XDECREF(iter); if (rv < 0) { goto GT_DONE; } } else { rv = handle_single_keyop(self, kobj, casobj, 0, optype, &cv); if (rv < 0) { goto GT_DONE; } } mres = (pycbc_MultiResult*)pycbc_multiresult_new(self); if (optype == PYCBC_CMD_DELETE) { if (pycbc_maybe_set_quiet(mres, is_quiet) == -1) { goto GT_DONE; } err = lcb_remove(self->instance, mres, ncmds, cv.cmdlist.remove); } else { err = lcb_unlock(self->instance, mres, ncmds, cv.cmdlist.unlock); } if (err != LCB_SUCCESS) { PYCBC_EXCTHROW_SCHED(err); goto GT_DONE; } err = pycbc_oputil_wait_common(self); if (err != LCB_SUCCESS) { PYCBC_EXCTHROW_WAIT(err); goto GT_DONE; } if (!pycbc_multiresult_maybe_raise(mres)) { ret = (PyObject*)mres; } GT_DONE: pycbc_common_vars_free(&cv); ret = pycbc_make_retval(argopts, &ret, &mres); Py_XDECREF(mres); return ret; }