コード例 #1
0
 def on_message(self, raw):
     """Triggered when a message is received from the broker child."""
     message, reason = Message.check_message(raw)
     if message is not None:
         self.application.on_gateway_message(self, message)
     else:
         logger.debug("Invalid message, closing websocket")
         self.close(code=1003, reason="{}.".format(reason))
コード例 #2
0
 def on_message(self, raw):
     """Triggered when a message is received from the web client."""
     message, reason = Message.check_message(raw)
     if message is not None:
         message.update({'src': self.uid})
         self.application.on_client_message(self, message)
     else:
         logger.debug("Invalid message, closing websocket")
         self.close(code=1003, reason="{}.".format(reason))
コード例 #3
0
 def on_message(self, raw):
     """Triggered when a message is received from the broker child."""
     if not self.authentified:
         if verify_auth_token(raw, self.application.keys):
             logger.info("Gateway websocket authentication verified")
             self.authentified = True
             self.application.gateways.update({self: []})
         else:
             logger.info("Gateway websocket authentication failed, "
                         "closing.")
             self.close()
     else:
         message, reason = Message.check_message(raw)
         if message is not None:
             self.application.on_gateway_message(self, message)
         else:
             logger.debug("Invalid message, closing websocket")
             self.close(code=1003, reason="{}.".format(reason))
コード例 #4
0
ファイル: test_messaging.py プロジェクト: rfuentess/pyaiot
def test_check_message_valid(msg_type):
    to_test = json.dumps({"type": msg_type, "data": "test"})
    message, reason = Message.check_message(to_test)
    assert message is not None
    assert reason is None
コード例 #5
0
ファイル: test_messaging.py プロジェクト: rfuentess/pyaiot
def test_check_message_bad_type():
    message, reason = Message.check_message('{"type": "test"}')
    assert message is None
    assert "Invalid message type" in reason
コード例 #6
0
ファイル: test_messaging.py プロジェクト: rfuentess/pyaiot
def test_check_message_bad_json(badvalue):
    message, reason = Message.check_message(badvalue)
    assert message is None
    assert "Invalid message " in reason