Exemplo n.º 1
0
    def __init__(self, parent, ddoc, view, options, _flags=0, mres=None):
        super(ViewResult, self).__init__(parent)
        self._ddoc = ddoc
        self._view = view
        self._bound_cb = ffi.callback(ROWCB_DECL, self._on_single_row)

        bm = BufManager(ffi)
        urlopts = ffi.NULL
        pypost = None
        cmd = ffi.new('lcb_CMDVIEWQUERY*')

        if options:
            in_uri, in_post = options._long_query_encoded
            # Note, encoded means URI/JSON encoded; not charset
            urlopts = bm.new_cstr(in_uri)
            if in_post and in_post != '{}':
                pypost = in_post

        C.lcb_view_query_initcmd(
            cmd, bm.new_cstr(self._ddoc), bm.new_cstr(self._view),
            urlopts, self._bound_cb)

        if pypost:
            cmd.postdata, cmd.npostdata = bm.new_cbuf(pypost)

        cmd.cmdflags |= _flags

        rc = C.lcb_view_query(self._instance, mres._cdata, cmd)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 2
0
 def set_namedarg(self, arg, value):
     bm = BufManager(ffi)
     arg = bm.new_cbuf(arg)
     value = bm.new_cbuf(value)
     rc = C.lcb_n1p_namedparam(self._lp, arg, len(arg), value, len(value))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 3
0
 def set_namedarg(self, arg, value):
     bm = BufManager(ffi)
     arg = bm.new_cbuf(arg)
     value = bm.new_cbuf(value)
     rc = C.lcb_n1p_namedparam(self._lp, arg, len(arg), value, len(value))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 4
0
 def setoption(self, option, value):
     bm = BufManager(ffi)
     option = bm.new_cbuf(option)
     value = bm.new_cbuf(value)
     rc = C.lcb_n1p_setopt(self._lp, option, len(option), value, len(value))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 5
0
 def setoption(self, option, value):
     bm = BufManager(ffi)
     option = bm.new_cbuf(option)
     value = bm.new_cbuf(value)
     rc = C.lcb_n1p_setopt(self._lp, option, len(option), value, len(value))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 6
0
    def _schedule(self, parent, mres):
        bm = BufManager(ffi)
        urlopts = ffi.NULL
        pypost = None
        cmd = self._c_command

        if self._options:
            in_uri, in_post = self._options._long_query_encoded
            # Note, encoded means URI/JSON encoded; not charset
            urlopts = bm.new_cstr(in_uri)
            if in_post and in_post != '{}':
                pypost = in_post

        C.lcb_view_query_initcmd(
            cmd, bm.new_cstr(self._ddoc), bm.new_cstr(self._view),
            urlopts, self._bound_cb)

        if pypost:
            cmd.postdata, cmd.npostdata = bm.new_cbuf(pypost)

        if self._include_docs:
            cmd.cmdflags |= C.LCB_CMDVIEWQUERY_F_INCLUDE_DOCS

        self._c_command.handle = self._c_handle

        self._parent = parent
        rc = C.lcb_view_query(parent._lcbh, mres._cdata, self._c_command)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 7
0
 def _add_creds(self, user, password):
     bm = BufManager(ffi)
     c_user = bm.new_cstr(user)
     c_pass = bm.new_cstr(password)
     pp = ffi.new('char*[2]', (c_user, c_pass))
     rc = C.lcb_cntl(self._lcbh, C.LCB_CNTL_SET, C.LCB_CNTL_BUCKET_CRED, pp)
     if rc:
         pycbc_exc_lcb(rc)
Exemplo n.º 8
0
 def _vbmap(self, key):
     bm = BufManager(ffi)
     info_obj = ffi.new('lcb_cntl_vbinfo_t*')
     info_obj.v.v0.key, info_obj.v.v0.nkey = bm.new_cbuf(key)
     rc = C.lcb_cntl(self._lcbh, C.LCB_CNTL_GET, C.LCB_CNTL_VBMAP, info_obj)
     if rc:
         raise pycbc_exc_lcb(rc)
     return info_obj.v.v0.vbucket, info_obj.v.v0.server_index
Exemplo n.º 9
0
        def _do_schedule(parent, mres):
            bm = BufManager(ffi)
            cmd = ffi.new('lcb_CMDHTTP*')
            cmd.type = self._type
            cmd.method = method

            C._Cb_set_key(cmd, *bm.new_cbuf(path))
            cmd.body, cmd.nbody = bm.new_cbuf(post_data)
            cmd.content_type = bm.new_cstr(content_type)
            rc = C.lcb_http3(parent._lcbh, mres._cdata, cmd)
            if rc:
                raise PyCBC.exc_lcb(rc, 'Scheduling HTTP request')
Exemplo n.º 10
0
        def _do_schedule(parent, mres):
            bm = BufManager(ffi)
            cmd = ffi.new('lcb_CMDHTTP*')
            cmd.type = self._type
            cmd.method = method

            C._Cb_set_key(cmd, *bm.new_cbuf(path))
            cmd.body, cmd.nbody = bm.new_cbuf(post_data)
            cmd.content_type = bm.new_cstr(content_type)
            rc = C.lcb_http3(parent._lcbh, mres._cdata, cmd)
            if rc:
                raise PyCBC.exc_lcb(rc, 'Scheduling HTTP request')
Exemplo n.º 11
0
    def __run_stat(self, k, mres):
        bm = BufManager(ffi)
        if k:
            if not isinstance(k, basestring):
                raise pycbc_exc_args('Stats arguments must be strings only!')
            c_key, c_len = bm.new_cbuf(k)
        else:
            c_key, c_len = ffi.NULL, 0

        C._Cb_set_key(self.c_command, c_key, c_len)
        rc = C.lcb_stats3(self.instance, mres._cdata, self.c_command)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 12
0
    def __run_stat(self, k, mres):
        bm = BufManager(ffi)
        if k:
            if not isinstance(k, basestring):
                raise pycbc_exc_args('Stats arguments must be strings only!')
            c_key, c_len = bm.new_cbuf(k)
        else:
            c_key, c_len = ffi.NULL, 0

        C._Cb_set_key(self.c_command, c_key, c_len)
        rc = C.lcb_stats3(self.instance, mres._cdata, self.c_command)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 13
0
    def __init__(self, parent, params, prepare, mres=None):
        super(N1qlResult, self).__init__(parent)
        self._bound_cb = ffi.callback(
            'void(lcb_t,int,lcb_RESPN1QL*)', self._on_single_row)
        bm = BufManager(ffi)

        cmd = ffi.new('lcb_CMDN1QL*')
        cmd.query, cmd.nquery = bm.new_cbuf(params)
        cmd.callback = self._bound_cb
        if prepare:
            cmd.cmdflags |= C.LCB_CMDN1QL_F_PREPCACHE
        rc = C.lcb_n1ql_query(parent._lcbh, mres._cdata, cmd)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 14
0
    def _schedule(self, parent, mres):
        bm = BufManager(ffi)
        urlopts = ffi.NULL
        pypost = None
        cmd = self._c_command

        if self._options:
            in_uri, in_post = self._options._long_query_encoded
            # Note, encoded means URI/JSON encoded; not charset
            urlopts = bm.new_cstr(in_uri)
            if in_post and in_post != '{}':
                pypost = in_post

        C.lcb_view_query_initcmd(cmd, bm.new_cstr(self._ddoc),
                                 bm.new_cstr(self._view), urlopts,
                                 self._bound_cb)

        if pypost:
            cmd.postdata, cmd.npostdata = bm.new_cbuf(pypost)

        if self._include_docs:
            cmd.cmdflags |= C.LCB_CMDVIEWQUERY_F_INCLUDE_DOCS

        self._c_command.handle = self._c_handle

        self._parent = parent
        rc = C.lcb_view_query(parent._lcbh, mres._cdata, self._c_command)
        if rc:
            raise pycbc_exc_lcb(rc)
Exemplo n.º 15
0
 def add_posarg(self, arg):
     bm = BufManager(ffi)
     arg = bm.new_cbuf(arg)
     rc = C.lcb_n1p_posparam(self._lp, arg, len(arg))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 16
0
 def add_posarg(self, arg):
     bm = BufManager(ffi)
     arg = bm.new_cbuf(arg)
     rc = C.lcb_n1p_posparam(self._lp, arg, len(arg))
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 17
0
 def setquery(self, query=None, type=C.LCB_N1P_QUERY_STATEMENT):
     bm = BufManager(ffi)
     query = bm.new_cbuf(query)
     rc = C.lcb_n1p_setquery(self._lp, bm.new_cstr(query), len(query), type)
     if rc:
         raise pycbc_exc_lcb(rc)
Exemplo n.º 18
0
    def __init__(self, connection_string=None, connstr=None,
                 username=None, password=None, quiet=False,
                 transcoder=None, default_format=FMT_JSON,
                 lockmode=LOCKMODE_EXC, unlock_gil=True,
                 _iops=None, _conntype=C.LCB_TYPE_BUCKET,
                 _flags=0):

        crst = ffi.new('struct lcb_create_st*')
        bm = BufManager(ffi)

        if not connstr and not connection_string:
            raise pycbc_exc_args('Must have connection string')
        if connstr and connection_string:
            raise pycbc_exc_args(
                "Cannot specify both 'connstr' and 'connection_string'")
        if not connstr:
            connstr = connection_string

        crst.version = 3
        crst.v.v3.connstr = bm.new_cstr(connstr)
        crst.v.v3.passwd = bm.new_cstr(password)
        crst.v.v3.username = bm.new_cstr(username)
        crst.v.v3.type = _conntype

        if _iops:
            procs = _iops
            self._iowrap = IOPSWrapper(procs)
            crst.v.v3.io = self._iowrap.get_lcb_iops()
        else:
            crst.v.v3.io = ffi.NULL

        self._handles = set()

        lcb_pp = ffi.new('lcb_t*')
        rc = C.lcb_create(lcb_pp, crst)
        if rc != C.LCB_SUCCESS:
            raise pycbc_exc_lcb(rc)

        self._lcbh = lcb_pp[0]

        self._bound_cb = {
            'store': ffi.callback(CALLBACK_DECL, self._storage_callback),
            'get': ffi.callback(CALLBACK_DECL, self._get_callback),
            'remove': ffi.callback(CALLBACK_DECL, self._remove_callback),
            'counter': ffi.callback(CALLBACK_DECL, self._counter_callback),
            'observe': ffi.callback(CALLBACK_DECL, self._observe_callback),
            'stats': ffi.callback(CALLBACK_DECL, self._stats_callback),
            'http': ffi.callback(CALLBACK_DECL, self._http_callback),
            '_default': ffi.callback(CALLBACK_DECL, self._default_callback),
            '_bootstrap': ffi.callback('void(lcb_t,lcb_error_t)',
                                       self._bootstrap_callback),
            '_dtor': ffi.callback('void(const void*)',
                                  self._instance_destroyed)
        }

        self._executors = {
            'upsert': executors.UpsertExecutor(self),
            'insert': executors.InsertExecutor(self),
            'replace': executors.ReplaceExecutor(self),
            'append': executors.AppendExecutor(self),
            'prepend': executors.PrependExecutor(self),
            'get': executors.GetExecutor(self),
            'lock': executors.LockExecutor(self),
            '_unlock': executors.UnlockExecutor(self),
            'touch': executors.TouchExecutor(self),
            'remove': executors.RemoveExecutor(self),
            'counter': executors.CounterExecutor(self),
            'endure': executors.DurabilityExecutor(self),
            '_chained_endure': executors.DurabilityChainExecutor(self),
            'observe': executors.ObserveExecutor(self),
            'stats': executors.StatsExecutor(self),
            '_rget': executors.GetReplicaExecutor(self)
        }

        self._install_cb(C.LCB_CALLBACK_DEFAULT, '_default')
        self._install_cb(C.LCB_CALLBACK_STORE, 'store')
        self._install_cb(C.LCB_CALLBACK_GET, 'get')
        self._install_cb(C.LCB_CALLBACK_GETREPLICA, 'get')
        self._install_cb(C.LCB_CALLBACK_REMOVE, 'remove')
        self._install_cb(C.LCB_CALLBACK_COUNTER, 'counter')
        self._install_cb(C.LCB_CALLBACK_OBSERVE, 'observe')
        self._install_cb(C.LCB_CALLBACK_STATS, 'stats')
        self._install_cb(C.LCB_CALLBACK_HTTP, 'http')
        C.lcb_set_bootstrap_callback(self._lcbh, self._bound_cb['_bootstrap'])

        # Set our properties
        self.data_passthrough = False
        self.transcoder = transcoder
        self.default_format = default_format
        self.quiet = quiet
        self.unlock_gil = unlock_gil

        self._dur_persist_to = 0
        self._dur_replicate_to = 0
        self._dur_timeout = 0
        self._dur_testhook = None
        self._privflags = _flags
        self._conncb = None
        self.__bucket = self._cntl(C.LCB_CNTL_BUCKETNAME, value_type='string')
        self.__connected = False
        self._lockmode = lockmode if unlock_gil else LOCKMODE_NONE
        self._lock = Lock()
        self._pipeline_queue = None

        self._embedref = None
        InstanceReference.addref(self)
Exemplo n.º 19
0
 def setquery(self, query=None, type=C.LCB_N1P_QUERY_STATEMENT):
     bm = BufManager(ffi)
     query = bm.new_cbuf(query)
     rc = C.lcb_n1p_setquery(self._lp, bm.new_cstr(query), len(query), type)
     if rc:
         raise pycbc_exc_lcb(rc)