

def defer(self, opres):
    '\n        Converts a raw :class:`couchbase.results.AsyncResult` object\n        into a :class:`Deferred`.\n\n        This is shorthand for the following "non-idiom"::\n\n          d = Deferred()\n          opres = cb.upsert("foo", "bar")\n          opres.callback = d.callback\n\n          def d_err(res, ex_type, ex_val, ex_tb):\n              d.errback(opres, ex_type, ex_val, ex_tb)\n\n          opres.errback = d_err\n          return d\n\n        :param opres: The operation to wrap\n        :type opres: :class:`couchbase.results.AsyncResult`\n\n        :return: a :class:`Deferred` object.\n\n        Example::\n\n          opres = cb.upsert("foo", "bar")\n          d = cb.defer(opres)\n          def on_ok(res):\n              print("Result OK. Cas: {0}".format(res.cas))\n          d.addCallback(opres)\n\n\n        '
    d = Deferred()
    opres.callback = d.callback

    def _on_err(mres, ex_type, ex_val, ex_tb):
        try:
            raise ex_type(ex_val)
        except CouchbaseError:
            d.errback()
    opres.errback = _on_err
    return d

dataset/ETHPy150Open couchbase/couchbase-python-client/txcouchbase/bucket.py RawBucket.defer/original