summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-04 17:43:11 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-04 17:43:11 (GMT)
commit7fcf224ec804d3dc4791ae25cfee23feb239eabd (patch)
treebc8535d4f412bc67e80060fa4474cbe8a566d381 /Python
parentca8a8d0b3fe228c0c3c0d84c09775630581edf25 (diff)
downloadcpython-7fcf224ec804d3dc4791ae25cfee23feb239eabd.zip
cpython-7fcf224ec804d3dc4791ae25cfee23feb239eabd.tar.gz
cpython-7fcf224ec804d3dc4791ae25cfee23feb239eabd.tar.bz2
Add 8-bit chr() back as chr8().
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 7d52e2b..093bb81 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -378,6 +378,29 @@ PyDoc_STRVAR(filter_doc,
static PyObject *
+builtin_chr(PyObject *self, PyObject *args)
+{
+ long x;
+ char s[1];
+
+ if (!PyArg_ParseTuple(args, "l:chr8", &x))
+ return NULL;
+ if (x < 0 || x >= 256) {
+ PyErr_SetString(PyExc_ValueError,
+ "chr8() arg not in range(256)");
+ return NULL;
+ }
+ s[0] = (char)x;
+ return PyString_FromStringAndSize(s, 1);
+}
+
+PyDoc_STRVAR(chr_doc,
+"chr8(i) -> 8-bit character\n\
+\n\
+Return a string of one character with ordinal i; 0 <= i < 256.");
+
+
+static PyObject *
builtin_unichr(PyObject *self, PyObject *args)
{
long x;
@@ -2223,6 +2246,7 @@ static PyMethodDef builtin_methods[] = {
{"any", builtin_any, METH_O, any_doc},
{"callable", builtin_callable, METH_O, callable_doc},
{"chr", builtin_unichr, METH_VARARGS, unichr_doc},
+ {"chr8", builtin_chr, METH_VARARGS, chr_doc},
{"cmp", builtin_cmp, METH_VARARGS, cmp_doc},
{"compile", (PyCFunction)builtin_compile, METH_VARARGS | METH_KEYWORDS, compile_doc},
{"delattr", builtin_delattr, METH_VARARGS, delattr_doc},