summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-17 23:59:11 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-17 23:59:11 (GMT)
commit024da5c2576f196dede4bfa0fc5808019bd54fd8 (patch)
tree5ddf497e06e42dac48d3d17ee288332b0a956296 /Modules/cjkcodecs
parentf4cfc8f6bb47e77ca954b58b436f2157b5b6f530 (diff)
downloadcpython-024da5c2576f196dede4bfa0fc5808019bd54fd8.zip
cpython-024da5c2576f196dede4bfa0fc5808019bd54fd8.tar.gz
cpython-024da5c2576f196dede4bfa0fc5808019bd54fd8.tar.bz2
Make all the multibyte codec tests pass.
Changes to io.py, necessary to make this work: - Redid io.StringIO as a TextIOWrapper on top of a BytesIO instance. - Got rid of _MemoryIOMixin, folding it into BytesIO instead. - The read() functions that take -1 to mean "eveything" now also take None. - Added readline() support to BufferedIOBase. :-(
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/multibytecodec.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index b26d38e..dae82b7 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -138,6 +138,11 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
{
PyObject *cb;
+ if (PyUnicode_Check(value)) {
+ value = _PyUnicode_AsDefaultEncodedString(value, NULL);
+ if (value == NULL)
+ return -1;
+ }
if (!PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, "errors must be a string");
return -1;
@@ -322,11 +327,11 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto errorexit;
}
- assert(PyString_Check(retstr));
- retstrsize = PyString_GET_SIZE(retstr);
+ assert(PyBytes_Check(retstr));
+ retstrsize = PyBytes_GET_SIZE(retstr);
REQUIRE_ENCODEBUFFER(buf, retstrsize);
- memcpy(buf->outbuf, PyString_AS_STRING(retstr), retstrsize);
+ memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize);
buf->outbuf += retstrsize;
newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
@@ -1224,10 +1229,18 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if (cres == NULL)
goto errorexit;
+ if (PyString_Check(cres)) {
+ PyObject *cres2 = PyBytes_FromObject(cres);
+ if (cres2 == NULL)
+ return NULL;
+ Py_DECREF(cres);
+ cres = cres2;
+ }
+
if (!PyBytes_Check(cres)) {
PyErr_Format(PyExc_TypeError,
"stream function returned a "
- "non-string object (%.100s)",
+ "non-bytes object (%.100s)",
cres->ob_type->tp_name);
goto errorexit;
}
@@ -1596,8 +1609,8 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
if (pwrt == NULL)
return NULL;
- assert(PyString_Check(pwrt));
- if (PyString_Size(pwrt) > 0) {
+ assert(PyBytes_Check(pwrt));
+ if (PyBytes_Size(pwrt) > 0) {
PyObject *wr;
wr = PyObject_CallMethod(self->stream, "write", "O", pwrt);
if (wr == NULL) {