summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-29 04:05:57 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-29 04:05:57 (GMT)
commita74184eb1d1ed8c1c139ea692b6037a7563d5540 (patch)
treeffa099c584ab7857a1ac61d6cd8b8f872c49ffb0 /Objects/unicodeobject.c
parent245b42ec4b07682dd44bb92dbde328c7ce78d90b (diff)
downloadcpython-a74184eb1d1ed8c1c139ea692b6037a7563d5540.zip
cpython-a74184eb1d1ed8c1c139ea692b6037a7563d5540.tar.gz
cpython-a74184eb1d1ed8c1c139ea692b6037a7563d5540.tar.bz2
Commit strict str/bytes distinction.
From now on, trying to write str to a binary stream is an error (I'm still working on the reverse). There are still (at least) two failing tests: - test_asynchat - test_urllib2_localnet but I'm sure these will be fixed by someone.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c55
1 files changed, 5 insertions, 50 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 1e8f63f..4e8b2ed 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -965,31 +965,11 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
return NULL;
}
-#if 0
- /* For b/w compatibility we also accept Unicode objects provided
- that no encodings is given and then redirect to
- PyObject_Unicode() which then applies the additional logic for
- Unicode subclasses.
-
- NOTE: This API should really only be used for object which
- represent *encoded* Unicode !
-
- */
- if (PyUnicode_Check(obj)) {
- if (encoding) {
- PyErr_SetString(PyExc_TypeError,
- "decoding Unicode is not supported");
- return NULL;
- }
- return PyObject_Unicode(obj);
- }
-#else
if (PyUnicode_Check(obj)) {
PyErr_SetString(PyExc_TypeError,
"decoding Unicode is not supported");
return NULL;
}
-#endif
/* Coerce object */
if (PyString_Check(obj)) {
@@ -6440,26 +6420,7 @@ able to handle UnicodeDecodeErrors.");
static PyObject *
unicode_decode(PyUnicodeObject *self, PyObject *args)
{
- char *encoding = NULL;
- char *errors = NULL;
- PyObject *v;
-
- if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
- return NULL;
- v = PyUnicode_AsDecodedObject((PyObject *)self, encoding, errors);
- if (v == NULL)
- goto onError;
- if (!PyString_Check(v) && !PyUnicode_Check(v)) {
- PyErr_Format(PyExc_TypeError,
- "decoder did not return a string/unicode object "
- "(type=%.400s)",
- Py_Type(v)->tp_name);
- Py_DECREF(v);
- return NULL;
- }
- return v;
-
- onError:
+ PyErr_Format(PyExc_TypeError, "decoding str is not supported");
return NULL;
}
@@ -8136,17 +8097,11 @@ unicode_buffer_getbuffer(PyUnicodeObject *self, PyBuffer *view, int flags)
{
if (flags & PyBUF_CHARACTER) {
- PyObject *str;
-
- str = _PyUnicode_AsDefaultEncodedString((PyObject *)self, NULL);
- if (str == NULL) return -1;
- return PyBuffer_FillInfo(view, (void *)PyString_AS_STRING(str),
- PyString_GET_SIZE(str), 1, flags);
- }
- else {
- return PyBuffer_FillInfo(view, (void *)self->str,
- PyUnicode_GET_DATA_SIZE(self), 1, flags);
+ PyErr_SetString(PyExc_SystemError, "can't use str as char buffer");
+ return -1;
}
+ return PyBuffer_FillInfo(view, (void *)self->str,
+ PyUnicode_GET_DATA_SIZE(self), 1, flags);
}