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. 2
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. 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:
            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)