Exemplo n.º 1
0
    def stringReceived(self, string):
        """
        This is the 'main' RPC method. This will always be called when
        a request arrives and it's up to this method to parse the request and
        dispatch it further.

        @type string: str
        @param string: Request from client, just the 'string' itself, already
            stripped of the netstring stuff.

        @rtype: DeferredList
        @return: Deferred, that will fire when all methods are finished. It
            will already have all the callbacks and errbacks neccessary to
            finish and send the response.
        """

        self._logRequest(string)
        try:
            request_content = jsonrpc.decodeRequest(string)
        except jsonrpc.JSONRPCError:
            self._parseError()
            return None

        is_batch = True
        if not isinstance(request_content, list):
            request_content = [request_content]
            is_batch = False

        dl = []
        for request_dict in request_content:
            d = succeed(request_dict)
            d.addCallback(jsonrpc.verifyMethodCall)
            d.addCallback(self._callMethod)
            d.addBoth(jsonrpc.prepareMethodResponse, request_dict['id'],
                      request_dict['jsonrpc'])
            dl.append(d)

        dl = DeferredList(dl, consumeErrors=True)
        dl.addBoth(self._cbFinishRequest, is_batch)

        return dl
Exemplo n.º 2
0
    def stringReceived(self, string):
        """
        This is the 'main' RPC method. This will always be called when
        a request arrives and it's up to this method to parse the request and
        dispatch it further.

        @type string: str
        @param string: Request from client, just the 'string' itself, already
            stripped of the netstring stuff.

        @rtype: DeferredList
        @return: Deferred, that will fire when all methods are finished. It
            will already have all the callbacks and errbacks neccessary to
            finish and send the response.
        """

        self._logRequest(string)
        try:
            request_content = jsonrpc.decodeRequest(string)
        except jsonrpc.JSONRPCError:
            self._parseError()
            return None

        is_batch = True
        if not isinstance(request_content, list):
            request_content = [request_content]
            is_batch = False

        dl = []
        for request_dict in request_content:
            d = succeed(request_dict)
            d.addCallback(jsonrpc.verifyMethodCall)
            d.addCallback(self._callMethod)
            d.addBoth(jsonrpc.prepareMethodResponse, request_dict['id'],
                      request_dict['jsonrpc'])
            dl.append(d)

        dl = DeferredList(dl, consumeErrors=True)
        dl.addBoth(self._cbFinishRequest, is_batch)

        return dl
Exemplo n.º 3
0
    def _getRequestContent(self, request):
        """
        Parse the JSON from the request. Return it as a list, even if there was
        only one method call (which would give us a dict). This will be useful
        later, as we can iterate over it in the same manner if it is a single
        call or a batch request.

        @type request: t.w.s.Request
        @param request: The request from client

        @rtype: list
        @return: List of dicts, one dict per method call.

        @raise JSONRPCError: If there's error in parsing.
        """

        request.content.seek(0, 0)
        request_json = request.content.read()
        request_content = jsonrpc.decodeRequest(request_json)

        return request_content
Exemplo n.º 4
0
    def _getRequestContent(self, request):
        """
        Parse the JSON from the request. Return it as a list, even if there was
        only one method call (which would give us a dict). This will be useful
        later, as we can iterate over it in the same manner if it is a single
        call or a batch request.

        @type request: t.w.s.Request
        @param request: The request from client

        @rtype: list
        @return: List of dicts, one dict per method call.

        @raise JSONRPCError: If there's error in parsing.
        """

        request.content.seek(0, 0)
        request_json = request.content.read()
        request_content = jsonrpc.decodeRequest(request_json)

        return request_content