mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-35384: The repr of ctypes.CArgObject no longer fails for non-ascii character. (GH-10863)
This commit is contained in:
parent
9dfc754d61
commit
3ffa8b9ba1
2 changed files with 23 additions and 4 deletions
|
|
@ -455,6 +455,12 @@ PyCArg_dealloc(PyCArgObject *self)
|
|||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static int
|
||||
is_literal_char(unsigned char c)
|
||||
{
|
||||
return c < 128 && _PyUnicode_IsPrintable(c) && c != '\\' && c != '\'';
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyCArg_repr(PyCArgObject *self)
|
||||
{
|
||||
|
|
@ -501,8 +507,14 @@ PyCArg_repr(PyCArgObject *self)
|
|||
break;
|
||||
|
||||
case 'c':
|
||||
sprintf(buffer, "<cparam '%c' (%c)>",
|
||||
self->tag, self->value.c);
|
||||
if (is_literal_char((unsigned char)self->value.c)) {
|
||||
sprintf(buffer, "<cparam '%c' ('%c')>",
|
||||
self->tag, self->value.c);
|
||||
}
|
||||
else {
|
||||
sprintf(buffer, "<cparam '%c' ('\\x%02x')>",
|
||||
self->tag, (unsigned char)self->value.c);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Hm, are these 'z' and 'Z' codes useful at all?
|
||||
|
|
@ -517,8 +529,14 @@ PyCArg_repr(PyCArgObject *self)
|
|||
break;
|
||||
|
||||
default:
|
||||
sprintf(buffer, "<cparam '%c' at %p>",
|
||||
self->tag, self);
|
||||
if (is_literal_char((unsigned char)self->tag)) {
|
||||
sprintf(buffer, "<cparam '%c' at %p>",
|
||||
(unsigned char)self->tag, self);
|
||||
}
|
||||
else {
|
||||
sprintf(buffer, "<cparam 0x%02x at %p>",
|
||||
(unsigned char)self->tag, self);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return PyUnicode_FromString(buffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue