예제 #1
0
파일: protocol.py 프로젝트: 0keita/configs
def deserialize_message(data, get_params_type=get_method_params_type):
    """Function used to deserialize data received from client."""
    if 'jsonrpc' in data:
        try:
            deserialize_params(data, get_params_type)
        except ValueError:
            raise JsonRpcInvalidParams()

        if 'id' in data:
            if 'method' in data:
                return JsonRPCRequestMessage(**data)
            else:
                return JsonRPCResponseMessage(**data)
        else:
            return JsonRPCNotification(**data)

    return data
예제 #2
0
파일: protocol.py 프로젝트: 0keita/configs
    def _send_response(self, msg_id, result=None, error=None):
        """Sends a JSON RPC response to the client.

        Args:
            msg_id(str): Id from request
            result(any): Result returned by handler
            error(any): Error returned by handler
        """
        response = JsonRPCResponseMessage(id=msg_id,
                                          jsonrpc=JsonRPCProtocol.VERSION,
                                          result=result,
                                          error=error)

        if error is None:
            del response.error
        else:
            del response.result

        self._send_data(response)