Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
0
 def test_compatibility_is_not_unicode(self):
     x = ''
     self.assertFalse(compatibility.is_unicode(x))
Ejemplo n.º 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))
Ejemplo n.º 5
0
 def test_is_not_unicode(self):
     x = ""
     self.assertFalse(compatibility.is_unicode(x))
Ejemplo n.º 6
0
 def test_is_unicode(self):
     x = unicode("")
     self.assertTrue(compatibility.is_unicode(x))