mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	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).
This commit is contained in:
		
							parent
							
								
									5a5c81a0e9
								
							
						
					
					
						commit
						1b1bcc9935
					
				
					 1 changed files with 1 additions and 14 deletions
				
			
		|  | @ -155,20 +155,7 @@ builtin_unicode(self, args) | |||
| 
 | ||||
| 	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[] = | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marc-André Lemburg
						Marc-André Lemburg