Skip to content

Commit a8880d1

Browse files
committed
post-merge
1 parent 35c9af7 commit a8880d1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Python/codecs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,9 +988,12 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
988988
return Py_BuildValue("(Nn)", res, end);
989989
}
990990

991+
992+
// --- handler: 'namereplace' -------------------------------------------------
993+
991994
PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
992995
{
993-
if (!PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeEncodeError)) {
996+
if (!_PyIsUnicodeEncodeError(exc)) {
994997
wrong_exception_type(exc);
995998
return NULL;
996999
}
@@ -1012,9 +1015,13 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
10121015
char buffer[256]; /* NAME_MAXLEN */
10131016
Py_ssize_t i = start, ressize = 0, replsize;
10141017
for (; i < end; ++i) {
1018+
// If 'c' is recognized by getname(), the corresponding replacement
1019+
// is '\\' + 'U' + '{' + NAME + '}', namely 1 + 1 + 1 + len(NAME) + 1
1020+
// characters. Otherwise, the replacement is obtained similarly as
1021+
// in PyCodec_BackslashReplaceErrors().
10151022
Py_UCS4 c = PyUnicode_READ_CHAR(obj, i);
10161023
if (ucnhash_capi->getname(c, buffer, sizeof(buffer), 1)) {
1017-
// failures of 'getname()' are ignored by this handler
1024+
// failures of 'getname()' are ignored by the handler
10181025
replsize = 1 + 1 + 1 + (int)strlen(buffer) + 1;
10191026
}
10201027
else if (c >= 0x10000) {
@@ -1044,7 +1051,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
10441051
Py_UCS4 c = PyUnicode_READ_CHAR(obj, i);
10451052
*outp++ = '\\';
10461053
if (ucnhash_capi->getname(c, buffer, sizeof(buffer), 1)) {
1047-
// failures of 'getname()' are ignored by this handler
1054+
// failures of 'getname()' are ignored by the handler
10481055
*outp++ = 'N';
10491056
*outp++ = '{';
10501057
(void)strcpy((char *)outp, buffer);

0 commit comments

Comments
 (0)