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
def test_compatibility_is_not_unicode(self): x = '' self.assertFalse(compatibility.is_unicode(x))
def test_compatibility_is_unicode(self): x = u'Mor, lilla mor, vem är väl som du' self.assertTrue(compatibility.is_unicode(x))
def test_is_not_unicode(self): x = "" self.assertFalse(compatibility.is_unicode(x))
def test_is_unicode(self): x = unicode("") self.assertTrue(compatibility.is_unicode(x))