Exemplo n.º 1
0
 def test_python_crash(self):
     import random
     from io import BytesIO
     random.seed(42)
     buf = BytesIO()
     for i in range(150000):
         buf.write(bytes([random.randint(0, 255)]))
     to_unicode(buf.getvalue(), 'utf-16-le')
     to_unicode(buf.getvalue(), 'utf-16-be')
     to_unicode(buf.getvalue(), 'utf-32-le')
     to_unicode(buf.getvalue(), 'utf-32-be')
Exemplo n.º 2
0
 def test_python_crash(self):
     import random
     from io import BytesIO
     random.seed(42)
     buf = BytesIO()
     for i in range(150000):
         buf.write(bytes([random.randint(0, 255)]))
     to_unicode(buf.getvalue(), 'utf-16-le')
     to_unicode(buf.getvalue(), 'utf-16-be')
     to_unicode(buf.getvalue(), 'utf-32-le')
     to_unicode(buf.getvalue(), 'utf-32-be')
Exemplo n.º 3
0
 def test_invalid_utf8(self):
     self.assertEqual(to_unicode(b'\xc2\xc2\xa3', 'utf-8'), u'\ufffd\xa3')
Exemplo n.º 4
0
 def test_utf8(self):
     self.assertEqual(to_unicode(b'\xc2\xa3', 'utf-8'), u'\xa3')
def bytes_to_unicode(bytes, encoding):
    """
	将给定的bytes,通过encoding转换成unicode
	"""
    return to_unicode(bytes, encoding)
Exemplo n.º 6
0
 def body_as_unicode(self):
     """Return body as unicode"""
     if self._cached_ubody is None:
         self._cached_ubody = to_unicode(self.body, self.encoding)
     return self._cached_ubody
Exemplo n.º 7
0
 def test_invalid_utf8(self):
     self.assertEqual(to_unicode('\xc2\xc2\xa3', 'utf-8'), u'\ufffd\xa3')
Exemplo n.º 8
0
 def test_utf8(self):
     self.assertEqual(to_unicode('\xc2\xa3', 'utf-8'), u'\xa3')
Exemplo n.º 9
0
 def body_as_unicode(self):
     """Return body as unicode"""
     if self._cached_ubody is None:
         self._cached_ubody = to_unicode(self.body, self.encoding)
     return self._cached_ubody
Exemplo n.º 10
0
 def test_invalid_utf8(self):
     self.assertEqual(to_unicode(b"\xc2\xc2\xa3", "utf-8"), "\ufffd\xa3")
Exemplo n.º 11
0
 def test_utf8(self):
     self.assertEqual(to_unicode(b"\xc2\xa3", "utf-8"), "\xa3")