Mercurial > cpython-lru_cache-weakref
annotate Modules/future_builtins.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
1 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
2 /* future_builtins module */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
3 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
4 /* This module provides functions that will be builtins in Python 3.0, |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
5 but that conflict with builtins that already exist in Python |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
6 2.x. */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
7 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
8 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
9 #include "Python.h" |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
10 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
11 PyDoc_STRVAR(module_doc, |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
12 "This module provides functions that will be builtins in Python 3.0,\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
13 but that conflict with builtins that already exist in Python 2.x.\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
14 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
15 Functions:\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
16 \n\ |
|
65313
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
17 ascii(arg) -- Returns the canonical string representation of an object.\n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
18 filter(pred, iterable) -- Returns an iterator yielding those items of \n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
19 iterable for which pred(item) is true.\n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
20 hex(arg) -- Returns the hexadecimal representation of an integer.\n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
21 map(func, *iterables) -- Returns an iterator that computes the function \n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
22 using arguments from each of the iterables.\n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
23 oct(arg) -- Returns the octal representation of an integer.\n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
24 zip(iter1 [,iter2 [...]]) -- Returns a zip object whose .next() method \n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
25 returns a tuple where the i-th element comes from the i-th iterable \n\ |
|
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
26 argument.\n\ |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
27 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
28 The typical usage of this module is to replace existing builtins in a\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
29 module's namespace:\n \n\ |
|
65313
08a9c046004d
Fix issue10065 - future_builtins' docstring lacks some functions
Senthil Kumaran <orsenthil@gmail.com>
parents:
61463
diff
changeset
|
30 from future_builtins import ascii, filter, map, hex, oct, zip\n"); |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
31 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
32 static PyObject * |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
33 builtin_hex(PyObject *self, PyObject *v) |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
34 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
35 return PyNumber_ToBase(v, 16); |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
36 } |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
37 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
38 PyDoc_STRVAR(hex_doc, |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
39 "hex(number) -> string\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
40 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
41 Return the hexadecimal representation of an integer or long integer."); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
42 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
43 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
44 static PyObject * |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
45 builtin_oct(PyObject *self, PyObject *v) |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
46 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
47 return PyNumber_ToBase(v, 8); |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
48 } |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
49 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
50 PyDoc_STRVAR(oct_doc, |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
51 "oct(number) -> string\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
52 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
53 Return the octal representation of an integer or long integer."); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
54 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
55 |
|
47613
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
56 static PyObject * |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
57 builtin_ascii(PyObject *self, PyObject *v) |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
58 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
59 return PyObject_Repr(v); |
|
47613
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
60 } |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
61 |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
62 PyDoc_STRVAR(ascii_doc, |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
63 "ascii(object) -> string\n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
64 \n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
65 Return the same as repr(). In Python 3.x, the repr() result will\n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
66 contain printable characters unescaped, while the ascii() result\n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
67 will have such characters backslash-escaped."); |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
68 |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
69 /* List of functions exported by this module */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
70 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
71 static PyMethodDef module_functions[] = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
72 {"hex", builtin_hex, METH_O, hex_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
73 {"oct", builtin_oct, METH_O, oct_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
74 {"ascii", builtin_ascii, METH_O, ascii_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
75 {NULL, NULL} /* Sentinel */ |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
76 }; |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
77 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
78 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
79 /* Initialize this module. */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
80 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
81 PyMODINIT_FUNC |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
82 initfuture_builtins(void) |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
83 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
84 PyObject *m, *itertools, *iter_func; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
85 char *it_funcs[] = {"imap", "ifilter", "izip", NULL}; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
86 char **cur_func; |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
87 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
88 m = Py_InitModule3("future_builtins", module_functions, module_doc); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
89 if (m == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
90 return; |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
91 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
92 itertools = PyImport_ImportModuleNoBlock("itertools"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
93 if (itertools == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
94 return; |
|
45899
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
95 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
54334
diff
changeset
|
96 /* If anything in the following loop fails, we fall through. */ |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
97 for (cur_func = it_funcs; *cur_func; ++cur_func){ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
98 iter_func = PyObject_GetAttrString(itertools, *cur_func); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
54334
diff
changeset
|
99 if (iter_func == NULL || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
54334
diff
changeset
|
100 PyModule_AddObject(m, *cur_func+1, iter_func) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
54334
diff
changeset
|
101 break; |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
102 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
103 Py_DECREF(itertools); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47613
diff
changeset
|
104 /* any other initialization needed */ |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
105 } |
