]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Modules/future_builtins.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Modules / future_builtins.c
CommitLineData
7eb75bcc
DM
1\r
2/* future_builtins module */\r
3\r
4/* This module provides functions that will be builtins in Python 3.0,\r
5 but that conflict with builtins that already exist in Python\r
6 2.x. */\r
7\r
8\r
9#include "Python.h"\r
10\r
11PyDoc_STRVAR(module_doc,\r
12"This module provides functions that will be builtins in Python 3.0,\n\\r
13but that conflict with builtins that already exist in Python 2.x.\n\\r
14\n\\r
15Functions:\n\\r
16\n\\r
17ascii(arg) -- Returns the canonical string representation of an object.\n\\r
18filter(pred, iterable) -- Returns an iterator yielding those items of \n\\r
19 iterable for which pred(item) is true.\n\\r
20hex(arg) -- Returns the hexadecimal representation of an integer.\n\\r
21map(func, *iterables) -- Returns an iterator that computes the function \n\\r
22 using arguments from each of the iterables.\n\\r
23oct(arg) -- Returns the octal representation of an integer.\n\\r
24zip(iter1 [,iter2 [...]]) -- Returns a zip object whose .next() method \n\\r
25 returns a tuple where the i-th element comes from the i-th iterable \n\\r
26 argument.\n\\r
27\n\\r
28The typical usage of this module is to replace existing builtins in a\n\\r
29module's namespace:\n \n\\r
30from future_builtins import ascii, filter, map, hex, oct, zip\n");\r
31\r
32static PyObject *\r
33builtin_hex(PyObject *self, PyObject *v)\r
34{\r
35 return PyNumber_ToBase(v, 16);\r
36}\r
37\r
38PyDoc_STRVAR(hex_doc,\r
39"hex(number) -> string\n\\r
40\n\\r
41Return the hexadecimal representation of an integer or long integer.");\r
42\r
43\r
44static PyObject *\r
45builtin_oct(PyObject *self, PyObject *v)\r
46{\r
47 return PyNumber_ToBase(v, 8);\r
48}\r
49\r
50PyDoc_STRVAR(oct_doc,\r
51"oct(number) -> string\n\\r
52\n\\r
53Return the octal representation of an integer or long integer.");\r
54\r
55\r
56static PyObject *\r
57builtin_ascii(PyObject *self, PyObject *v)\r
58{\r
59 return PyObject_Repr(v);\r
60}\r
61\r
62PyDoc_STRVAR(ascii_doc,\r
63"ascii(object) -> string\n\\r
64\n\\r
65Return the same as repr(). In Python 3.x, the repr() result will\n\\r
66contain printable characters unescaped, while the ascii() result\n\\r
67will have such characters backslash-escaped.");\r
68\r
69/* List of functions exported by this module */\r
70\r
71static PyMethodDef module_functions[] = {\r
72 {"hex", builtin_hex, METH_O, hex_doc},\r
73 {"oct", builtin_oct, METH_O, oct_doc},\r
74 {"ascii", builtin_ascii, METH_O, ascii_doc},\r
75 {NULL, NULL} /* Sentinel */\r
76};\r
77\r
78\r
79/* Initialize this module. */\r
80\r
81PyMODINIT_FUNC\r
82initfuture_builtins(void)\r
83{\r
84 PyObject *m, *itertools, *iter_func;\r
85 char *it_funcs[] = {"imap", "ifilter", "izip", NULL};\r
86 char **cur_func;\r
87\r
88 m = Py_InitModule3("future_builtins", module_functions, module_doc);\r
89 if (m == NULL)\r
90 return;\r
91\r
92 itertools = PyImport_ImportModuleNoBlock("itertools");\r
93 if (itertools == NULL)\r
94 return;\r
95\r
96 /* If anything in the following loop fails, we fall through. */\r
97 for (cur_func = it_funcs; *cur_func; ++cur_func){\r
98 iter_func = PyObject_GetAttrString(itertools, *cur_func);\r
99 if (iter_func == NULL ||\r
100 PyModule_AddObject(m, *cur_func+1, iter_func) < 0)\r
101 break;\r
102 }\r
103 Py_DECREF(itertools);\r
104 /* any other initialization needed */\r
105}\r