class OperationInfo(object):
    __slots__ = ('exc', 'ctx', 'res')

    def __init__(self):
        self.start(None)

    def start(self, ctx):
        self.exc = None
        self.ctx = ctx
        self.res = MultiResult()

    def throw(self, exc):
        self.res.all_ok = False
        if self.exc:
            return

        self.exc = exc
        self.exc.all_results = self.res

    def rethrow(self):
        if self.exc:
            raise self.exc


    def _warn_dup_key(self, key, conn):
        msg = "Duplicate key {0} found".format(key)
        if conn._privflags & PYCBC_CONN_F_WARNEXPLICIT:
            warn_explicit(msg,
                          RuntimeWarning,
                          __file__, -1,
                          module="couchbase_ffi.connection",
                          registry={})
        else:
            warn(msg, RuntimeWarning)

    def add_single(self, pres, key, conn):
        pres.key = key
        try:
            if key in self.res:
                self._warn_dup_key(key, conn)

            self.res[key] = pres

        except TypeError as e:
            self.throw(ValueFormatError.pyexc("Unhashable key", obj=key))
            return

        self.update_single(pres, conn)

    def update_single(self, pres, conn):
        if not pres.rc:
            return

        self.res.all_ok = False
        if pres.rc == C.LCB_KEY_ENOENT and self.ctx.quiet or conn.quiet:
            return

        self.throw(conn._make_exc(pres.rc, pres))

    def mkret(self, is_multi):
        if is_multi:
            return self.res
        return self.res.values()[0]
 def start(self, ctx):
     self.exc = None
     self.ctx = ctx
     self.res = MultiResult()
示例#3
0
 def _make_mres(self):
     if self._is_async:
         return AsyncResult()
     else:
         return MultiResult()