[Python-checkins] python/dist/src/Modules _tkinter.c,1.133,1.134

loewis@users.sourceforge.net loewis@users.sourceforge.net
Wed, 04 Dec 2002 11:54:38 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv2233/Modules

Modified Files:
	_tkinter.c 
Log Message:
Decode untyped strings from UTF-8.


Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.133
retrieving revision 1.134
diff -C2 -d -r1.133 -r1.134
*** _tkinter.c	26 Nov 2002 22:12:12 -0000	1.133
--- _tkinter.c	4 Dec 2002 19:54:36 -0000	1.134
***************
*** 771,776 ****
  	TkappObject *app = (TkappObject*)tkapp;
  
! 	if (value->typePtr == NULL)
! 		return PyString_FromStringAndSize(value->bytes, value->length);
  
  	if (value->typePtr == app->BooleanType) {
--- 771,801 ----
  	TkappObject *app = (TkappObject*)tkapp;
  
! 	if (value->typePtr == NULL) {
! 		/* If the result contains any bytes with the top bit set,
! 		   it's UTF-8 and we should decode it to Unicode */
! #ifdef Py_USING_UNICODE
! 		int i;
! 		char *s = value->bytes;
! 		int len = value->length;
! 		for (i = 0; i < len; i++) {
! 			if (value->bytes[i] & 0x80)
! 				break;
! 		}
! 
! 		if (i == value->length)
! 			result = PyString_FromStringAndSize(s, len);
! 		else {
! 			/* Convert UTF-8 to Unicode string */
! 			result = PyUnicode_DecodeUTF8(s, len, "strict");
! 			if (result == NULL) {
! 				PyErr_Clear();
! 				result = PyString_FromStringAndSize(s, len);
! 			}
! 		}
! #else
! 		res = PyString_FromStringAndSize(value->bytes, value->length);
! #endif
! 		return result;
! 	}
  
  	if (value->typePtr == app->BooleanType) {