[Python-checkins] python/dist/src/Python exceptions.c,1.44,1.45
doerwalter at users.sourceforge.net
doerwalter at users.sourceforge.net
Tue Aug 12 11:32:45 EDT 2003
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv14601/Python
Modified Files:
exceptions.c
Log Message:
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
If there is only one bad character it will now be printed in a
form that is a valid Python string.
Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** exceptions.c 24 Feb 2003 15:33:31 -0000 1.44
--- exceptions.c 12 Aug 2003 17:32:43 -0000 1.45
***************
*** 1252,1259 ****
if (end==start+1) {
PyOS_snprintf(buffer, sizeof(buffer),
! "'%.400s' codec can't encode character '\\u%x' in position %d: %.400s",
PyString_AS_STRING(encodingObj),
! (int)PyUnicode_AS_UNICODE(objectObj)[start],
start,
PyString_AS_STRING(reasonObj)
--- 1252,1267 ----
if (end==start+1) {
+ int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
+ char *format;
+ if (badchar <= 0xff)
+ format = "'%.400s' codec can't encode character '\\x%02x' in position %d: %.400s";
+ else if (badchar <= 0xffff)
+ format = "'%.400s' codec can't encode character '\\u%04x' in position %d: %.400s";
+ else
+ format = "'%.400s' codec can't encode character '\\U%08x' in position %d: %.400s";
PyOS_snprintf(buffer, sizeof(buffer),
! format,
PyString_AS_STRING(encodingObj),
! badchar,
start,
PyString_AS_STRING(reasonObj)
***************
*** 1330,1334 ****
if (end==start+1) {
PyOS_snprintf(buffer, sizeof(buffer),
! "'%.400s' codec can't decode byte 0x%x in position %d: %.400s",
PyString_AS_STRING(encodingObj),
((int)PyString_AS_STRING(objectObj)[start])&0xff,
--- 1338,1342 ----
if (end==start+1) {
PyOS_snprintf(buffer, sizeof(buffer),
! "'%.400s' codec can't decode byte 0x%02x in position %d: %.400s",
PyString_AS_STRING(encodingObj),
((int)PyString_AS_STRING(objectObj)[start])&0xff,
***************
*** 1439,1445 ****
if (end==start+1) {
PyOS_snprintf(buffer, sizeof(buffer),
! "can't translate character '\\u%x' in position %d: %.400s",
! (int)PyUnicode_AS_UNICODE(objectObj)[start],
start,
PyString_AS_STRING(reasonObj)
--- 1447,1461 ----
if (end==start+1) {
+ int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
+ char *format;
+ if (badchar <= 0xff)
+ format = "can't translate character '\\x%02x' in position %d: %.400s";
+ else if (badchar <= 0xffff)
+ format = "can't translate character '\\u%04x' in position %d: %.400s";
+ else
+ format = "can't translate character '\\U%08x' in position %d: %.400s";
PyOS_snprintf(buffer, sizeof(buffer),
! format,
! badchar,
start,
PyString_AS_STRING(reasonObj)
More information about the Python-checkins
mailing list