How to use the amqpstorm.compatibility.try_utf8_decode function in AMQPStorm

To help you get started, we’ve selected a few AMQPStorm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eandersson / amqpstorm / tests / compatiblity_tests.py View on Github external
def test_compatibility_try_utf8_decode_on_integer(self):
        x = 5
        self.assertEqual(x, compatibility.try_utf8_decode(x))
github eandersson / amqpstorm / tests / compatiblity_tests.py View on Github external
def test_compatibility_try_utf8_decode_on_dict(self):
        x = dict(hello='world')
        self.assertEqual(x, compatibility.try_utf8_decode(x))
github fake-name / ReadableWebProxy / amqpstorm / channel.py View on Github external
def _basic_return(self, frame_in):
        """Handle a Basic Return Frame and treat it as an error.

        :param specification.Basic.Return frame_in: Amqp frame.
        :return:
        """
        reply_text = try_utf8_decode(frame_in.reply_text)
        message = (
            "Message not delivered: %s (%s) to queue '%s' from exchange '%s'" %
            (
                reply_text,
                frame_in.reply_code,
                frame_in.routing_key,
                frame_in.exchange
            )
        )
        exception = AMQPMessageError(message,
                                     reply_code=frame_in.reply_code)
        self.exceptions.append(exception)
github eandersson / amqpstorm / amqpstorm / channel0.py View on Github external
def _send_start_ok(self, frame_in):
        """Send Start OK frame.

        :param specification.Connection.Start frame_in: Amqp frame.
        :return:
        """
        mechanisms = try_utf8_decode(frame_in.mechanisms)
        if 'EXTERNAL' in mechanisms:
            mechanism = 'EXTERNAL'
            credentials = '\0\0'
        elif 'PLAIN' in mechanisms:
            mechanism = 'PLAIN'
            credentials = self._plain_credentials()
        else:
            exception = AMQPConnectionError(
                'Unsupported Security Mechanism(s): %s' %
                frame_in.mechanisms
            )
            self._connection.exceptions.append(exception)
            return
        start_ok_frame = specification.Connection.StartOk(
            mechanism=mechanism,
            client_properties=self._client_properties(),
github eandersson / amqpstorm / amqpstorm / channel0.py View on Github external
def _close_connection(self, frame_in):
        """Connection Close.

        :param specification.Connection.Close frame_in: Amqp frame.
        :return:
        """
        self._set_connection_state(Stateful.CLOSED)
        if frame_in.reply_code != 200:
            reply_text = try_utf8_decode(frame_in.reply_text)
            message = (
                'Connection was closed by remote server: %s' % reply_text
            )
            exception = AMQPConnectionError(message,
                                            reply_code=frame_in.reply_code)
            self._connection.exceptions.append(exception)
github eandersson / amqpstorm / amqpstorm / channel.py View on Github external
def _basic_cancel(self, frame_in):
        """Handle a Basic Cancel frame.

        :param specification.Basic.Cancel frame_in: Amqp frame.

        :return:
        """
        LOGGER.warning(
            'Received Basic.Cancel on consumer_tag: %s',
            try_utf8_decode(frame_in.consumer_tag)
        )
        self.remove_consumer_tag(frame_in.consumer_tag)
github eandersson / amqpstorm / amqpstorm / message.py View on Github external
def _try_decode_dict(self, content):
        """Decode content of a dictionary.

        :param dict content:
        :return:
        """
        result = dict()
        for key, value in content.items():
            key = try_utf8_decode(key)
            if isinstance(value, dict):
                result[key] = self._try_decode_dict(value)
            elif isinstance(value, list):
                result[key] = self._try_decode_list(value)
            elif isinstance(value, tuple):
                result[key] = self._try_decode_tuple(value)
            else:
                result[key] = try_utf8_decode(value)
        return result
github eandersson / amqpstorm / amqpstorm / channel.py View on Github external
def _close_channel(self, frame_in):
        """Close Channel.

        :param specification.Channel.Close frame_in: Channel Close frame.
        :return:
        """
        self.set_state(self.CLOSED)
        self.remove_consumer_tag()
        if self._inbound:
            del self._inbound[:]
        self.exceptions.append(AMQPChannelError(
            'Channel %d was closed by remote server: %s' %
            (
                self._channel_id,
                try_utf8_decode(frame_in.reply_text)
            ),
            reply_code=frame_in.reply_code
        ))
github eandersson / amqpstorm / amqpstorm / message.py View on Github external
def _try_decode_utf8_content(self, content, content_type):
        """Generic function to decode content.

        :param object content:
        :return:
        """
        if not self._auto_decode or not content:
            return content
        if content_type in self._decode_cache:
            return self._decode_cache[content_type]
        if isinstance(content, dict):
            content = self._try_decode_dict(content)
        else:
            content = try_utf8_decode(content)
        self._decode_cache[content_type] = content
        return content