summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-26 04:19:43 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-26 04:19:43 (GMT)
commit6ea45d33412d4ecb2862645d57137b7ea1223281 (patch)
tree90a60a1298fff16a71f2501e87613385624a52d9 /Modules/cjkcodecs
parent5b0fdc9d0aef58fffe225bee493d62cd905d6b80 (diff)
downloadcpython-6ea45d33412d4ecb2862645d57137b7ea1223281.zip
cpython-6ea45d33412d4ecb2862645d57137b7ea1223281.tar.gz
cpython-6ea45d33412d4ecb2862645d57137b7ea1223281.tar.bz2
Use unicode and remove support for some uses of str8.
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h11
-rw-r--r--Modules/cjkcodecs/multibytecodec.c26
2 files changed, 19 insertions, 18 deletions
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index c79b304..9449c1f 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -261,22 +261,19 @@ getcodec(PyObject *self, PyObject *encoding)
const MultibyteCodec *codec;
const char *enc;
- if (PyUnicode_Check(encoding)) {
- encoding = _PyUnicode_AsDefaultEncodedString(encoding, NULL);
- if (encoding == NULL)
- return NULL;
- }
- if (!PyString_Check(encoding)) {
+ if (!PyUnicode_Check(encoding)) {
PyErr_SetString(PyExc_TypeError,
"encoding name must be a string.");
return NULL;
}
+ enc = PyUnicode_AsString(encoding, NULL);
+ if (enc == NULL)
+ return NULL;
cofunc = getmultibytecodec();
if (cofunc == NULL)
return NULL;
- enc = PyString_AS_STRING(encoding);
for (codec = codec_list; codec->encoding[0]; codec++)
if (strcmp(codec->encoding, enc) == 0)
break;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 7d14437..4778efb 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -85,16 +85,20 @@ internal_error_callback(const char *errors)
else if (strcmp(errors, "replace") == 0)
return ERROR_REPLACE;
else
- return PyString_FromString(errors);
+ return PyUnicode_FromString(errors);
}
static PyObject *
call_error_callback(PyObject *errors, PyObject *exc)
{
PyObject *args, *cb, *r;
+ const char *str;
- assert(PyString_Check(errors));
- cb = PyCodec_LookupError(PyString_AS_STRING(errors));
+ assert(PyUnicode_Check(errors));
+ str = PyUnicode_AsString(errors);
+ if (str == NULL)
+ return NULL;
+ cb = PyCodec_LookupError(str);
if (cb == NULL)
return NULL;
@@ -129,7 +133,7 @@ codecctx_errors_get(MultibyteStatefulCodecContext *self)
return self->errors;
}
- return PyString_FromString(errors);
+ return PyUnicode_FromString(errors);
}
static int
@@ -137,18 +141,18 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
void *closure)
{
PyObject *cb;
+ const char *str;
- if (PyUnicode_Check(value)) {
- value = _PyUnicode_AsDefaultEncodedString(value, NULL);
- if (value == NULL)
- return -1;
- }
- if (!PyString_Check(value)) {
+ if (!PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError, "errors must be a string");
return -1;
}
- cb = internal_error_callback(PyString_AS_STRING(value));
+ str = PyUnicode_AsString(value);
+ if (str == NULL)
+ return -1;
+
+ cb = internal_error_callback(str);
if (cb == NULL)
return -1;