Example #1
0
    def test_success_function(self):
        steps = []
        def _append(v):
            steps.append(v)
            return steps

        dfd = mustbe_deferred(_append, 1)
        dfd.addCallback(self.assertEqual, [1,2]) # it is [1] with maybeDeferred
        steps.append(2) # add another value, that should be catched by assertEqual
        return dfd
Example #2
0
    def test_unfired_deferred(self):
        steps = []
        def _append(v):
            steps.append(v)
            dfd = defer.Deferred()
            reactor.callLater(0, dfd.callback, steps)
            return dfd

        dfd = mustbe_deferred(_append, 1)
        dfd.addCallback(self.assertEqual, [1,2]) # it is [1] with maybeDeferred
        steps.append(2) # add another value, that should be catched by assertEqual
        return dfd
Example #3
0
    def post(self, *args):
        jsonid = None
        try:
            req = escape.json_decode(self.request.body)
            method = req["method"]
            assert isinstance(method, types.StringTypes), "{0}: {1}".format(method, type(method))
            params = req["params"]
            assert isinstance(params, (types.ListType, types.TupleType)), "{0}: {1}".format(params, type(params))
            jsonid = req["id"]
            assert isinstance(jsonid, (types.NoneType, types.IntType, types.StringTypes)), "{0}: {1}".format(jsonid, type(jsonid))
        except Exception as e:
            self.log(e, "bad request", isError=True)
            d = defer_fail(JsonrpcError("bad request"))
        else:
            # XXX: not supports nested services. e.g.: foo.bar
            function = getattr(self, "jsonrpc_{0}".format(method), None)
            if callable(function):
                args = list(args) + list(params)
                d = mustbe_deferred(function, *args)
            else:
                d = defer_fail(JsonrpcError("method not found: {0}".format(method)))

        d.addBoth(self._cbResult, jsonid)
        return d