mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #1548891: The cStringIO.StringIO() constructor now encodes unicode
arguments with the system default encoding just like the write() method does, instead of converting it to a raw buffer.
This commit is contained in:
parent
f678e82240
commit
5a77fe92bd
4 changed files with 31 additions and 5 deletions
|
@ -134,6 +134,27 @@ class TestcStringIO(TestGenericStringIO):
|
|||
f = self.MODULE.StringIO(a)
|
||||
self.assertEqual(f.getvalue(), '\x00\x01\x02')
|
||||
|
||||
def test_unicode(self):
|
||||
|
||||
if not test_support.have_unicode: return
|
||||
|
||||
# The cStringIO module converts Unicode strings to character
|
||||
# strings when writing them to cStringIO objects.
|
||||
# Check that this works.
|
||||
|
||||
f = self.MODULE.StringIO()
|
||||
f.write(u'abcde')
|
||||
s = f.getvalue()
|
||||
self.assertEqual(s, 'abcde')
|
||||
self.assertEqual(type(s), str)
|
||||
|
||||
f = self.MODULE.StringIO(u'abcde')
|
||||
s = f.getvalue()
|
||||
self.assertEqual(s, 'abcde')
|
||||
self.assertEqual(type(s), str)
|
||||
|
||||
self.assertRaises(UnicodeEncodeError, self.MODULE.StringIO, u'\xf4')
|
||||
|
||||
|
||||
import sys
|
||||
if sys.platform.startswith('java'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue