예제 #1
0
    def process(self):
        """
        Call method defined in tornwamp.customize.procedures (dict).

        Each method should return:
        - RESPONSE
        - ERROR

        Which will be the processor's answer message.'
        """
        msg = CallMessage(*self.message.value)
        direct_messages = []
        method_name = msg.procedure
        if (method_name in customize.procedures):
            method = customize.procedures[method_name]
            answer, direct_messages = method(*msg.args,
                                             call_message=msg,
                                             connection=self.connection,
                                             **msg.kwargs)
        else:
            error_uri = "wamp.rpc.unsupported.procedure"
            error_msg = "The procedure {} doesn't exist".format(method_name)
            response_msg = ErrorMessage(request_code=msg.code,
                                        request_id=msg.request_id,
                                        details={"call": msg.json},
                                        uri=error_uri)
            response_msg.error(error_msg)
            answer = response_msg
        self.answer_message = answer
        self.direct_messages = direct_messages
예제 #2
0
파일: __init__.py 프로젝트: ef-ctx/tornwamp
    def process(self):
        """
        Call method defined in tornwamp.customize.procedures (dict).

        Each method should return:
        - RESPONSE
        - ERROR

        Which will be the processor's answer message.'
        """
        msg = CallMessage(*self.message.value)
        method_name = msg.procedure
        if (method_name in customize.procedures):
            method = customize.procedures[method_name]
            answer, self.broadcast_messages = method(*msg.args, call_message=msg, connection=self.connection, **msg.kwargs)
        else:
            error_uri = "wamp.rpc.unsupported.procedure"
            error_msg = "The procedure {} doesn't exist".format(method_name)
            response_msg = ErrorMessage(
                request_code=msg.code,
                request_id=msg.request_id,
                details={"call": msg.json},
                uri=error_uri
            )
            response_msg.error(error_msg)
            answer = response_msg
        self.answer_message = answer
예제 #3
0
 def process(self):
     message = Message(*self.message.value)
     description = "Unsupported message {0}".format(self.message.value)
     out_message = ErrorMessage(request_code=message.code,
                                request_id=message.id,
                                uri='wamp.unsupported.message')
     out_message.error(description)
     self.answer_message = out_message
예제 #4
0
파일: __init__.py 프로젝트: ef-ctx/tornwamp
 def process(self):
     message = Message(*self.message.value)
     description = "Unsupported message {0}".format(self.message.value)
     out_message = ErrorMessage(
         request_code=message.code,
         request_id=message.id,
         uri='wamp.unsupported.message'
     )
     out_message.error(description)
     self.answer_message = out_message
예제 #5
0
 def process(self):
     """
     Return SUBSCRIBE message based on the input HELLO message.
     """
     received_message = PublishMessage(*self.message.value)
     allow, msg = customize.authorize_publication(received_message.topic, self.connection)
     answer = None
     if allow:
         publication_id = create_global_id()
         if received_message.options.get("acknowledge"):
             answer = PublishedMessage(
                 request_id=received_message.request_id,
                 publication_id=publication_id
             )
         self.direct_messages = customize.get_publish_direct_messages(
             received_message,
             publication_id,
             self.connection
         )
     else:
         answer = ErrorMessage(
             request_id=received_message.request_id,
             request_code=received_message.code,
             uri="tornwamp.publish.unauthorized"
         )
         answer.error(msg)
     self.answer_message = answer
예제 #6
0
 def test_use_customized_message_if_available(self):
     options = {"acknowledge": True}
     expected_answer = ErrorMessage(
         request_id=345,
         request_code=16,
         uri="something.is.wrong"
     )
     def error(*args, **kwargs):
         return None, expected_answer
     customize.get_publish_messages = error
     message = PublishMessage(request_id=345, topic="world.cup", options=options)
     connection = ClientConnection(None)
     processor = PublishProcessor(message, connection)
     answer = processor.answer_message
     self.assertEqual(answer, expected_answer)
예제 #7
0
 def process(self):
     """
     Return SUBSCRIBE message based on the input HELLO message.
     """
     received_message = SubscribeMessage(*self.message.value)
     allow, msg = customize.authorize_subscription(received_message.topic, self.connection)
     if allow:
         subscription_id = customize.add_subscriber(received_message.topic, self.connection)
         answer = SubscribedMessage(
             request_id=received_message.request_id,
             subscription_id=subscription_id
         )
         self.direct_messages = customize.get_subscribe_direct_messages(received_message, subscription_id)
     else:
         answer = ErrorMessage(
             request_id=received_message.request_id,
             request_code=received_message.code,
             uri="tornwamp.subscribe.unauthorized"
         )
         answer.error(msg)
     self.answer_message = answer