[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.166,2.167

M.-A. Lemburg python-dev@python.org
Fri, 7 Jul 2000 06:48:27 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17051/Python

Modified Files:
	bltinmodule.c 
Log Message:
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).

Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.166
retrieving revision 2.167
diff -C2 -r2.166 -r2.167
*** bltinmodule.c	2000/07/03 21:39:47	2.166
--- bltinmodule.c	2000/07/07 13:48:25	2.167
***************
*** 156,173 ****
  	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);
  }
  
--- 156,160 ----
  	if ( !PyArg_ParseTuple(args, "O|ss:unicode", &v, &encoding, &errors) )
  	    return NULL;
! 	return PyUnicode_FromEncodedObject(v, encoding, errors);
  }