Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a54b92b

Browse files
committed
Add a unicode prefix to the characters in the UnicodeEncodeError and
UnicodeTranslateError message.
1 parent fd196bd commit a54b92b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

Lib/test/test_codeccallbacks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def test_unicodeencodeerror(self):
258258
self.check_exceptionobjectargs(
259259
UnicodeEncodeError,
260260
["ascii", u"g\xfcrk", 1, 2, "ouch"],
261-
"'ascii' codec can't encode character '\\xfc' in position 1: ouch"
261+
"'ascii' codec can't encode character u'\\xfc' in position 1: ouch"
262262
)
263263
self.check_exceptionobjectargs(
264264
UnicodeEncodeError,
@@ -268,23 +268,23 @@ def test_unicodeencodeerror(self):
268268
self.check_exceptionobjectargs(
269269
UnicodeEncodeError,
270270
["ascii", u"\xfcx", 0, 1, "ouch"],
271-
"'ascii' codec can't encode character '\\xfc' in position 0: ouch"
271+
"'ascii' codec can't encode character u'\\xfc' in position 0: ouch"
272272
)
273273
self.check_exceptionobjectargs(
274274
UnicodeEncodeError,
275275
["ascii", u"\u0100x", 0, 1, "ouch"],
276-
"'ascii' codec can't encode character '\\u0100' in position 0: ouch"
276+
"'ascii' codec can't encode character u'\\u0100' in position 0: ouch"
277277
)
278278
self.check_exceptionobjectargs(
279279
UnicodeEncodeError,
280280
["ascii", u"\uffffx", 0, 1, "ouch"],
281-
"'ascii' codec can't encode character '\\uffff' in position 0: ouch"
281+
"'ascii' codec can't encode character u'\\uffff' in position 0: ouch"
282282
)
283283
if sys.maxunicode > 0xffff:
284284
self.check_exceptionobjectargs(
285285
UnicodeEncodeError,
286286
["ascii", u"\U00010000x", 0, 1, "ouch"],
287-
"'ascii' codec can't encode character '\\U00010000' in position 0: ouch"
287+
"'ascii' codec can't encode character u'\\U00010000' in position 0: ouch"
288288
)
289289

290290
def test_unicodedecodeerror(self):
@@ -303,23 +303,23 @@ def test_unicodetranslateerror(self):
303303
self.check_exceptionobjectargs(
304304
UnicodeTranslateError,
305305
[u"g\xfcrk", 1, 2, "ouch"],
306-
"can't translate character '\\xfc' in position 1: ouch"
306+
"can't translate character u'\\xfc' in position 1: ouch"
307307
)
308308
self.check_exceptionobjectargs(
309309
UnicodeTranslateError,
310310
[u"g\u0100rk", 1, 2, "ouch"],
311-
"can't translate character '\\u0100' in position 1: ouch"
311+
"can't translate character u'\\u0100' in position 1: ouch"
312312
)
313313
self.check_exceptionobjectargs(
314314
UnicodeTranslateError,
315315
[u"g\uffffrk", 1, 2, "ouch"],
316-
"can't translate character '\\uffff' in position 1: ouch"
316+
"can't translate character u'\\uffff' in position 1: ouch"
317317
)
318318
if sys.maxunicode > 0xffff:
319319
self.check_exceptionobjectargs(
320320
UnicodeTranslateError,
321321
[u"g\U00010000rk", 1, 2, "ouch"],
322-
"can't translate character '\\U00010000' in position 1: ouch"
322+
"can't translate character u'\\U00010000' in position 1: ouch"
323323
)
324324
self.check_exceptionobjectargs(
325325
UnicodeTranslateError,

Python/exceptions.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,11 @@ UnicodeEncodeError__str__(PyObject *self, PyObject *arg)
12541254
int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
12551255
char *format;
12561256
if (badchar <= 0xff)
1257-
format = "'%.400s' codec can't encode character '\\x%02x' in position %d: %.400s";
1257+
format = "'%.400s' codec can't encode character u'\\x%02x' in position %d: %.400s";
12581258
else if (badchar <= 0xffff)
1259-
format = "'%.400s' codec can't encode character '\\u%04x' in position %d: %.400s";
1259+
format = "'%.400s' codec can't encode character u'\\u%04x' in position %d: %.400s";
12601260
else
1261-
format = "'%.400s' codec can't encode character '\\U%08x' in position %d: %.400s";
1261+
format = "'%.400s' codec can't encode character u'\\U%08x' in position %d: %.400s";
12621262
PyOS_snprintf(buffer, sizeof(buffer),
12631263
format,
12641264
PyString_AS_STRING(encodingObj),
@@ -1449,11 +1449,11 @@ UnicodeTranslateError__str__(PyObject *self, PyObject *arg)
14491449
int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
14501450
char *format;
14511451
if (badchar <= 0xff)
1452-
format = "can't translate character '\\x%02x' in position %d: %.400s";
1452+
format = "can't translate character u'\\x%02x' in position %d: %.400s";
14531453
else if (badchar <= 0xffff)
1454-
format = "can't translate character '\\u%04x' in position %d: %.400s";
1454+
format = "can't translate character u'\\u%04x' in position %d: %.400s";
14551455
else
1456-
format = "can't translate character '\\U%08x' in position %d: %.400s";
1456+
format = "can't translate character u'\\U%08x' in position %d: %.400s";
14571457
PyOS_snprintf(buffer, sizeof(buffer),
14581458
format,
14591459
badchar,

0 commit comments

Comments
 (0)