Commit 2233d27a authored by Walter Dörwald's avatar Walter Dörwald

Change readbuffer_encode() and charbuffer_encode() to

return bytes objects.
parent 63a28be0
...@@ -422,12 +422,12 @@ class ReadBufferTest(unittest.TestCase): ...@@ -422,12 +422,12 @@ class ReadBufferTest(unittest.TestCase):
def test_array(self): def test_array(self):
import array import array
self.assertEqual( self.assertEqual(
codecs.readbuffer_encode(array.array("c", "spam")), codecs.readbuffer_encode(array.array("b", bytes("spam"))),
("spam", 4) (b"spam", 4)
) )
def test_empty(self): def test_empty(self):
self.assertEqual(codecs.readbuffer_encode(""), ("", 0)) self.assertEqual(codecs.readbuffer_encode(""), (b"", 0))
def test_bad_args(self): def test_bad_args(self):
self.assertRaises(TypeError, codecs.readbuffer_encode) self.assertRaises(TypeError, codecs.readbuffer_encode)
...@@ -436,10 +436,10 @@ class ReadBufferTest(unittest.TestCase): ...@@ -436,10 +436,10 @@ class ReadBufferTest(unittest.TestCase):
class CharBufferTest(unittest.TestCase): class CharBufferTest(unittest.TestCase):
def test_string(self): def test_string(self):
self.assertEqual(codecs.charbuffer_encode("spam"), ("spam", 4)) self.assertEqual(codecs.charbuffer_encode("spam"), (b"spam", 4))
def test_empty(self): def test_empty(self):
self.assertEqual(codecs.charbuffer_encode(""), ("", 0)) self.assertEqual(codecs.charbuffer_encode(""), (b"", 0))
def test_bad_args(self): def test_bad_args(self):
self.assertRaises(TypeError, codecs.charbuffer_encode) self.assertRaises(TypeError, codecs.charbuffer_encode)
......
...@@ -533,8 +533,7 @@ readbuffer_encode(PyObject *self, ...@@ -533,8 +533,7 @@ readbuffer_encode(PyObject *self,
&data, &size, &errors)) &data, &size, &errors))
return NULL; return NULL;
return codec_tuple(PyString_FromStringAndSize(data, size), return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
size);
} }
static PyObject * static PyObject *
...@@ -549,8 +548,7 @@ charbuffer_encode(PyObject *self, ...@@ -549,8 +548,7 @@ charbuffer_encode(PyObject *self,
&data, &size, &errors)) &data, &size, &errors))
return NULL; return NULL;
return codec_tuple(PyString_FromStringAndSize(data, size), return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
size);
} }
static PyObject * static PyObject *
...@@ -569,14 +567,12 @@ unicode_internal_encode(PyObject *self, ...@@ -569,14 +567,12 @@ unicode_internal_encode(PyObject *self,
if (PyUnicode_Check(obj)) { if (PyUnicode_Check(obj)) {
data = PyUnicode_AS_DATA(obj); data = PyUnicode_AS_DATA(obj);
size = PyUnicode_GET_DATA_SIZE(obj); size = PyUnicode_GET_DATA_SIZE(obj);
return codec_tuple(PyString_FromStringAndSize(data, size), return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
size);
} }
else { else {
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
return NULL; return NULL;
return codec_tuple(PyString_FromStringAndSize(data, size), return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
size);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment