summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-02 16:21:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-12-02 16:21:02 (GMT)
commit26e5335a46f34944da7fd20ab8b1574fae6a5585 (patch)
treea4882123d64823f69311b4fef8c4d73f1162d5d4 /Modules/cjkcodecs
parent3d490d4eff6980ab1577db5567d0ab457aa0c501 (diff)
parent47a00f3d1a1fe3774d92e5d9263ef3bff79dd4ac (diff)
downloadcpython-26e5335a46f34944da7fd20ab8b1574fae6a5585.zip
cpython-26e5335a46f34944da7fd20ab8b1574fae6a5585.tar.gz
cpython-26e5335a46f34944da7fd20ab8b1574fae6a5585.tar.bz2
merge 3.3 (#16585)
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/multibytecodec.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 40717d8..c032cdb 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -316,7 +316,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto errorexit;
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
- !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) ||
+ (!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) && !PyBytes_Check(tobj)) ||
!PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) {
PyErr_SetString(PyExc_TypeError,
"encoding error handler must return "
@@ -324,7 +324,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto errorexit;
}
- {
+ if (PyUnicode_Check(tobj)) {
const Py_UNICODE *uraw = PyUnicode_AS_UNICODE(tobj);
retstr = multibytecodec_encode(codec, state, &uraw,
@@ -333,6 +333,10 @@ multibytecodec_encerror(MultibyteCodec *codec,
if (retstr == NULL)
goto errorexit;
}
+ else {
+ Py_INCREF(tobj);
+ retstr = tobj;
+ }
assert(PyBytes_Check(retstr));
retstrsize = PyBytes_GET_SIZE(retstr);