[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.151,2.152

Guido van Rossum python-dev@python.org
2000年4月11日 11:38:26 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Python
In directory eric:/projects/python/develop/guido/src/Python
Modified Files:
	bltinmodule.c 
Log Message:
Marc-Andre Lemburg:
Added special case to unicode(): when being passed a
Unicode object as first argument, return the object as-is.
Raises an exception when given a Unicode object *and* an
encoding name.
Index: bltinmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.151
retrieving revision 2.152
diff -C2 -r2.151 -r2.152
*** bltinmodule.c	2000年04月05日 20:11:21	2.151
--- bltinmodule.c	2000年04月11日 15:38:23	2.152
***************
*** 166,178 ****
 	PyObject *args;
 {
! 	char *s;
 	int len;
 	char *encoding = NULL;
 	char *errors = NULL;
 
! 	if ( !PyArg_ParseTuple(args, "s#|ss:unicode", &s, &len, 
! 			 &encoding, &errors) )
 	 return NULL;
! 	return PyUnicode_Decode(s, len, encoding, errors);
 }
 
--- 166,191 ----
 	PyObject *args;
 {
! PyObject *v;
! 	const void *buffer;
 	int len;
 	char *encoding = NULL;
 	char *errors = NULL;
 
! 	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);
 }
 

AltStyle によって変換されたページ (->オリジナル) /