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)
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)
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)
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)
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')
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')
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)
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)
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)