def _handle_done(self, resp, mres): self.done = True self._c_handle = None if resp.rc: if resp.rc == C.LCB_HTTP_ERROR: try: raise PyCBC.exc_http(self.value) except: mres._add_err(sys.exc_info()) else: mres._add_bad_rc(resp.rc, self) if resp.nvalue: self.value = buf2str(resp.value, resp.nvalue) try: self.value = PyCBC.json_decode(self.value) except: pass if resp.htresp: if not self.value and resp.htresp.nbody: self.value = buf2str(resp.htresp.body, resp.htresp.nbody) self.http_status = resp.htresp.htstatus if self._parent._is_async: try: mres._maybe_throw() self._invoke_async(mres, is_final=True) except: mres.errback(mres, *sys.exc_info()) finally: del self._parent
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 _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)
def _on_single_row(self, instance, cbtype, resp): mres = ffi.from_handle(resp.cookie) if resp.rflags & C.LCB_RESP_F_FINAL: if resp.nrow: self.value = bytes(ffi.buffer(resp.row, resp.nrow)) self._step(mres, True) self._done(mres, resp.rc, resp.htresp.htstatus if resp.htresp else 0) else: # Simply parse the row try: row = PyCBC.json_decode(bytes(ffi.buffer(resp.row, resp.nrow))) self.rows.append(row) except: mres._add_err(sys.exc_info()) self._step(mres, False)
def _do_json_decode(self, value): return PyCBC.json_decode(value)