def _route_message(self, message, data):
        """ Route message to any handlers on the message namespace """
        # route message to handlers
        if message.namespace in self._handlers:

            # debug messages
            if message.namespace != NS_HEARTBEAT:
                self.logger.debug(
                    "Received: %s", _message_to_string(message, data))

            # message handlers
            try:
                handled = \
                    self._handlers[message.namespace].receive_message(
                        message, data)

                if not handled:
                    if data.get(REQUEST_ID) not in self._request_callbacks:
                        self.logger.debug(
                            "Message unhandled: %s",
                            _message_to_string(message, data))
            except Exception:  # pylint: disable=broad-except
                self.logger.exception(
                    (u"Exception caught while sending message to "
                     u"controller %s: %s"),
                    type(self._handlers[message.namespace]).__name__,
                    _message_to_string(message, data))

        else:
            self.logger.debug(
                "Received unknown namespace: %s",
                _message_to_string(message, data))
dataset/ETHPy150Open balloob/pychromecast/pychromecast/socket_client.py/SocketClient._route_message/original