From 2233d27a3f9c946a1c9e3a7dd45728d819170bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Fri, 22 Jun 2007 12:17:08 +0000 Subject: [PATCH] Change readbuffer_encode() and charbuffer_encode() to return bytes objects. --- Lib/test/test_codecs.py | 10 +++++----- Modules/_codecsmodule.c | 12 ++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 666f0dff95c..89a3473d287 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -422,12 +422,12 @@ class ReadBufferTest(unittest.TestCase): def test_array(self): import array self.assertEqual( - codecs.readbuffer_encode(array.array("c", "spam")), - ("spam", 4) + codecs.readbuffer_encode(array.array("b", bytes("spam"))), + (b"spam", 4) ) def test_empty(self): - self.assertEqual(codecs.readbuffer_encode(""), ("", 0)) + self.assertEqual(codecs.readbuffer_encode(""), (b"", 0)) def test_bad_args(self): self.assertRaises(TypeError, codecs.readbuffer_encode) @@ -436,10 +436,10 @@ class ReadBufferTest(unittest.TestCase): class CharBufferTest(unittest.TestCase): 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): - self.assertEqual(codecs.charbuffer_encode(""), ("", 0)) + self.assertEqual(codecs.charbuffer_encode(""), (b"", 0)) def test_bad_args(self): self.assertRaises(TypeError, codecs.charbuffer_encode) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index de5270d6076..119967154ca 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -533,8 +533,7 @@ readbuffer_encode(PyObject *self, &data, &size, &errors)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), - size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } static PyObject * @@ -549,8 +548,7 @@ charbuffer_encode(PyObject *self, &data, &size, &errors)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), - size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } static PyObject * @@ -569,14 +567,12 @@ unicode_internal_encode(PyObject *self, if (PyUnicode_Check(obj)) { data = PyUnicode_AS_DATA(obj); size = PyUnicode_GET_DATA_SIZE(obj); - return codec_tuple(PyString_FromStringAndSize(data, size), - size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } else { if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), - size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } }