Esempio n. 1
0
    def _stats_callback(self, instance, cbtype, resp):
        resp = ffi.cast('lcb_RESPSTATS*', resp)
        mres = ffi.from_handle(resp.cookie)

        if resp.rc:
            r = ValueResult()
            r.key = '__dummy__'
            mres._add_bad_rc(resp.rc, r)

        if resp.key == ffi.NULL and resp.server == ffi.NULL:
            self._chk_op_done(mres)
            return

        if resp.rc:
            return

        kbuf = bytes(ffi.buffer(resp.key, resp.nkey))
        key = self._tc.decode_key(kbuf)
        if resp.nvalue:
            value = from_cstring(resp.value, resp.nvalue)
            try:
                value = int(value)
            except ValueError:
                pass
        else:
            value = None

        server = from_cstring(resp.server)
        mres.setdefault(key, {})[server] = value
    def _get_callback(self, instance, cookie, err, resp):
        res = ValueResult()
        res.cas = resp.v.v0.cas
        res.flags = resp.v.v0.flags
        res.rc = err

        if not err:
            value = ffi.buffer(resp.v.v0.bytes, resp.v.v0.nbytes)[:]
            effective_format = resp.v.v0.flags
            if self.data_passthrough or self._cur.ctx.no_format:
                effective_format = FMT_BYTES

            try:
                value = self._tc.decode_value(value, effective_format)
                res.value = value

            except Exception as e:
                res.value = None
                exc = ValueFormatError.pyexc(inner=e, obj=value)
                self._cur.throw(exc)

        else:
            res.value = None

        self._add_response(resp, res)
Esempio n. 3
0
    def _on_single_row(self, instance, cbtype, resp):
        mres = ffi.from_handle(resp.cookie)
        if resp.rflags & C.LCB_RESP_F_FINAL:
            self._handle_done(resp, mres)
            return

        if resp.rc != C.LCB_SUCCESS:
            mres._add_bad_rc(resp.rc, self)
            return

        row = {}
        if resp.nkey:
            row['key'] = PyCBC.json_decode(buf2str(resp.key, resp.nkey))
        if resp.nvalue:
            row['value'] = PyCBC.json_decode(buf2str(resp.value, resp.nvalue))
        if resp.docid:
            # Document ID is always a simple string, so no need to decode
            row['id'] = buf2str(resp.docid, resp.ndocid)

        if resp.docresp:
            py_doc = ValueResult()
            l_doc = resp.docresp
            row['__DOCRESULT__'] = py_doc
            py_doc.key = row['id']
            py_doc.flags = l_doc.itmflags
            py_doc.cas = l_doc.cas
            py_doc.rc = l_doc.rc
            if not resp.docresp.rc:
                buf = bytes(ffi.buffer(l_doc.value, l_doc.nvalue))
                try:
                    tc = self._parent._tc
                    py_doc.value = tc.decode_value(buf, py_doc.flags)
                except:
                    py_doc.value = buf[::]

        # So now that we have a row..
        self.rows.append(row)
        if self._parent._is_async:
            self._invoke_async(mres)
Esempio n. 4
0
    def _on_single_row(self, instance, cbtype, resp):
        mres = ffi.from_handle(resp.cookie)
        if resp.rflags & C.LCB_RESP_F_FINAL:
            if resp.nvalue:
                self.value = bytes(ffi.buffer(resp.value, resp.nvalue))
            self._step(mres, True)
            self._done(mres, resp.rc,
                       resp.htresp.htstatus if resp.htresp else 0)
            return

        # Actually parse the row here!
        row = {}
        if resp.nkey:
            row['key'] = PyCBC.json_decode(buf2str(resp.key, resp.nkey))
        if resp.nvalue:
            row['value'] = PyCBC.json_decode(buf2str(resp.value, resp.nvalue))
        if resp.docid:
            # Document ID is always a simple string, so no need to decode
            row['id'] = buf2str(resp.docid, resp.ndocid)

        if resp.docresp:
            py_doc = ValueResult()
            l_doc = resp.docresp
            row['__DOCRESULT__'] = py_doc
            py_doc.key = row['id']
            py_doc.flags = l_doc.itmflags
            py_doc.cas = l_doc.cas
            py_doc.rc = l_doc.rc
            if not resp.docresp.rc:
                buf = bytes(ffi.buffer(l_doc.value, l_doc.nvalue))
                try:
                    tc = self._parent._tc
                    py_doc.value = tc.decode_value(buf, py_doc.flags)
                except:
                    py_doc.value = buf[::]

        # So now that we have a row..
        self.rows.append(row)
        self._step(mres, False)
Esempio n. 5
0
    def _on_single_row(self, instance, cbtype, resp):
        mres = ffi.from_handle(resp.cookie)
        if resp.rflags & C.LCB_RESP_F_FINAL:
            self._handle_done(resp, mres)
            return

        if resp.rc != C.LCB_SUCCESS:
            mres._add_bad_rc(resp.rc, self)
            return

        row = {}
        if resp.nkey:
            row['key'] = PyCBC.json_decode(buf2str(resp.key, resp.nkey))
        if resp.nvalue:
            row['value'] = PyCBC.json_decode(buf2str(resp.value, resp.nvalue))
        if resp.docid:
            # Document ID is always a simple string, so no need to decode
            row['id'] = buf2str(resp.docid, resp.ndocid)

        if resp.docresp:
            py_doc = ValueResult()
            l_doc = resp.docresp
            row['__DOCRESULT__'] = py_doc
            py_doc.key = row['id']
            py_doc.flags = l_doc.itmflags
            py_doc.cas = l_doc.cas
            py_doc.rc = l_doc.rc
            if not resp.docresp.rc:
                buf = bytes(ffi.buffer(l_doc.value, l_doc.nvalue))
                try:
                    tc = self._parent._tc
                    py_doc.value = tc.decode_value(buf, py_doc.flags)
                except:
                    py_doc.value = buf[::]

        # So now that we have a row..
        self.rows.append(row)
        if self._parent._is_async:
            self._invoke_async(mres)
 def _arith_callback(self, instance, cookie, err, resp):
     res = ValueResult()
     res.cas = resp.v.v0.cas
     res.value = resp.v.v0.value
     res.rc = err
     self._add_response(resp, res)
 def make_result(self, key, value):
     vr = ValueResult()
     vr.key = key
     vr.value = []
     return vr
 def make_result(self, key, _):
     vr = ValueResult()
     vr.key = key
     return vr
Esempio n. 9
0
 def make_result(self, key, value):
     vr = ValueResult()
     vr.key = key
     vr.value = []
     return vr
Esempio n. 10
0
 def make_result(self, key, _):
     vr = ValueResult()
     vr.key = key
     return vr