Index: Lib/test/test_codecs.py =================================================================== --- Lib/test/test_codecs.py (revision 58845) +++ Lib/test/test_codecs.py (working copy) @@ -1265,7 +1265,9 @@ encodedresult = b"" for c in s: writer.write(c) - encodedresult += q.read() + chunk = q.read() + assert type(chunk) is bytes + encodedresult += chunk q = Queue(b"") reader = codecs.getreader(encoding)(q) decodedresult = "" Index: Lib/test/test_multibytecodec_support.py =================================================================== --- Lib/test/test_multibytecodec_support.py (revision 58845) +++ Lib/test/test_multibytecodec_support.py (working copy) @@ -52,6 +52,10 @@ func = self.encode if expected: result = func(source, scheme)[0] + if func is self.decode: + assert type(result) is str + else: + assert type(result) is bytes self.assertEqual(result, expected) else: self.assertRaises(UnicodeError, func, source, scheme) Index: Modules/cjkcodecs/multibytecodec.c =================================================================== --- Modules/cjkcodecs/multibytecodec.c (revision 58845) +++ Modules/cjkcodecs/multibytecodec.c (working copy) @@ -175,15 +175,15 @@ Py_ssize_t orgpos, orgsize; orgpos = (Py_ssize_t)((char *)buf->outbuf - - PyBytes_AS_STRING(buf->outobj)); - orgsize = PyBytes_GET_SIZE(buf->outobj); - if (PyBytes_Resize(buf->outobj, orgsize + ( + PyString_AS_STRING(buf->outobj)); + orgsize = PyString_GET_SIZE(buf->outobj); + if (_PyString_Resize(&buf->outobj, orgsize + ( esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1) return -1; - buf->outbuf = (unsigned char *)PyBytes_AS_STRING(buf->outobj) +orgpos; - buf->outbuf_end = (unsigned char *)PyBytes_AS_STRING(buf->outobj) - + PyBytes_GET_SIZE(buf->outobj); + buf->outbuf = (unsigned char *)PyString_AS_STRING(buf->outobj) +orgpos; + buf->outbuf_end = (unsigned char *)PyString_AS_STRING(buf->outobj) + + PyString_GET_SIZE(buf->outobj); return 0; } @@ -330,11 +330,11 @@ goto errorexit; } - assert(PyBytes_Check(retstr)); - retstrsize = PyBytes_GET_SIZE(retstr); + assert(PyString_Check(retstr)); + retstrsize = PyString_GET_SIZE(retstr); REQUIRE_ENCODEBUFFER(buf, retstrsize); - memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize); + memcpy(buf->outbuf, PyString_AS_STRING(retstr), retstrsize); buf->outbuf += retstrsize; newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); @@ -476,16 +476,16 @@ Py_ssize_t finalsize, r = 0; if (datalen == 0) - return PyBytes_FromStringAndSize(NULL, 0); + return PyString_FromStringAndSize(NULL, 0); buf.excobj = NULL; buf.inbuf = buf.inbuf_top = *data; buf.inbuf_end = buf.inbuf_top + datalen; - buf.outobj = PyBytes_FromStringAndSize(NULL, datalen * 2 + 16); + buf.outobj = PyString_FromStringAndSize(NULL, datalen * 2 + 16); if (buf.outobj == NULL) goto errorexit; - buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj); - buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj); + buf.outbuf = (unsigned char *)PyString_AS_STRING(buf.outobj); + buf.outbuf_end = buf.outbuf + PyString_GET_SIZE(buf.outobj); while (buf.inbuf < buf.inbuf_end) { Py_ssize_t inleft, outleft; @@ -520,10 +520,10 @@ } finalsize = (Py_ssize_t)((char *)buf.outbuf - - PyBytes_AS_STRING(buf.outobj)); + PyString_AS_STRING(buf.outobj)); - if (finalsize != PyBytes_GET_SIZE(buf.outobj)) - if (PyBytes_Resize(buf.outobj, finalsize) == -1) + if (finalsize != PyString_GET_SIZE(buf.outobj)) + if (_PyString_Resize(&buf.outobj, finalsize) == -1) goto errorexit; Py_XDECREF(buf.excobj); @@ -1611,8 +1611,8 @@ if (pwrt == NULL) return NULL; - assert(PyBytes_Check(pwrt)); - if (PyBytes_Size(pwrt) > 0) { + assert(PyString_Check(pwrt)); + if (PyString_Size(pwrt) > 0) { PyObject *wr; wr = PyObject_CallMethod(self->stream, "write", "O", pwrt); if (wr == NULL) { Index: Modules/_codecsmodule.c =================================================================== --- Modules/_codecsmodule.c (revision 58845) +++ Modules/_codecsmodule.c (working copy) @@ -180,7 +180,7 @@ "string is too large to encode"); return NULL; } - v = PyBytes_FromStringAndSize(NULL, newsize); + v = PyString_FromStringAndSize(NULL, newsize); if (v == NULL) { return NULL; @@ -188,11 +188,11 @@ else { register Py_ssize_t i; register char c; - register char *p = PyBytes_AS_STRING(v); + register char *p = PyString_AS_STRING(v); for (i = 0; i < size; i++) { /* There's at least enough room for a hex escape */ - assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); + assert(newsize - (p - PyString_AS_STRING(v)) >= 4); c = PyString_AS_STRING(str)[i]; if (c == '\'' || c == '\\') *p++ = '\\', *p++ = c; @@ -212,13 +212,13 @@ *p++ = c; } *p = '\0'; - if (PyBytes_Resize(v, (p - PyBytes_AS_STRING(v)))) { + if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) { Py_DECREF(v); return NULL; } } - return codec_tuple(v, PyBytes_Size(v)); + return codec_tuple(v, PyString_Size(v)); } /* --- Decoder ------------------------------------------------------------ */ @@ -654,7 +654,7 @@ &data, &size, &errors)) return NULL; - return codec_tuple(PyBytes_FromStringAndSize(data, size), size); + return codec_tuple(PyString_FromStringAndSize(data, size), size); } static PyObject * @@ -669,7 +669,7 @@ &data, &size, &errors)) return NULL; - return codec_tuple(PyBytes_FromStringAndSize(data, size), size); + return codec_tuple(PyString_FromStringAndSize(data, size), size); } static PyObject * @@ -688,12 +688,12 @@ if (PyUnicode_Check(obj)) { data = PyUnicode_AS_DATA(obj); size = PyUnicode_GET_DATA_SIZE(obj); - return codec_tuple(PyBytes_FromStringAndSize(data, size), size); + return codec_tuple(PyString_FromStringAndSize(data, size), size); } else { if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) return NULL; - return codec_tuple(PyBytes_FromStringAndSize(data, size), size); + return codec_tuple(PyString_FromStringAndSize(data, size), size); } }