summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-02-23 03:09:44 (GMT)
committerEric Smith <eric@trueblade.com>2008-02-23 03:09:44 (GMT)
commita73fbe791d0d41db543ebe39d2f6df0a4265be4b (patch)
treea07f32dc9b4de83ec186ee8a06430230edba48c3 /Modules
parent73d796324242dc2164a0b5943bd08d6252a28651 (diff)
downloadcpython-a73fbe791d0d41db543ebe39d2f6df0a4265be4b.zip
cpython-a73fbe791d0d41db543ebe39d2f6df0a4265be4b.tar.gz
cpython-a73fbe791d0d41db543ebe39d2f6df0a4265be4b.tar.bz2
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/future_builtins.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/Modules/future_builtins.c b/Modules/future_builtins.c
new file mode 100644
index 0000000..d5c136a
--- /dev/null
+++ b/Modules/future_builtins.c
@@ -0,0 +1,69 @@
+
+/* future_builtins module */
+
+/* This module provides functions that will be builtins in Python 3.0,
+ but that conflict with builtins that already exist in Python
+ 2.x. */
+
+
+#include "Python.h"
+
+PyDoc_STRVAR(module_doc,
+"This module provides functions that will be builtins in Python 3.0,\n\
+but that conflict with builtins that already exist in Python 2.x.\n\
+\n\
+Functions:\n\
+\n\
+hex(arg) -- Returns the hexidecimal representation of an integer\n\
+oct(arg) -- Returns the octal representation of an integer\n\
+\n\
+The typical usage of this module is to replace existing builtins in a\n\
+module's namespace:\n \n\
+from future_builtins import hex, oct\n");
+
+static PyObject *
+builtin_hex(PyObject *self, PyObject *v)
+{
+ return PyNumber_ToBase(v, 16);
+}
+
+PyDoc_STRVAR(hex_doc,
+"hex(number) -> string\n\
+\n\
+Return the hexadecimal representation of an integer or long integer.");
+
+
+static PyObject *
+builtin_oct(PyObject *self, PyObject *v)
+{
+ return PyNumber_ToBase(v, 8);
+}
+
+PyDoc_STRVAR(oct_doc,
+"oct(number) -> string\n\
+\n\
+Return the octal representation of an integer or long integer.");
+
+
+/* List of functions exported by this module */
+
+static PyMethodDef module_functions[] = {
+ {"hex", builtin_hex, METH_O, hex_doc},
+ {"oct", builtin_oct, METH_O, oct_doc},
+ {NULL, NULL} /* Sentinel */
+};
+
+
+/* Initialize this module. */
+
+PyMODINIT_FUNC
+initfuture_builtins(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("future_builtins", module_functions, module_doc);
+ if (m == NULL)
+ return;
+
+ /* any other initialization needed */
+}