Example #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
Example #2
0
    def _handle_response(self, mres, resp):
        result = self
        headers = result.headers

        if resp.headers:
            ix = 0
            while True:
                pp = resp.headers[ix]
                if pp == ffi.NULL:
                    break
                key = from_cstring(resp.headers[ix])
                value = from_cstring(resp.headers[ix+1])
                headers[key] = value
                ix += 2

        result.rc = resp.rc
        result.htcode = resp.htstatus

        if resp.rc:
            mres._add_bad_rc(resp.rc)
        elif not self.success and not mres._quiet:
            try:
                raise PyCBC.exc_http(self.value, response=self)
            except PyCBC.default_exception:
                mres._add_err(sys.exc_info())

        if resp.nbody:
            buf = bytes(ffi.buffer(ffi.cast('const char*', resp.body), resp.nbody))
            tc = self._parent._tc
            try:
                result.http_data = tc.decode_value(buf, self._format)
            except:
                if not self._quiet:
                    mres._add_err(sys.exc_info())
                result.http_data = buf
Example #3
0
    def server_nodes(self):
        nodelist = C.lcb_get_server_list(self._lcbh)
        s_list = []
        ix = 0

        while True:
            cur_str = nodelist[ix]
            if not cur_str:
                break
            s_list.append(from_cstring(cur_str))
            ix += 1

        return s_list
Example #4
0
    def _handle_response(self, mres, resp):
        result = self
        headers = result.headers

        if resp.headers:
            ix = 0
            while True:
                pp = resp.headers[ix]
                if pp == ffi.NULL:
                    break
                key = from_cstring(resp.headers[ix])
                value = from_cstring(resp.headers[ix + 1])
                headers[key] = value
                ix += 2

        result.rc = resp.rc
        result.htcode = resp.htstatus

        if resp.rc:
            mres._add_bad_rc(resp.rc)
        elif not self.success and not mres._quiet:
            try:
                raise PyCBC.exc_http(self.value, response=self)
            except PyCBC.default_exception:
                mres._add_err(sys.exc_info())

        if resp.nbody:
            buf = bytes(
                ffi.buffer(ffi.cast('const char*', resp.body), resp.nbody))
            tc = self._parent._tc
            try:
                result.http_data = tc.decode_value(buf, self._format)
            except:
                if not self._quiet:
                    mres._add_err(sys.exc_info())
                result.http_data = buf
Example #5
0
 def convert_output(self, c_value):
     return from_cstring(c_value[0])
Example #6
0
 def errstr(self):
     return from_cstring(C.lcb_strerror(ffi.NULL, self.rc))
 def errstr(self):
     return from_cstring(C.lcb_strerror(ffi.NULL, self.rc))
Example #8
0
def buf2str(v, n):
    return from_cstring(ffi.cast('const char*', v), n)
def buf2str(v, n):
    return from_cstring(ffi.cast('const char*', v), n)
def _strerror(rc):
    return from_cstring(C.lcb_strerror(ffi.NULL, rc))
def lcb_version():
    num_p = ffi.new('unsigned*')
    str_p = C.lcb_get_version(num_p)
    return from_cstring(str_p), num_p[0]
Example #12
0
def _strerror(rc):
    return from_cstring(C.lcb_strerror(ffi.NULL, rc))
Example #13
0
def lcb_version():
    num_p = ffi.new('unsigned*')
    str_p = C.lcb_get_version(num_p)
    return from_cstring(str_p), num_p[0]