Changeset 391 for python/trunk/Modules/future_builtins.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/future_builtins.c
r2 r391 15 15 Functions:\n\ 16 16 \n\ 17 hex(arg) -- Returns the hexadecimal representation of an integer\n\ 18 oct(arg) -- Returns the octal representation of an integer\n\ 17 ascii(arg) -- Returns the canonical string representation of an object.\n\ 18 filter(pred, iterable) -- Returns an iterator yielding those items of \n\ 19 iterable for which pred(item) is true.\n\ 20 hex(arg) -- Returns the hexadecimal representation of an integer.\n\ 21 map(func, *iterables) -- Returns an iterator that computes the function \n\ 22 using arguments from each of the iterables.\n\ 23 oct(arg) -- Returns the octal representation of an integer.\n\ 24 zip(iter1 [,iter2 [...]]) -- Returns a zip object whose .next() method \n\ 25 returns a tuple where the i-th element comes from the i-th iterable \n\ 26 argument.\n\ 19 27 \n\ 20 28 The typical usage of this module is to replace existing builtins in a\n\ 21 29 module's namespace:\n \n\ 22 from future_builtins import hex, oct\n");30 from future_builtins import ascii, filter, map, hex, oct, zip\n"); 23 31 24 32 static PyObject * 25 33 builtin_hex(PyObject *self, PyObject *v) 26 34 { 27 35 return PyNumber_ToBase(v, 16); 28 36 } 29 37 … … 37 45 builtin_oct(PyObject *self, PyObject *v) 38 46 { 39 47 return PyNumber_ToBase(v, 8); 40 48 } 41 49 … … 49 57 builtin_ascii(PyObject *self, PyObject *v) 50 58 { 51 59 return PyObject_Repr(v); 52 60 } 53 61 … … 62 70 63 71 static PyMethodDef module_functions[] = { 64 {"hex",builtin_hex, METH_O, hex_doc},65 {"oct",builtin_oct, METH_O, oct_doc},66 {"ascii",builtin_ascii, METH_O, ascii_doc},67 {NULL, NULL}/* Sentinel */72 {"hex", builtin_hex, METH_O, hex_doc}, 73 {"oct", builtin_oct, METH_O, oct_doc}, 74 {"ascii", builtin_ascii, METH_O, ascii_doc}, 75 {NULL, NULL} /* Sentinel */ 68 76 }; 69 77 … … 74 82 initfuture_builtins(void) 75 83 { 76 77 78 84 PyObject *m, *itertools, *iter_func; 85 char *it_funcs[] = {"imap", "ifilter", "izip", NULL}; 86 char **cur_func; 79 87 80 81 82 88 m = Py_InitModule3("future_builtins", module_functions, module_doc); 89 if (m == NULL) 90 return; 83 91 84 85 86 92 itertools = PyImport_ImportModuleNoBlock("itertools"); 93 if (itertools == NULL) 94 return; 87 95 88 for (cur_func = it_funcs; *cur_func; ++cur_func){ 89 iter_func = PyObject_GetAttrString(itertools, *cur_func); 90 if (iter_func == NULL) 91 return; 92 PyModule_AddObject(m, *cur_func+1, iter_func); 93 } 94 Py_DECREF(itertools); 95 /* any other initialization needed */ 96 /* If anything in the following loop fails, we fall through. */ 97 for (cur_func = it_funcs; *cur_func; ++cur_func){ 98 iter_func = PyObject_GetAttrString(itertools, *cur_func); 99 if (iter_func == NULL || 100 PyModule_AddObject(m, *cur_func+1, iter_func) < 0) 101 break; 102 } 103 Py_DECREF(itertools); 104 /* any other initialization needed */ 96 105 }
Note:
See TracChangeset
for help on using the changeset viewer.