コード例 #1
0
ファイル: basic.py プロジェクト: exg77/amqpstorm
    def _handle_utf8_payload(body, properties):
        """Update the Body and Properties to the appropriate encoding.

        :param str|unicode body:
        :param dict properties:
        :return:
        """
        if compatibility.is_unicode(body):
            if 'content_encoding' not in properties:
                properties['content_encoding'] = 'utf-8'
            encoding = properties['content_encoding']
            body = body.encode(encoding)
        elif compatibility.PYTHON3 and isinstance(body, str):
            body = bytes(body, encoding='utf-8')
        return body
コード例 #2
0
    def _handle_utf8_payload(body, properties):
        """Update the Body and Properties to the appropriate encoding.

        :param str|unicode body:
        :param dict properties:
        :return:
        """
        if compatibility.is_unicode(body):
            if 'content_encoding' not in properties:
                properties['content_encoding'] = 'utf-8'
            encoding = properties['content_encoding']
            body = body.encode(encoding)
        elif compatibility.PYTHON3 and isinstance(body, str):
            body = bytes(body, encoding='utf-8')
        return body
コード例 #3
0
 def test_compatibility_is_not_unicode(self):
     x = ''
     self.assertFalse(compatibility.is_unicode(x))
コード例 #4
0
 def test_compatibility_is_unicode(self):
     x = u'Mor, lilla mor, vem är väl som du'
     self.assertTrue(compatibility.is_unicode(x))
コード例 #5
0
 def test_is_not_unicode(self):
     x = ""
     self.assertFalse(compatibility.is_unicode(x))
コード例 #6
0
 def test_is_unicode(self):
     x = unicode("")
     self.assertTrue(compatibility.is_unicode(x))