Mercurial > cpython-lru_cache-weakref
annotate Modules/future_builtins.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 673532aa378b |
| children | e38335d4df91 1480fa3fcab4 |
| 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\ |
|
45502
ade7ac88d2d0
Fix typo of hexidecimal
Neal Norwitz <nnorwitz@gmail.com>
parents:
45439
diff
changeset
|
17 hex(arg) -- Returns the hexadecimal representation of an integer\n\ |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
18 oct(arg) -- Returns the octal representation of an integer\n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
19 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
20 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
|
21 module's namespace:\n \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
22 from future_builtins import hex, oct\n"); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
23 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
24 static PyObject * |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
25 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
|
26 { |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
27 return PyNumber_ToBase(v, 16); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
28 } |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
29 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
30 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
|
31 "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
|
32 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
33 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
|
34 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
35 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
36 static PyObject * |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
37 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
|
38 { |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
39 return PyNumber_ToBase(v, 8); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
40 } |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
41 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
42 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
|
43 "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
|
44 \n\ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
45 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
|
46 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
47 |
|
47613
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
48 static PyObject * |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
49 builtin_ascii(PyObject *self, PyObject *v) |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
50 { |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
51 return PyObject_Repr(v); |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
52 } |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
53 |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
54 PyDoc_STRVAR(ascii_doc, |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
55 "ascii(object) -> string\n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
56 \n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
57 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
|
58 contain printable characters unescaped, while the ascii() result\n\ |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
59 will have such characters backslash-escaped."); |
|
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
60 |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
61 /* 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
|
62 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
63 static PyMethodDef module_functions[] = { |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
64 {"hex", builtin_hex, METH_O, hex_doc}, |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
65 {"oct", builtin_oct, METH_O, oct_doc}, |
|
47613
673532aa378b
Add future_builtins.ascii().
Georg Brandl <georg@python.org>
parents:
45899
diff
changeset
|
66 {"ascii", builtin_ascii, METH_O, ascii_doc}, |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
67 {NULL, NULL} /* Sentinel */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
68 }; |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
69 |
|
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 /* 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
|
72 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
73 PyMODINIT_FUNC |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
74 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
|
75 { |
|
45899
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
76 PyObject *m, *itertools, *iter_func; |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
77 char *it_funcs[] = {"imap", "ifilter", "izip", NULL}; |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
78 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
|
79 |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
80 m = Py_InitModule3("future_builtins", module_functions, module_doc); |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
81 if (m == NULL) |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
82 return; |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
83 |
|
45899
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
84 itertools = PyImport_ImportModuleNoBlock("itertools"); |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
85 if (itertools == NULL) |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
86 return; |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
87 |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
88 for (cur_func = it_funcs; *cur_func; ++cur_func){ |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
89 iter_func = PyObject_GetAttrString(itertools, *cur_func); |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
90 if (iter_func == NULL) |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
91 return; |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
92 PyModule_AddObject(m, *cur_func+1, iter_func); |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
93 } |
|
4ca7119d1700
Added zip, map, filter to future_bultins (#2171)
David Wolever <david@wolever.net>
parents:
45502
diff
changeset
|
94 Py_DECREF(itertools); |
|
45439
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
95 /* any other initialization needed */ |
|
8eb598331231
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
Eric Smith <eric@trueblade.com>
parents:
diff
changeset
|
96 } |
