Ejemplo n.º 1
0
    def on_message(self, message):
        """Process messages when they arrive.

        :param str message:
            The received message. This should be a valid
            json document.
        """
        try:
            # Throws ValueError
            message = json.loads(message)

            self.ws_pub_sub.execute_actions(message)

        except NoActionForMsgTypeError:
            self.send_error(
                'noActionForMsgType',
                message,
                "The client has sent a message for which "
                "there is no associated action."
            )
            msg.no_action_for_msg_type(_path, message)

        except (NotDictError, NoMessageTypeError,
                ValueError):
            self.send_malformed_message_error(message)
            msg.malformed_message(_path, message)
Ejemplo n.º 2
0
    def send_user_message(self, message):
        """Send a message to all instances of a single user.

        The user id is appended to the message type and
        ``message`` is sent through the database.

        .. todo::
            *   Change the message type of the subscription
                to be organised by namespace.
            *   Change this method so that it uses
                self.handler.user_msg_type.
        """
        try:
            message['type'] = '{}({})'.format(
                message['type'], self.handler.user.id)

            self.redirect_to('d', message)

        except MalformedMessageError:
            self.handler.send_malformed_message_error(
                message)
            msg.malformed_message(_path, message)

        except AttributeError:
            if not hasattr(self.handler, 'user'):
                self.handler.send_user_not_loaded_error(
                    message)
            else:
                raise
Ejemplo n.º 3
0
    def send_user_message(self, message):
        """Send a message to all instances of a single user.

        The user id is appended to the message type and
        ``message`` is sent through the database.

        .. todo::
            *   Change the message type of the subscription
                to be organised by namespace.
            *   Change this method so that it uses
                self.handler.user_msg_type.
        """
        try:
            message['type'] = '{}({})'.format(message['type'],
                                              self.handler.user.id)

            self.redirect_to('d', message)

        except MalformedMessageError:
            self.handler.send_malformed_message_error(message)
            msg.malformed_message(_path, message)

        except AttributeError:
            if not hasattr(self.handler, 'user'):
                self.handler.send_user_not_loaded_error(message)
            else:
                raise
Ejemplo n.º 4
0
    def send_user_message(self, message):
        """Send a message to all instances of a single user.

        The user id is appended to the message type and
        ``message`` is sent through the database.
        """
        try:
            message['type'] = '{}({})'.format(
                message['type'], self.handler.user.id)

            self.redirect_to('d', message)

        except MalformedMessageError:
            self.handler.send_malformed_message_error(
                message)
            msg.malformed_message(_path, message)

        except AttributeError:
            if not hasattr(self.handler, 'user'):
                self.handler.send_user_not_loaded_error(
                    message)
            else:
                raise
Ejemplo n.º 5
0
    def on_message(self, message):
        """Process messages when they arrive.

        :param str message:
            The received message. This should be a valid
            json document.
        """
        try:
            # Throws ValueError
            message = json.loads(message)

            self.ws_pub_sub.execute_actions(message)

        except NoActionForMsgTypeError:
            self.send_error(
                'noActionForMsgType', message,
                "The client has sent a message for which "
                "there is no associated action.")
            msg.no_action_for_msg_type(_path, message)

        except (NotDictError, NoMessageTypeError, ValueError):
            self.send_malformed_message_error(message)
            msg.malformed_message(_path, message)