diff Python/bltinmodule.c @ 13402:7fbdb581838f legacy-trunk

Fixed unicode() to use the new API PyUnicode_FromEncodedObject(). This adds support for instance to the constructor (instances have to define __str__ and can return Unicode objects via that hook; string return values are decoded into Unicode using the current default encoding).
author Marc-André Lemburg <mal@egenix.com>
date Fri, 07 Jul 2000 13:48:25 +0000
parents 63d2887baf11
children 23f9689ace50
line wrap: on
line diff
--- a/Python/bltinmodule.c	Fri Jul 07 13:46:42 2000 +0000
+++ b/Python/bltinmodule.c	Fri Jul 07 13:48:25 2000 +0000
@@ -155,20 +155,7 @@
 
 	if ( !PyArg_ParseTuple(args, "O|ss:unicode", &v, &encoding, &errors) )
 	    return NULL;
-	/* Special case: Unicode will stay Unicode */
-	if (PyUnicode_Check(v)) {
-	    if (encoding) {
-		PyErr_SetString(PyExc_TypeError,
-		  "unicode() does not support decoding of Unicode objects");
-		return NULL;
-	    }
-	    Py_INCREF(v);
-	    return v;
-	}
-	/* Read raw data and decode it */
-	if (PyObject_AsReadBuffer(v, &buffer, &len))
-	    return NULL;
-	return PyUnicode_Decode((const char *)buffer, len, encoding, errors);
+	return PyUnicode_FromEncodedObject(v, encoding, errors);
 }
 
 static char unicode_doc[] =