2 /* future_builtins module */
4 /* This module provides functions that will be builtins in Python 3.0,
5 but that conflict with builtins that already exist in Python
11 PyDoc_STRVAR(module_doc
,
12 "This module provides functions that will be builtins in Python 3.0,\n\
13 but that conflict with builtins that already exist in Python 2.x.\n\
17 hex(arg) -- Returns the hexadecimal representation of an integer\n\
18 oct(arg) -- Returns the octal representation of an integer\n\
20 The typical usage of this module is to replace existing builtins in a\n\
21 module's namespace:\n \n\
22 from future_builtins import hex, oct\n");
25 builtin_hex(PyObject
*self
, PyObject
*v
)
27 return PyNumber_ToBase(v
, 16);
31 "hex(number) -> string\n\
33 Return the hexadecimal representation of an integer or long integer.");
37 builtin_oct(PyObject
*self
, PyObject
*v
)
39 return PyNumber_ToBase(v
, 8);
43 "oct(number) -> string\n\
45 Return the octal representation of an integer or long integer.");
48 /* List of functions exported by this module */
50 static PyMethodDef module_functions
[] = {
51 {"hex", builtin_hex
, METH_O
, hex_doc
},
52 {"oct", builtin_oct
, METH_O
, oct_doc
},
53 {NULL
, NULL
} /* Sentinel */
57 /* Initialize this module. */
60 initfuture_builtins(void)
62 PyObject
*m
, *itertools
, *iter_func
;
63 char *it_funcs
[] = {"imap", "ifilter", "izip", NULL
};
66 m
= Py_InitModule3("future_builtins", module_functions
, module_doc
);
70 itertools
= PyImport_ImportModuleNoBlock("itertools");
71 if (itertools
== NULL
)
74 for (cur_func
= it_funcs
; *cur_func
; ++cur_func
){
75 iter_func
= PyObject_GetAttrString(itertools
, *cur_func
);
76 if (iter_func
== NULL
)
78 PyModule_AddObject(m
, *cur_func
+1, iter_func
);
81 /* any other initialization needed */