예제 #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))