Esempio n. 1
0
import sys

from couchbase_ffi._cinit import get_handle
from couchbase_ffi._rtconfig import PyCBC
from couchbase_ffi.constants import FMT_JSON
from couchbase_ffi.result import HttpResult
from couchbase_ffi.bufmanager import BufManager
from couchbase_ffi._strutil import from_cstring

ffi, C = get_handle()
METHOD_MAP = {
    'GET': C.LCB_HTTP_METHOD_GET,
    'PUT': C.LCB_HTTP_METHOD_PUT,
    'POST': C.LCB_HTTP_METHOD_POST,
    'DELETE': C.LCB_HTTP_METHOD_DELETE
}


class HttpRequest(HttpResult):
    def __init__(self, path, method=C.LCB_HTTP_METHOD_GET,
                 type=C.LCB_HTTP_TYPE_VIEW, response_format=FMT_JSON,
                 content_type='application_json', post_data=None, quiet=False):

        super(HttpRequest, self).__init__()
        self.key = path
        self._parent = None
        self._format = response_format
        self._quiet = quiet
        self._type = type

        if not path:
Esempio n. 2
0
from couchbase_ffi._cinit import get_handle
from couchbase_ffi._rtconfig import pycbc_exc_lcb, pycbc_exc_args
from couchbase_ffi._strutil import from_cstring

ffi, C = get_handle()


class CntlHandler(object):
    def allocate(self, mode):
        """
        Allocate the pointer. Mode is provided in case input and output allocations differ
        """
        raise NotImplementedError()

    def convert_input(self, py_arg, c_value):
        raise NotImplementedError()

    def convert_output(self, c_value):
        raise NotImplementedError()

    def execute(self, lcbh, op, value):
        if value is not None:
            mode = C.LCB_CNTL_SET
        else:
            mode = C.LCB_CNTL_GET
        c_data = self.allocate(mode)

        if mode == C.LCB_CNTL_SET:
            try:
                self.convert_input(value, c_data)
            except: