blob: d5c136a50f78a5d14079e6c34f4919dea25525b6 [file] [log] [blame]
Eric Smitha73fbe72008-02-23 03:09:44 +00001
2/* future_builtins module */
3
4/* This module provides functions that will be builtins in Python 3.0,
5 but that conflict with builtins that already exist in Python
6 2.x. */
7
8
9#include "Python.h"
10
11PyDoc_STRVAR(module_doc,
12"This module provides functions that will be builtins in Python 3.0,\n\
13but that conflict with builtins that already exist in Python 2.x.\n\
14\n\
15Functions:\n\
16\n\
17hex(arg) -- Returns the hexidecimal representation of an integer\n\
18oct(arg) -- Returns the octal representation of an integer\n\
19\n\
20The typical usage of this module is to replace existing builtins in a\n\
21module's namespace:\n \n\
22from future_builtins import hex, oct\n");
23
24static PyObject *
25builtin_hex(PyObject *self, PyObject *v)
26{
27 return PyNumber_ToBase(v, 16);
28}
29
30PyDoc_STRVAR(hex_doc,
31"hex(number) -> string\n\
32\n\
33Return the hexadecimal representation of an integer or long integer.");
34
35
36static PyObject *
37builtin_oct(PyObject *self, PyObject *v)
38{
39 return PyNumber_ToBase(v, 8);
40}
41
42PyDoc_STRVAR(oct_doc,
43"oct(number) -> string\n\
44\n\
45Return the octal representation of an integer or long integer.");
46
47
48/* List of functions exported by this module */
49
50static PyMethodDef module_functions[] = {
51 {"hex", builtin_hex, METH_O, hex_doc},
52 {"oct", builtin_oct, METH_O, oct_doc},
53 {NULL, NULL} /* Sentinel */
54};
55
56
57/* Initialize this module. */
58
59PyMODINIT_FUNC
60initfuture_builtins(void)
61{
62 PyObject *m;
63
64 m = Py_InitModule3("future_builtins", module_functions, module_doc);
65 if (m == NULL)
66 return;
67
68 /* any other initialization needed */
69}