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

Skip to content

Commit 7fcf224

Browse files
committed
Add 8-bit chr() back as chr8().
1 parent ca8a8d0 commit 7fcf224

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Python/bltinmodule.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,29 @@ PyDoc_STRVAR(filter_doc,
377377
"or string, return the same type, else return a list.");
378378

379379

380+
static PyObject *
381+
builtin_chr(PyObject *self, PyObject *args)
382+
{
383+
long x;
384+
char s[1];
385+
386+
if (!PyArg_ParseTuple(args, "l:chr8", &x))
387+
return NULL;
388+
if (x < 0 || x >= 256) {
389+
PyErr_SetString(PyExc_ValueError,
390+
"chr8() arg not in range(256)");
391+
return NULL;
392+
}
393+
s[0] = (char)x;
394+
return PyString_FromStringAndSize(s, 1);
395+
}
396+
397+
PyDoc_STRVAR(chr_doc,
398+
"chr8(i) -> 8-bit character\n\
399+
\n\
400+
Return a string of one character with ordinal i; 0 <= i < 256.");
401+
402+
380403
static PyObject *
381404
builtin_unichr(PyObject *self, PyObject *args)
382405
{
@@ -2223,6 +2246,7 @@ static PyMethodDef builtin_methods[] = {
22232246
{"any", builtin_any, METH_O, any_doc},
22242247
{"callable", builtin_callable, METH_O, callable_doc},
22252248
{"chr", builtin_unichr, METH_VARARGS, unichr_doc},
2249+
{"chr8", builtin_chr, METH_VARARGS, chr_doc},
22262250
{"cmp", builtin_cmp, METH_VARARGS, cmp_doc},
22272251
{"compile", (PyCFunction)builtin_compile, METH_VARARGS | METH_KEYWORDS, compile_doc},
22282252
{"delattr", builtin_delattr, METH_VARARGS, delattr_doc},

0 commit comments

Comments
 (0)