Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 58664:993f703a61ba
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 03 Feb 2010 02:35:45 +0000 |
| parents | a08840ce88d3 |
| children | 81d6833c6278 |
| rev | line source |
|---|---|
| 86 | 1 /* Built-in functions */ |
| 2 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
3 #include "Python.h" |
|
46208
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
4 #include "Python-ast.h" |
| 86 | 5 |
| 6 #include "node.h" | |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35636
diff
changeset
|
7 #include "code.h" |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
8 #include "eval.h" |
| 86 | 9 |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
10 #include <ctype.h> |
|
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
11 |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
12 /* The default encoding used by the platform file system APIs |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
13 Can remain NULL for all platforms that don't have such a concept |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43487
diff
changeset
|
14 |
|
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43487
diff
changeset
|
15 Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the |
|
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43487
diff
changeset
|
16 values for Py_FileSystemDefaultEncoding! |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
17 */ |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23868
diff
changeset
|
18 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
19 const char *Py_FileSystemDefaultEncoding = "mbcs"; |
|
49403
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
20 int Py_HasFileSystemDefaultEncoding = 1; |
|
27782
904f0e769820
My previous checkin caused compile() to no longer accept buffers, as noted
Just van Rossum <just@letterror.com>
parents:
27781
diff
changeset
|
21 #elif defined(__APPLE__) |
|
904f0e769820
My previous checkin caused compile() to no longer accept buffers, as noted
Just van Rossum <just@letterror.com>
parents:
27781
diff
changeset
|
22 const char *Py_FileSystemDefaultEncoding = "utf-8"; |
|
49403
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
23 int Py_HasFileSystemDefaultEncoding = 1; |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
24 #else |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
25 const char *Py_FileSystemDefaultEncoding = NULL; /* use default */ |
|
49403
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
26 int Py_HasFileSystemDefaultEncoding = 0; |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
27 #endif |
|
17817
f7c385226f65
Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17694
diff
changeset
|
28 |
|
49403
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
29 int |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
30 _Py_SetFileSystemEncoding(PyObject *s) |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
31 { |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
32 PyObject *defenc; |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
33 if (!PyUnicode_Check(s)) { |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
34 PyErr_BadInternalCall(); |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
35 return -1; |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
36 } |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
37 defenc = _PyUnicode_AsDefaultEncodedString(s, NULL); |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
38 if (!defenc) |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
39 return -1; |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
40 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
41 /* A file system encoding was set at run-time */ |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
42 free((char*)Py_FileSystemDefaultEncoding); |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
43 Py_FileSystemDefaultEncoding = strdup(PyBytes_AsString(defenc)); |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
44 Py_HasFileSystemDefaultEncoding = 0; |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
45 return 0; |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
46 } |
|
e822992cf6ce
Issue #3187: Add sys.setfilesystemencoding.
Martin v. Löwis <martin@v.loewis.de>
parents:
49261
diff
changeset
|
47 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
48 static PyObject * |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
49 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
50 { |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
51 PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *cell; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
52 PyObject *cls = NULL; |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
53 Py_ssize_t nargs, nbases; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
54 |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
55 assert(args != NULL); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
56 if (!PyTuple_Check(args)) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
57 PyErr_SetString(PyExc_TypeError, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
58 "__build_class__: args is not a tuple"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
59 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
60 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
61 nargs = PyTuple_GET_SIZE(args); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
62 if (nargs < 2) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
63 PyErr_SetString(PyExc_TypeError, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
64 "__build_class__: not enough arguments"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
65 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
66 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
67 func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
68 name = PyTuple_GET_ITEM(args, 1); |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42817
diff
changeset
|
69 if (!PyUnicode_Check(name)) { |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
70 PyErr_SetString(PyExc_TypeError, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
71 "__build_class__: name is not a string"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
72 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
73 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
74 bases = PyTuple_GetSlice(args, 2, nargs); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
75 if (bases == NULL) |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
76 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
77 nbases = nargs - 2; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
78 |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
79 if (kwds == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
80 meta = NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
81 mkw = NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
82 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
83 else { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
84 mkw = PyDict_Copy(kwds); /* Don't modify kwds passed in! */ |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
85 if (mkw == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
86 Py_DECREF(bases); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
87 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
88 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
89 meta = PyDict_GetItemString(mkw, "metaclass"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
90 if (meta != NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
91 Py_INCREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
92 if (PyDict_DelItemString(mkw, "metaclass") < 0) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
93 Py_DECREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
94 Py_DECREF(mkw); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
95 Py_DECREF(bases); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
96 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
97 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
98 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
99 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
100 if (meta == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
101 if (PyTuple_GET_SIZE(bases) == 0) |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
102 meta = (PyObject *) (&PyType_Type); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
103 else { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
104 PyObject *base0 = PyTuple_GET_ITEM(bases, 0); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
105 meta = (PyObject *) (base0->ob_type); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
106 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
107 Py_INCREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
108 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
109 prep = PyObject_GetAttrString(meta, "__prepare__"); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
110 if (prep == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
111 PyErr_Clear(); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
112 ns = PyDict_New(); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
113 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
114 else { |
|
50615
45aef53f5c71
Mini-optimization: use pack/unpack functions for argument tuples.
Raymond Hettinger <python@rcn.com>
parents:
50586
diff
changeset
|
115 PyObject *pargs = PyTuple_Pack(2, name, bases); |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
116 if (pargs == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
117 Py_DECREF(prep); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
118 Py_DECREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
119 Py_XDECREF(mkw); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
120 Py_DECREF(bases); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
121 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
122 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
123 ns = PyEval_CallObjectWithKeywords(prep, pargs, mkw); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
124 Py_DECREF(pargs); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
125 Py_DECREF(prep); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
126 if (ns == NULL) { |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
127 Py_DECREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
128 Py_XDECREF(mkw); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
129 Py_DECREF(bases); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
130 return NULL; |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
131 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
132 } |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
133 cell = PyObject_CallFunctionObjArgs(func, ns, NULL); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
134 if (cell != NULL) { |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
135 PyObject *margs; |
|
50615
45aef53f5c71
Mini-optimization: use pack/unpack functions for argument tuples.
Raymond Hettinger <python@rcn.com>
parents:
50586
diff
changeset
|
136 margs = PyTuple_Pack(3, name, bases, ns); |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
137 if (margs != NULL) { |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
138 cls = PyEval_CallObjectWithKeywords(meta, margs, mkw); |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
139 Py_DECREF(margs); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
140 } |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
141 if (cls != NULL && PyCell_Check(cell)) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
142 Py_INCREF(cls); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
143 PyCell_SET(cell, cls); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
144 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
145 Py_DECREF(cell); |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
146 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
147 Py_DECREF(ns); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
148 Py_DECREF(meta); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
149 Py_XDECREF(mkw); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
150 Py_DECREF(bases); |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
151 return cls; |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
152 } |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
153 |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
154 PyDoc_STRVAR(build_class_doc, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
155 "__build_class__(func, name, *bases, metaclass=None, **kwds) -> class\n\ |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
156 \n\ |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
157 Internal helper function used by the class statement."); |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
158 |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
159 static PyObject * |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
160 builtin___import__(PyObject *self, PyObject *args, PyObject *kwds) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
161 { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
162 static char *kwlist[] = {"name", "globals", "locals", "fromlist", |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
163 "level", 0}; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
164 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
165 PyObject *globals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
166 PyObject *locals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
167 PyObject *fromlist = NULL; |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
168 int level = -1; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
169 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
170 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOOi:__import__", |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
171 kwlist, &name, &globals, &locals, &fromlist, &level)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
172 return NULL; |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
173 return PyImport_ImportModuleLevel(name, globals, locals, |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
174 fromlist, level); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
175 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
176 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
177 PyDoc_STRVAR(import_doc, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
178 "__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module\n\ |
| 8561 | 179 \n\ |
| 180 Import a module. The globals are only used to determine the context;\n\ | |
| 181 they are not modified. The locals are currently unused. The fromlist\n\ | |
| 182 should be a list of names to emulate ``from name import ...'', or an\n\ | |
| 183 empty list to emulate ``import name''.\n\ | |
| 184 When importing a module from a package, note that __import__('A.B', ...)\n\ | |
| 185 returns package A when fromlist is empty, but its submodule B when\n\ | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
186 fromlist is not empty. Level is used to determine whether to perform \n\ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
187 absolute or relative imports. -1 is the original strategy of attempting\n\ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
188 both absolute and relative imports, 0 is absolute, a positive number\n\ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
189 is the number of parent directories to search relative to the current module."); |
| 8561 | 190 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
191 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
192 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
193 builtin_abs(PyObject *self, PyObject *v) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
194 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
195 return PyNumber_Absolute(v); |
| 86 | 196 } |
| 197 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
198 PyDoc_STRVAR(abs_doc, |
| 8561 | 199 "abs(number) -> number\n\ |
| 200 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
201 Return the absolute value of the argument."); |
| 8561 | 202 |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
203 static PyObject * |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
204 builtin_all(PyObject *self, PyObject *v) |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
205 { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
206 PyObject *it, *item; |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
207 PyObject *(*iternext)(PyObject *); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
208 int cmp; |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
209 |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
210 it = PyObject_GetIter(v); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
211 if (it == NULL) |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
212 return NULL; |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
213 iternext = *Py_TYPE(it)->tp_iternext; |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
214 |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
215 for (;;) { |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
216 item = iternext(it); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
217 if (item == NULL) |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
218 break; |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
219 cmp = PyObject_IsTrue(item); |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
220 Py_DECREF(item); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
221 if (cmp < 0) { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
222 Py_DECREF(it); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
223 return NULL; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
224 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
225 if (cmp == 0) { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
226 Py_DECREF(it); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
227 Py_RETURN_FALSE; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
228 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
229 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
230 Py_DECREF(it); |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
231 if (PyErr_Occurred()) { |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
232 if (PyErr_ExceptionMatches(PyExc_StopIteration)) |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
233 PyErr_Clear(); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
234 else |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
235 return NULL; |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
236 } |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
237 Py_RETURN_TRUE; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
238 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
239 |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
240 PyDoc_STRVAR(all_doc, |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
241 "all(iterable) -> bool\n\ |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
242 \n\ |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
243 Return True if bool(x) is True for all values x in the iterable."); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
244 |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
245 static PyObject * |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
246 builtin_any(PyObject *self, PyObject *v) |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
247 { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
248 PyObject *it, *item; |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
249 PyObject *(*iternext)(PyObject *); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
250 int cmp; |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
251 |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
252 it = PyObject_GetIter(v); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
253 if (it == NULL) |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
254 return NULL; |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
255 iternext = *Py_TYPE(it)->tp_iternext; |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
256 |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
257 for (;;) { |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
258 item = iternext(it); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
259 if (item == NULL) |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
260 break; |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
261 cmp = PyObject_IsTrue(item); |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
262 Py_DECREF(item); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
263 if (cmp < 0) { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
264 Py_DECREF(it); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
265 return NULL; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
266 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
267 if (cmp == 1) { |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
268 Py_DECREF(it); |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
269 Py_RETURN_TRUE; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
270 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
271 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
272 Py_DECREF(it); |
|
44373
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
273 if (PyErr_Occurred()) { |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
274 if (PyErr_ExceptionMatches(PyExc_StopIteration)) |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
275 PyErr_Clear(); |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
276 else |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
277 return NULL; |
|
2750d531fdc0
Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
278 } |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
279 Py_RETURN_FALSE; |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
280 } |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
281 |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
282 PyDoc_STRVAR(any_doc, |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
283 "any(iterable) -> bool\n\ |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
284 \n\ |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
285 Return True if bool(x) is True for any x in the iterable."); |
| 8561 | 286 |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
287 static PyObject * |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
288 builtin_ascii(PyObject *self, PyObject *v) |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
289 { |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
290 return PyObject_ASCII(v); |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
291 } |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
292 |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
293 PyDoc_STRVAR(ascii_doc, |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
294 "ascii(object) -> string\n\ |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
295 \n\ |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
296 As repr(), return a string containing a printable representation of an\n\ |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
297 object, but escape the non-ASCII characters in the string returned by\n\ |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
298 repr() using \\x, \\u or \\U escapes. This generates a string similar\n\ |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
299 to that returned by repr() in Python 2."); |
|
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
300 |
| 8561 | 301 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
302 static PyObject * |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
303 builtin_bin(PyObject *self, PyObject *v) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
304 { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
305 return PyNumber_ToBase(v, 2); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
306 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
307 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
308 PyDoc_STRVAR(bin_doc, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
309 "bin(number) -> string\n\ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
310 \n\ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
311 Return the binary representation of an integer or long integer."); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
312 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
313 |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
314 typedef struct { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
315 PyObject_HEAD |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
316 PyObject *func; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
317 PyObject *it; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
318 } filterobject; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
319 |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
320 static PyObject * |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
321 filter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
322 { |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
323 PyObject *func, *seq; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
324 PyObject *it; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
325 filterobject *lz; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
326 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
327 if (type == &PyFilter_Type && !_PyArg_NoKeywords("filter()", kwds)) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
328 return NULL; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
329 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
330 if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq)) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
331 return NULL; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
332 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
333 /* Get iterator. */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
334 it = PyObject_GetIter(seq); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
335 if (it == NULL) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
336 return NULL; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
337 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
338 /* create filterobject structure */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
339 lz = (filterobject *)type->tp_alloc(type, 0); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
340 if (lz == NULL) { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
341 Py_DECREF(it); |
|
35264
b431ed7bcdc2
Fix cleanup DECREF logic in builtin_filter function.
Georg Brandl <georg@python.org>
parents:
34736
diff
changeset
|
342 return NULL; |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
343 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
344 Py_INCREF(func); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
345 lz->func = func; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
346 lz->it = it; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
347 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
348 return (PyObject *)lz; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
349 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
350 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
351 static void |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
352 filter_dealloc(filterobject *lz) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
353 { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
354 PyObject_GC_UnTrack(lz); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
355 Py_XDECREF(lz->func); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
356 Py_XDECREF(lz->it); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
357 Py_TYPE(lz)->tp_free(lz); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
358 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
359 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
360 static int |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
361 filter_traverse(filterobject *lz, visitproc visit, void *arg) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
362 { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
363 Py_VISIT(lz->it); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
364 Py_VISIT(lz->func); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
365 return 0; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
366 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
367 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
368 static PyObject * |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
369 filter_next(filterobject *lz) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
370 { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
371 PyObject *item; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
372 PyObject *it = lz->it; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
373 long ok; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
374 PyObject *(*iternext)(PyObject *); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
375 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
376 iternext = *Py_TYPE(it)->tp_iternext; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
377 for (;;) { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
378 item = iternext(it); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
379 if (item == NULL) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
380 return NULL; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
381 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
382 if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
383 ok = PyObject_IsTrue(item); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
384 } else { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
385 PyObject *good; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
386 good = PyObject_CallFunctionObjArgs(lz->func, |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
387 item, NULL); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
388 if (good == NULL) { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
389 Py_DECREF(item); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
390 return NULL; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
391 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
392 ok = PyObject_IsTrue(good); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
393 Py_DECREF(good); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
394 } |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
395 if (ok) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
396 return item; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
397 Py_DECREF(item); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
398 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
399 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
400 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
401 PyDoc_STRVAR(filter_doc, |
|
47097
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
402 "filter(function or None, iterable) --> filter object\n\ |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
403 \n\ |
|
47097
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
404 Return an iterator yielding those items of iterable for which function(item)\n\ |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
405 is true. If function is None, return the items that are true."); |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
406 |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
407 PyTypeObject PyFilter_Type = { |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
408 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
409 "filter", /* tp_name */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
410 sizeof(filterobject), /* tp_basicsize */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
411 0, /* tp_itemsize */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
412 /* methods */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
413 (destructor)filter_dealloc, /* tp_dealloc */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
414 0, /* tp_print */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
415 0, /* tp_getattr */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
416 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51245
diff
changeset
|
417 0, /* tp_reserved */ |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
418 0, /* tp_repr */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
419 0, /* tp_as_number */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
420 0, /* tp_as_sequence */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
421 0, /* tp_as_mapping */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
422 0, /* tp_hash */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
423 0, /* tp_call */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
424 0, /* tp_str */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
425 PyObject_GenericGetAttr, /* tp_getattro */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
426 0, /* tp_setattro */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
427 0, /* tp_as_buffer */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
428 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
429 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
430 filter_doc, /* tp_doc */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
431 (traverseproc)filter_traverse, /* tp_traverse */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
432 0, /* tp_clear */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
433 0, /* tp_richcompare */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
434 0, /* tp_weaklistoffset */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
435 PyObject_SelfIter, /* tp_iter */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
436 (iternextfunc)filter_next, /* tp_iternext */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
437 0, /* tp_methods */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
438 0, /* tp_members */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
439 0, /* tp_getset */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
440 0, /* tp_base */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
441 0, /* tp_dict */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
442 0, /* tp_descr_get */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
443 0, /* tp_descr_set */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
444 0, /* tp_dictoffset */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
445 0, /* tp_init */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
446 PyType_GenericAlloc, /* tp_alloc */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
447 filter_new, /* tp_new */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
448 PyObject_GC_Del, /* tp_free */ |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
449 }; |
|
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
450 |
| 8561 | 451 |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
452 static PyObject * |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
453 builtin_format(PyObject *self, PyObject *args) |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
454 { |
|
44273
eb2260dcb365
Fixed #1593 spacing of the builtin_format function is inconsistent. Thanks to Joseph for the fix
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
455 PyObject *value; |
|
45382
7af955843929
Fixes for shared 2.6 code that implements PEP 3101, advanced string
Eric Smith <eric@trueblade.com>
parents:
45086
diff
changeset
|
456 PyObject *format_spec = NULL; |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
457 |
|
45382
7af955843929
Fixes for shared 2.6 code that implements PEP 3101, advanced string
Eric Smith <eric@trueblade.com>
parents:
45086
diff
changeset
|
458 if (!PyArg_ParseTuple(args, "O|U:format", &value, &format_spec)) |
|
7af955843929
Fixes for shared 2.6 code that implements PEP 3101, advanced string
Eric Smith <eric@trueblade.com>
parents:
45086
diff
changeset
|
459 return NULL; |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
460 |
|
45382
7af955843929
Fixes for shared 2.6 code that implements PEP 3101, advanced string
Eric Smith <eric@trueblade.com>
parents:
45086
diff
changeset
|
461 return PyObject_Format(value, format_spec); |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
462 } |
|
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
463 |
|
43110
cdb7b9f82cc4
Added test cases for string.Formatter subclassing.
Eric Smith <eric@trueblade.com>
parents:
42899
diff
changeset
|
464 PyDoc_STRVAR(format_doc, |
|
cdb7b9f82cc4
Added test cases for string.Formatter subclassing.
Eric Smith <eric@trueblade.com>
parents:
42899
diff
changeset
|
465 "format(value[, format_spec]) -> string\n\ |
|
cdb7b9f82cc4
Added test cases for string.Formatter subclassing.
Eric Smith <eric@trueblade.com>
parents:
42899
diff
changeset
|
466 \n\ |
|
cdb7b9f82cc4
Added test cases for string.Formatter subclassing.
Eric Smith <eric@trueblade.com>
parents:
42899
diff
changeset
|
467 Returns value.__format__(format_spec)\n\ |
|
cdb7b9f82cc4
Added test cases for string.Formatter subclassing.
Eric Smith <eric@trueblade.com>
parents:
42899
diff
changeset
|
468 format_spec defaults to \"\""); |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
469 |
|
41609
92ead87bf984
Add 8-bit chr() back as chr8().
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
470 static PyObject * |
|
41955
4c5fbe65b7de
Make the name of the C variables match the Python names
Walter Dörwald <walter@livinglogic.de>
parents:
41888
diff
changeset
|
471 builtin_chr(PyObject *self, PyObject *args) |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
472 { |
|
48601
a476ef5eebad
Merged revisions 65339-65340,65342 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48432
diff
changeset
|
473 int x; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
474 |
|
48601
a476ef5eebad
Merged revisions 65339-65340,65342 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48432
diff
changeset
|
475 if (!PyArg_ParseTuple(args, "i:chr", &x)) |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
476 return NULL; |
|
18282
f38923ce3c6b
more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
Fredrik Lundh <fredrik@pythonware.com>
parents:
18281
diff
changeset
|
477 |
|
24737
eaa87632b1e8
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
Marc-André Lemburg <mal@egenix.com>
parents:
24071
diff
changeset
|
478 return PyUnicode_FromOrdinal(x); |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
479 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
480 |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
481 PyDoc_VAR(chr_doc) = PyDoc_STR( |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
482 "chr(i) -> Unicode character\n\ |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
483 \n\ |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
484 Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff." |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
485 ) |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
486 #ifndef Py_UNICODE_WIDE |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
487 PyDoc_STR( |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
488 "\nIf 0x10000 <= i, a surrogate pair is returned." |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
489 ) |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
490 #endif |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
491 ; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
492 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
493 |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
494 static char * |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
495 source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf) |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
496 { |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
497 char *str; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
498 Py_ssize_t size; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
499 |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
500 if (PyUnicode_Check(cmd)) { |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
501 cf->cf_flags |= PyCF_IGNORE_COOKIE; |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
502 cmd = _PyUnicode_AsDefaultEncodedString(cmd, NULL); |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
503 if (cmd == NULL) |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
504 return NULL; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
505 } |
|
42898
0020bc784c76
Some changes in preparation of stricter rules about mixing str and bytes.
Guido van Rossum <guido@python.org>
parents:
42854
diff
changeset
|
506 else if (!PyObject_CheckReadBuffer(cmd)) { |
|
48883
f27ccfdea834
#3706: fix error message for wrong exec() argument type. R=Guido.
Georg Brandl <georg@python.org>
parents:
48660
diff
changeset
|
507 PyErr_Format(PyExc_TypeError, |
|
f27ccfdea834
#3706: fix error message for wrong exec() argument type. R=Guido.
Georg Brandl <georg@python.org>
parents:
48660
diff
changeset
|
508 "%s() arg 1 must be a %s object", |
|
f27ccfdea834
#3706: fix error message for wrong exec() argument type. R=Guido.
Georg Brandl <georg@python.org>
parents:
48660
diff
changeset
|
509 funcname, what); |
|
42898
0020bc784c76
Some changes in preparation of stricter rules about mixing str and bytes.
Guido van Rossum <guido@python.org>
parents:
42854
diff
changeset
|
510 return NULL; |
|
0020bc784c76
Some changes in preparation of stricter rules about mixing str and bytes.
Guido van Rossum <guido@python.org>
parents:
42854
diff
changeset
|
511 } |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
512 if (PyObject_AsReadBuffer(cmd, (const void **)&str, &size) < 0) { |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
513 return NULL; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
514 } |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
515 if (strlen(str) != size) { |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
516 PyErr_SetString(PyExc_TypeError, |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
517 "source code string cannot contain null bytes"); |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
518 return NULL; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
519 } |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
520 return str; |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
521 } |
|
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
522 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
523 static PyObject * |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
524 builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
525 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
526 char *str; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
527 char *filename; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
528 char *startstr; |
|
46227
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
529 int mode = -1; |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
530 int dont_inherit = 0; |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
531 int supplied_flags = 0; |
|
57675
087fe5fa113c
Merged revisions 76534,76538,76628,76701,76774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56751
diff
changeset
|
532 int is_ast; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
533 PyCompilerFlags cf; |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
534 PyObject *cmd; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
535 static char *kwlist[] = {"source", "filename", "mode", "flags", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
536 "dont_inherit", NULL}; |
|
46227
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
537 int start[] = {Py_file_input, Py_eval_input, Py_single_input}; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
538 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
539 if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oss|ii:compile", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
540 kwlist, &cmd, &filename, &startstr, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
541 &supplied_flags, &dont_inherit)) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
542 return NULL; |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
543 |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
544 cf.cf_flags = supplied_flags | PyCF_SOURCE_IS_UTF8; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
545 |
|
27878
be7683a6f521
- Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents:
27795
diff
changeset
|
546 if (supplied_flags & |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36604
diff
changeset
|
547 ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST)) |
|
27878
be7683a6f521
- Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents:
27795
diff
changeset
|
548 { |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
549 PyErr_SetString(PyExc_ValueError, |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
550 "compile(): unrecognised flags"); |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
551 return NULL; |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
552 } |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
553 /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
554 |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
555 if (!dont_inherit) { |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
556 PyEval_MergeCompilerFlags(&cf); |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
557 } |
|
46208
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
558 |
|
46227
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
559 if (strcmp(startstr, "exec") == 0) |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
560 mode = 0; |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
561 else if (strcmp(startstr, "eval") == 0) |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
562 mode = 1; |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
563 else if (strcmp(startstr, "single") == 0) |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
564 mode = 2; |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
565 else { |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
566 PyErr_SetString(PyExc_ValueError, |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
567 "compile() arg 3 must be 'exec', 'eval' or 'single'"); |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
568 return NULL; |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
569 } |
|
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
570 |
|
57675
087fe5fa113c
Merged revisions 76534,76538,76628,76701,76774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56751
diff
changeset
|
571 is_ast = PyAST_Check(cmd); |
|
087fe5fa113c
Merged revisions 76534,76538,76628,76701,76774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56751
diff
changeset
|
572 if (is_ast == -1) |
|
087fe5fa113c
Merged revisions 76534,76538,76628,76701,76774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56751
diff
changeset
|
573 return NULL; |
|
087fe5fa113c
Merged revisions 76534,76538,76628,76701,76774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
56751
diff
changeset
|
574 if (is_ast) { |
|
46208
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
575 PyObject *result; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
576 if (supplied_flags & PyCF_ONLY_AST) { |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
577 Py_INCREF(cmd); |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
578 result = cmd; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
579 } |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
580 else { |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
581 PyArena *arena; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
582 mod_ty mod; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
583 |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
584 arena = PyArena_New(); |
|
46227
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
585 mod = PyAST_obj2mod(cmd, arena, mode); |
|
46208
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
586 if (mod == NULL) { |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
587 PyArena_Free(arena); |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
588 return NULL; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
589 } |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
590 result = (PyObject*)PyAST_Compile(mod, filename, |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
591 &cf, arena); |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
592 PyArena_Free(arena); |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
593 } |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
594 return result; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
595 } |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
596 |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
597 str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf); |
|
46208
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
598 if (str == NULL) |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
599 return NULL; |
|
ea75b12fe8e7
Merged revisions 62004 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
45738
diff
changeset
|
600 |
|
46227
b2d93a960b98
Merged revisions 62039-62042 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
46208
diff
changeset
|
601 return Py_CompileStringFlags(str, filename, start[mode], &cf); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
602 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
603 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
604 PyDoc_STRVAR(compile_doc, |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
605 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\ |
| 8561 | 606 \n\ |
| 607 Compile the source string (a Python module, statement or expression)\n\ | |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
608 into a code object that can be executed by exec() or eval().\n\ |
| 8561 | 609 The filename will be used for run-time error messages.\n\ |
| 610 The mode must be 'exec' to compile a module, 'single' to compile a\n\ | |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
611 single (interactive) statement, or 'eval' to compile an expression.\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
612 The flags argument, if present, controls which future statements influence\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
613 the compilation of the code.\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
614 The dont_inherit argument, if non-zero, stops the compilation inheriting\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
615 the effects of any future statements in effect in the code calling\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
616 compile; if absent or zero these statements do influence the compilation,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
617 in addition to any features explicitly specified."); |
| 8561 | 618 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
619 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
620 builtin_dir(PyObject *self, PyObject *args) |
| 86 | 621 { |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
622 PyObject *arg = NULL; |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
623 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
624 if (!PyArg_UnpackTuple(args, "dir", 0, 1, &arg)) |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
625 return NULL; |
|
19705
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19670
diff
changeset
|
626 return PyObject_Dir(arg); |
| 86 | 627 } |
| 628 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
629 PyDoc_STRVAR(dir_doc, |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
630 "dir([object]) -> list of strings\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
631 "\n" |
|
41107
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
632 "If called without an argument, return the names in the current scope.\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
633 "Else, return an alphabetized list of names comprising (some of) the attributes\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
634 "of the given object, and of attributes reachable from it.\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
635 "If the object supplies a method named __dir__, it will be used; otherwise\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
636 "the default dir() logic is used and returns:\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
637 " for a module object: the module's attributes.\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
638 " for a class object: its attributes, and recursively the attributes\n" |
|
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
639 " of its bases.\n" |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
640 " for any other object: its attributes, its class's attributes, and\n" |
|
41107
cf452027073e
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Georg Brandl <georg@python.org>
parents:
40933
diff
changeset
|
641 " recursively the attributes of its class's base classes."); |
| 8561 | 642 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
643 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
644 builtin_divmod(PyObject *self, PyObject *args) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
645 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
646 PyObject *v, *w; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
647 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
648 if (!PyArg_UnpackTuple(args, "divmod", 2, 2, &v, &w)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
649 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
650 return PyNumber_Divmod(v, w); |
| 86 | 651 } |
| 652 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
653 PyDoc_STRVAR(divmod_doc, |
| 8561 | 654 "divmod(x, y) -> (div, mod)\n\ |
| 655 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
656 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); |
| 8561 | 657 |
| 658 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
659 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
660 builtin_eval(PyObject *self, PyObject *args) |
| 86 | 661 { |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
662 PyObject *cmd, *result, *tmp = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
663 PyObject *globals = Py_None, *locals = Py_None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
664 char *str; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
665 PyCompilerFlags cf; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
666 |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
667 if (!PyArg_UnpackTuple(args, "eval", 1, 3, &cmd, &globals, &locals)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
668 return NULL; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
669 if (locals != Py_None && !PyMapping_Check(locals)) { |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
670 PyErr_SetString(PyExc_TypeError, "locals must be a mapping"); |
|
32507
682f74088602
* Fix missing return after error message is set.
Raymond Hettinger <python@rcn.com>
parents:
32463
diff
changeset
|
671 return NULL; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
672 } |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
673 if (globals != Py_None && !PyDict_Check(globals)) { |
|
35500
8fa83a9ebc6e
Whitespace normalization.
Georg Brandl <georg@python.org>
parents:
35364
diff
changeset
|
674 PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ? |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
675 "globals must be a real dict; try eval(expr, {}, mapping)" |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
676 : "globals must be a dict"); |
|
32507
682f74088602
* Fix missing return after error message is set.
Raymond Hettinger <python@rcn.com>
parents:
32463
diff
changeset
|
677 return NULL; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
678 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
679 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
680 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
681 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
682 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
683 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
684 else if (locals == Py_None) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
685 locals = globals; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
686 |
|
35567
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
687 if (globals == NULL || locals == NULL) { |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
688 PyErr_SetString(PyExc_TypeError, |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
689 "eval must be given globals and locals " |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
690 "when called without a frame"); |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
691 return NULL; |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
692 } |
|
fa0881fd49b7
bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault.
Georg Brandl <georg@python.org>
parents:
35500
diff
changeset
|
693 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
694 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
695 if (PyDict_SetItemString(globals, "__builtins__", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
696 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
697 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
698 } |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
699 |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
700 if (PyCode_Check(cmd)) { |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21077
diff
changeset
|
701 if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) { |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
702 PyErr_SetString(PyExc_TypeError, |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
703 "code object passed to eval() may not contain free variables"); |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
704 return NULL; |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
705 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
706 return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals); |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
707 } |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
708 |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
709 cf.cf_flags = PyCF_SOURCE_IS_UTF8; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
710 str = source_as_string(cmd, "eval", "string, bytes or code", &cf); |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
711 if (str == NULL) |
| 86 | 712 return NULL; |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
713 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
714 while (*str == ' ' || *str == '\t') |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
715 str++; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
716 |
|
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
717 (void)PyEval_MergeCompilerFlags(&cf); |
|
27781
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
718 result = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf); |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
719 Py_XDECREF(tmp); |
|
cc01fb654ce3
patch #683515: "Add unicode support to compile(), eval() and exec"
Just van Rossum <just@letterror.com>
parents:
27681
diff
changeset
|
720 return result; |
| 86 | 721 } |
| 722 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
723 PyDoc_STRVAR(eval_doc, |
| 8561 | 724 "eval(source[, globals[, locals]]) -> value\n\ |
| 725 \n\ | |
| 726 Evaluate the source in the context of globals and locals.\n\ | |
| 727 The source may be a string representing a Python expression\n\ | |
| 728 or a code object as returned by compile().\n\ | |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40411
diff
changeset
|
729 The globals must be a dictionary and locals can be any mapping,\n\ |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
730 defaulting to the current globals and locals.\n\ |
|
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31837
diff
changeset
|
731 If only globals is given, locals defaults to it.\n"); |
| 8561 | 732 |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
733 static PyObject * |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
734 builtin_exec(PyObject *self, PyObject *args) |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
735 { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
736 PyObject *v; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
737 PyObject *prog, *globals = Py_None, *locals = Py_None; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
738 int plain = 0; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
739 |
|
50615
45aef53f5c71
Mini-optimization: use pack/unpack functions for argument tuples.
Raymond Hettinger <python@rcn.com>
parents:
50586
diff
changeset
|
740 if (!PyArg_UnpackTuple(args, "exec", 1, 3, &prog, &globals, &locals)) |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
741 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
742 |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
743 if (globals == Py_None) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
744 globals = PyEval_GetGlobals(); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
745 if (locals == Py_None) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
746 locals = PyEval_GetLocals(); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
747 plain = 1; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
748 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
749 if (!globals || !locals) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
750 PyErr_SetString(PyExc_SystemError, |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
751 "globals and locals cannot be NULL"); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
752 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
753 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
754 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
755 else if (locals == Py_None) |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
756 locals = globals; |
|
48883
f27ccfdea834
#3706: fix error message for wrong exec() argument type. R=Guido.
Georg Brandl <georg@python.org>
parents:
48660
diff
changeset
|
757 |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
758 if (!PyDict_Check(globals)) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
759 PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.100s", |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
760 globals->ob_type->tp_name); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
761 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
762 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
763 if (!PyMapping_Check(locals)) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
764 PyErr_Format(PyExc_TypeError, |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
765 "arg 3 must be a mapping or None, not %.100s", |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
766 locals->ob_type->tp_name); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
767 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
768 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
769 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
770 if (PyDict_SetItemString(globals, "__builtins__", |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
771 PyEval_GetBuiltins()) != 0) |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
772 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
773 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
774 |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
775 if (PyCode_Check(prog)) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
776 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) { |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
777 PyErr_SetString(PyExc_TypeError, |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
778 "code object passed to exec() may not " |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
779 "contain free variables"); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
780 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
781 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
782 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
783 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
784 else { |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
785 char *str; |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
786 PyCompilerFlags cf; |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
787 cf.cf_flags = PyCF_SOURCE_IS_UTF8; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
788 str = source_as_string(prog, "exec", |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51270
diff
changeset
|
789 "string, bytes or code", &cf); |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
790 if (str == NULL) |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
791 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
792 if (PyEval_MergeCompilerFlags(&cf)) |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
793 v = PyRun_StringFlags(str, Py_file_input, globals, |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
794 locals, &cf); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
795 else |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
796 v = PyRun_String(str, Py_file_input, globals, locals); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
797 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
798 if (v == NULL) |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
799 return NULL; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
800 Py_DECREF(v); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
801 Py_RETURN_NONE; |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
802 } |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
803 |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
804 PyDoc_STRVAR(exec_doc, |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
805 "exec(object[, globals[, locals]])\n\ |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
806 \n\ |
|
57793
a08840ce88d3
Fix typo (reported by terlop on IRC)
Mark Dickinson <dickinsm@gmail.com>
parents:
57675
diff
changeset
|
807 Read and execute code from an object, which can be a string or a code\n\ |
|
50586
1146b7b0d518
#4826 exec() doesn't take a file object anymore
Benjamin Peterson <benjamin@python.org>
parents:
50076
diff
changeset
|
808 object.\n\ |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
809 The globals and locals are dictionaries, defaulting to the current\n\ |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
810 globals and locals. If only globals is given, locals defaults to it."); |
|
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
811 |
| 8561 | 812 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
813 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
814 builtin_getattr(PyObject *self, PyObject *args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
815 { |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42817
diff
changeset
|
816 PyObject *v, *result, *dflt = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
817 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
818 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
819 if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
820 return NULL; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
821 |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
822 if (!PyUnicode_Check(name)) { |
|
18888
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
823 PyErr_SetString(PyExc_TypeError, |
|
28740
d3297e298211
some more error-message enhancements
Alex Martelli <aleaxit@gmail.com>
parents:
28738
diff
changeset
|
824 "getattr(): attribute name must be string"); |
|
18888
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
825 return NULL; |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
826 } |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
827 result = PyObject_GetAttr(v, name); |
|
20471
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
828 if (result == NULL && dflt != NULL && |
|
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
829 PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
830 { |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
831 PyErr_Clear(); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
832 Py_INCREF(dflt); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
833 result = dflt; |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
834 } |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
835 return result; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
836 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
837 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
838 PyDoc_STRVAR(getattr_doc, |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
839 "getattr(object, name[, default]) -> value\n\ |
| 8561 | 840 \n\ |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
841 Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\ |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
842 When a default argument is given, it is returned when the attribute doesn't\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
843 exist; without it, an exception is raised in that case."); |
| 8561 | 844 |
| 845 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
846 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
847 builtin_globals(PyObject *self) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
848 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
849 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
850 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
851 d = PyEval_GetGlobals(); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
852 Py_XINCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
853 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
854 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
855 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
856 PyDoc_STRVAR(globals_doc, |
| 8561 | 857 "globals() -> dictionary\n\ |
| 858 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
859 Return the dictionary containing the current scope's global variables."); |
| 8561 | 860 |
| 861 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
862 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
863 builtin_hasattr(PyObject *self, PyObject *args) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
864 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
865 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
866 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
867 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
868 if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
869 return NULL; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41969
diff
changeset
|
870 if (!PyUnicode_Check(name)) { |
|
18890
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
871 PyErr_SetString(PyExc_TypeError, |
|
28740
d3297e298211
some more error-message enhancements
Alex Martelli <aleaxit@gmail.com>
parents:
28738
diff
changeset
|
872 "hasattr(): attribute name must be string"); |
|
18890
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
873 return NULL; |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
874 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
875 v = PyObject_GetAttr(v, name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
876 if (v == NULL) { |
|
47080
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
877 if (!PyErr_ExceptionMatches(PyExc_Exception)) |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
878 return NULL; |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
879 else { |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
880 PyErr_Clear(); |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
881 Py_INCREF(Py_False); |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
882 return Py_False; |
|
58a0d5524f9a
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46606
diff
changeset
|
883 } |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
884 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
885 Py_DECREF(v); |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
886 Py_INCREF(Py_True); |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
887 return Py_True; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
888 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
889 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
890 PyDoc_STRVAR(hasattr_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
891 "hasattr(object, name) -> bool\n\ |
| 8561 | 892 \n\ |
| 893 Return whether the object has an attribute with the given name.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
894 (This is done by calling getattr(object, name) and catching exceptions.)"); |
| 8561 | 895 |
| 896 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
897 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
898 builtin_id(PyObject *self, PyObject *v) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
899 { |
| 13078 | 900 return PyLong_FromVoidPtr(v); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
901 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
902 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
903 PyDoc_STRVAR(id_doc, |
| 8561 | 904 "id(object) -> integer\n\ |
| 905 \n\ | |
| 906 Return the identity of an object. This is guaranteed to be unique among\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
907 simultaneously existing objects. (Hint: it's the object's memory address.)"); |
| 8561 | 908 |
| 909 | |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
910 /* map object ************************************************************/ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
911 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
912 typedef struct { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
913 PyObject_HEAD |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
914 PyObject *iters; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
915 PyObject *func; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
916 } mapobject; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
917 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
918 static PyObject * |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
919 map_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
920 { |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
921 PyObject *it, *iters, *func; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
922 mapobject *lz; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
923 Py_ssize_t numargs, i; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
924 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
925 if (type == &PyMap_Type && !_PyArg_NoKeywords("map()", kwds)) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
926 return NULL; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
927 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
928 numargs = PyTuple_Size(args); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
929 if (numargs < 2) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
930 PyErr_SetString(PyExc_TypeError, |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
931 "map() must have at least two arguments."); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
932 return NULL; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
933 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
934 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
935 iters = PyTuple_New(numargs-1); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
936 if (iters == NULL) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
937 return NULL; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
938 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
939 for (i=1 ; i<numargs ; i++) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
940 /* Get iterator. */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
941 it = PyObject_GetIter(PyTuple_GET_ITEM(args, i)); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
942 if (it == NULL) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
943 Py_DECREF(iters); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
944 return NULL; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
945 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
946 PyTuple_SET_ITEM(iters, i-1, it); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
947 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
948 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
949 /* create mapobject structure */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
950 lz = (mapobject *)type->tp_alloc(type, 0); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
951 if (lz == NULL) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
952 Py_DECREF(iters); |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
953 return NULL; |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
954 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
955 lz->iters = iters; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
956 func = PyTuple_GET_ITEM(args, 0); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
957 Py_INCREF(func); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
958 lz->func = func; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
959 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
960 return (PyObject *)lz; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
961 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
962 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
963 static void |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
964 map_dealloc(mapobject *lz) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
965 { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
966 PyObject_GC_UnTrack(lz); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
967 Py_XDECREF(lz->iters); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
968 Py_XDECREF(lz->func); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
969 Py_TYPE(lz)->tp_free(lz); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
970 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
971 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
972 static int |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
973 map_traverse(mapobject *lz, visitproc visit, void *arg) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
974 { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
975 Py_VISIT(lz->iters); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
976 Py_VISIT(lz->func); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
977 return 0; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
978 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
979 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
980 static PyObject * |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
981 map_next(mapobject *lz) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
982 { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
983 PyObject *val; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
984 PyObject *argtuple; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
985 PyObject *result; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
986 Py_ssize_t numargs, i; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
987 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
988 numargs = PyTuple_Size(lz->iters); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
989 argtuple = PyTuple_New(numargs); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
990 if (argtuple == NULL) |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
991 return NULL; |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
992 |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
993 for (i=0 ; i<numargs ; i++) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
994 val = PyIter_Next(PyTuple_GET_ITEM(lz->iters, i)); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
995 if (val == NULL) { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
996 Py_DECREF(argtuple); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
997 return NULL; |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
998 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
999 PyTuple_SET_ITEM(argtuple, i, val); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1000 } |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1001 result = PyObject_Call(lz->func, argtuple, NULL); |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1002 Py_DECREF(argtuple); |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1003 return result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1004 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1005 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1006 PyDoc_STRVAR(map_doc, |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1007 "map(func, *iterables) --> map object\n\ |
| 8561 | 1008 \n\ |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1009 Make an iterator that computes the function using arguments from\n\ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1010 each of the iterables. Stops when the shortest iterable is exhausted."); |
| 8561 | 1011 |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1012 PyTypeObject PyMap_Type = { |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1013 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1014 "map", /* tp_name */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1015 sizeof(mapobject), /* tp_basicsize */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1016 0, /* tp_itemsize */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1017 /* methods */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1018 (destructor)map_dealloc, /* tp_dealloc */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1019 0, /* tp_print */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1020 0, /* tp_getattr */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1021 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51245
diff
changeset
|
1022 0, /* tp_reserved */ |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1023 0, /* tp_repr */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1024 0, /* tp_as_number */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1025 0, /* tp_as_sequence */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1026 0, /* tp_as_mapping */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1027 0, /* tp_hash */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1028 0, /* tp_call */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1029 0, /* tp_str */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1030 PyObject_GenericGetAttr, /* tp_getattro */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1031 0, /* tp_setattro */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1032 0, /* tp_as_buffer */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1033 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1034 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1035 map_doc, /* tp_doc */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1036 (traverseproc)map_traverse, /* tp_traverse */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1037 0, /* tp_clear */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1038 0, /* tp_richcompare */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1039 0, /* tp_weaklistoffset */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1040 PyObject_SelfIter, /* tp_iter */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1041 (iternextfunc)map_next, /* tp_iternext */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1042 0, /* tp_methods */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1043 0, /* tp_members */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1044 0, /* tp_getset */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1045 0, /* tp_base */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1046 0, /* tp_dict */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1047 0, /* tp_descr_get */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1048 0, /* tp_descr_set */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1049 0, /* tp_dictoffset */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1050 0, /* tp_init */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1051 PyType_GenericAlloc, /* tp_alloc */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1052 map_new, /* tp_new */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1053 PyObject_GC_Del, /* tp_free */ |
|
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
1054 }; |
| 8561 | 1055 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1056 static PyObject * |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1057 builtin_next(PyObject *self, PyObject *args) |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1058 { |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1059 PyObject *it, *res; |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1060 PyObject *def = NULL; |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1061 |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1062 if (!PyArg_UnpackTuple(args, "next", 1, 2, &it, &def)) |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1063 return NULL; |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1064 if (!PyIter_Check(it)) { |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1065 PyErr_Format(PyExc_TypeError, |
|
46606
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1066 "%.200s object is not an iterator", |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1067 it->ob_type->tp_name); |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1068 return NULL; |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1069 } |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1070 |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1071 res = (*it->ob_type->tp_iternext)(it); |
|
46606
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1072 if (res != NULL) { |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1073 return res; |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1074 } else if (def != NULL) { |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1075 if (PyErr_Occurred()) { |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1076 if(!PyErr_ExceptionMatches(PyExc_StopIteration)) |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1077 return NULL; |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1078 PyErr_Clear(); |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1079 } |
|
46606
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1080 Py_INCREF(def); |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1081 return def; |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1082 } else if (PyErr_Occurred()) { |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1083 return NULL; |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1084 } else { |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1085 PyErr_SetNone(PyExc_StopIteration); |
|
af0ef04401bb
Fix nits in builtin next().
Georg Brandl <georg@python.org>
parents:
46227
diff
changeset
|
1086 return NULL; |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1087 } |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1088 } |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1089 |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1090 PyDoc_STRVAR(next_doc, |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1091 "next(iterator[, default])\n\ |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1092 \n\ |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1093 Return the next item from the iterator. If default is given and the iterator\n\ |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1094 is exhausted, it is returned instead of raising StopIteration."); |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1095 |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1096 |
|
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
1097 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1098 builtin_setattr(PyObject *self, PyObject *args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1099 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1100 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1101 PyObject *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1102 PyObject *value; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1103 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1104 if (!PyArg_UnpackTuple(args, "setattr", 3, 3, &v, &name, &value)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1105 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1106 if (PyObject_SetAttr(v, name, value) != 0) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1107 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1108 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1109 return Py_None; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1110 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1111 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1112 PyDoc_STRVAR(setattr_doc, |
| 8561 | 1113 "setattr(object, name, value)\n\ |
| 1114 \n\ | |
| 1115 Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1116 ``x.y = v''."); |
| 8561 | 1117 |
| 1118 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1119 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1120 builtin_delattr(PyObject *self, PyObject *args) |
| 1843 | 1121 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1122 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1123 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1124 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1125 if (!PyArg_UnpackTuple(args, "delattr", 2, 2, &v, &name)) |
| 1843 | 1126 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1127 if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0) |
| 1843 | 1128 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1129 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1130 return Py_None; |
| 1843 | 1131 } |
| 1132 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1133 PyDoc_STRVAR(delattr_doc, |
|
9514
a126107c433a
Fix cosmetic bug in delattr docstring discovered by JvR.
Guido van Rossum <guido@python.org>
parents:
9188
diff
changeset
|
1134 "delattr(object, name)\n\ |
| 8561 | 1135 \n\ |
| 1136 Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1137 ``del x.y''."); |
| 8561 | 1138 |
| 1139 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1140 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1141 builtin_hash(PyObject *self, PyObject *v) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1142 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1143 long x; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1144 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1145 x = PyObject_Hash(v); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1146 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1147 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1148 return PyLong_FromLong(x); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1149 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1150 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1151 PyDoc_STRVAR(hash_doc, |
| 8561 | 1152 "hash(object) -> integer\n\ |
| 1153 \n\ | |
| 1154 Return a hash value for the object. Two objects with the same value have\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1155 the same hash value. The reverse is not necessarily true, but likely."); |
| 8561 | 1156 |
| 1157 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1158 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1159 builtin_hex(PyObject *self, PyObject *v) |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1160 { |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
1161 return PyNumber_ToBase(v, 16); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1162 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1163 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1164 PyDoc_STRVAR(hex_doc, |
| 8561 | 1165 "hex(number) -> string\n\ |
| 1166 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1167 Return the hexadecimal representation of an integer or long integer."); |
| 8561 | 1168 |
| 1169 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1170 static PyObject * |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1171 builtin_iter(PyObject *self, PyObject *args) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1172 { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1173 PyObject *v, *w = NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1174 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1175 if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w)) |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1176 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1177 if (w == NULL) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1178 return PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1179 if (!PyCallable_Check(v)) { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1180 PyErr_SetString(PyExc_TypeError, |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1181 "iter(v, w): v must be callable"); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1182 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1183 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1184 return PyCallIter_New(v, w); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1185 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1186 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1187 PyDoc_STRVAR(iter_doc, |
|
47097
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
1188 "iter(iterable) -> iterator\n\ |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1189 iter(callable, sentinel) -> iterator\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1190 \n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1191 Get an iterator from an object. In the first form, the argument must\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1192 supply its own iterator, or be a sequence.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1193 In the second form, the callable is called until it returns the sentinel."); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1194 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1195 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1196 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1197 builtin_len(PyObject *self, PyObject *v) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1198 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36484
diff
changeset
|
1199 Py_ssize_t res; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1200 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13447
diff
changeset
|
1201 res = PyObject_Size(v); |
|
8589
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1202 if (res < 0 && PyErr_Occurred()) |
|
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1203 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1204 return PyLong_FromSsize_t(res); |
| 86 | 1205 } |
| 1206 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1207 PyDoc_STRVAR(len_doc, |
| 8561 | 1208 "len(object) -> integer\n\ |
| 1209 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1210 Return the number of items of a sequence or mapping."); |
| 8561 | 1211 |
| 1212 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1213 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1214 builtin_locals(PyObject *self) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1215 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1216 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1217 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1218 d = PyEval_GetLocals(); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39603
diff
changeset
|
1219 Py_XINCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1220 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1221 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1222 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1223 PyDoc_STRVAR(locals_doc, |
| 8561 | 1224 "locals() -> dictionary\n\ |
| 1225 \n\ | |
|
27076
753306f9b0a0
SF bug #655271: Slightly modify locals() doc
Raymond Hettinger <python@rcn.com>
parents:
26824
diff
changeset
|
1226 Update and return a dictionary containing the current scope's local variables."); |
| 8561 | 1227 |
| 1228 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1229 static PyObject * |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1230 min_max(PyObject *args, PyObject *kwds, int op) |
| 86 | 1231 { |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1232 PyObject *v, *it, *item, *val, *maxitem, *maxval, *keyfunc=NULL; |
|
33099
ce016d0ec701
Patch #1005468: Disambiguate "min() or max()" exception string.
Martin v. Löwis <martin@v.loewis.de>
parents:
33019
diff
changeset
|
1233 const char *name = op == Py_LT ? "min" : "max"; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1234 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1235 if (PyTuple_Size(args) > 1) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1236 v = args; |
|
33099
ce016d0ec701
Patch #1005468: Disambiguate "min() or max()" exception string.
Martin v. Löwis <martin@v.loewis.de>
parents:
33019
diff
changeset
|
1237 else if (!PyArg_UnpackTuple(args, (char *)name, 1, 1, &v)) |
| 86 | 1238 return NULL; |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1239 |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1240 if (kwds != NULL && PyDict_Check(kwds) && PyDict_Size(kwds)) { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1241 keyfunc = PyDict_GetItemString(kwds, "key"); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1242 if (PyDict_Size(kwds)!=1 || keyfunc == NULL) { |
|
35500
8fa83a9ebc6e
Whitespace normalization.
Georg Brandl <georg@python.org>
parents:
35364
diff
changeset
|
1243 PyErr_Format(PyExc_TypeError, |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1244 "%s() got an unexpected keyword argument", name); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1245 return NULL; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1246 } |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1247 Py_INCREF(keyfunc); |
|
35500
8fa83a9ebc6e
Whitespace normalization.
Georg Brandl <georg@python.org>
parents:
35364
diff
changeset
|
1248 } |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1249 |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1250 it = PyObject_GetIter(v); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1251 if (it == NULL) { |
|
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1252 Py_XDECREF(keyfunc); |
| 86 | 1253 return NULL; |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1254 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1255 |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1256 maxitem = NULL; /* the result */ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1257 maxval = NULL; /* the value associated with the result */ |
|
34123
4e8fb12f8378
Put parentheses around the assignment in the 'while' loop conditional
Brett Cannon <bcannon@gmail.com>
parents:
34085
diff
changeset
|
1258 while (( item = PyIter_Next(it) )) { |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1259 /* get the value from the key function */ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1260 if (keyfunc != NULL) { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1261 val = PyObject_CallFunctionObjArgs(keyfunc, item, NULL); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1262 if (val == NULL) |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1263 goto Fail_it_item; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1264 } |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1265 /* no key function; the value is the item */ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1266 else { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1267 val = item; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1268 Py_INCREF(val); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1269 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1270 |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1271 /* maximum value and item are unset; set them */ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1272 if (maxval == NULL) { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1273 maxitem = item; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1274 maxval = val; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1275 } |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1276 /* maximum value and item are set; update them as necessary */ |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1277 else { |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1278 int cmp = PyObject_RichCompareBool(val, maxval, op); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1279 if (cmp < 0) |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1280 goto Fail_it_item_and_val; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1281 else if (cmp > 0) { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1282 Py_DECREF(maxval); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1283 Py_DECREF(maxitem); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1284 maxval = val; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1285 maxitem = item; |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1286 } |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1287 else { |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1288 Py_DECREF(item); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1289 Py_DECREF(val); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1290 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1291 } |
| 86 | 1292 } |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1293 if (PyErr_Occurred()) |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1294 goto Fail_it; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1295 if (maxval == NULL) { |
|
33099
ce016d0ec701
Patch #1005468: Disambiguate "min() or max()" exception string.
Martin v. Löwis <martin@v.loewis.de>
parents:
33019
diff
changeset
|
1296 PyErr_Format(PyExc_ValueError, |
|
ce016d0ec701
Patch #1005468: Disambiguate "min() or max()" exception string.
Martin v. Löwis <martin@v.loewis.de>
parents:
33019
diff
changeset
|
1297 "%s() arg is an empty sequence", name); |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1298 assert(maxitem == NULL); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1299 } |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1300 else |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1301 Py_DECREF(maxval); |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1302 Py_DECREF(it); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1303 Py_XDECREF(keyfunc); |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1304 return maxitem; |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1305 |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1306 Fail_it_item_and_val: |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1307 Py_DECREF(val); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1308 Fail_it_item: |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1309 Py_DECREF(item); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1310 Fail_it: |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1311 Py_XDECREF(maxval); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1312 Py_XDECREF(maxitem); |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1313 Py_DECREF(it); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44881
diff
changeset
|
1314 Py_XDECREF(keyfunc); |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1315 return NULL; |
| 86 | 1316 } |
| 1317 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1318 static PyObject * |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1319 builtin_min(PyObject *self, PyObject *args, PyObject *kwds) |
| 86 | 1320 { |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1321 return min_max(args, kwds, Py_LT); |
| 86 | 1322 } |
| 1323 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1324 PyDoc_STRVAR(min_doc, |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1325 "min(iterable[, key=func]) -> value\n\ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1326 min(a, b, c, ...[, key=func]) -> value\n\ |
| 8561 | 1327 \n\ |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1328 With a single iterable argument, return its smallest item.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1329 With two or more arguments, return the smallest argument."); |
| 8561 | 1330 |
| 1331 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1332 static PyObject * |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1333 builtin_max(PyObject *self, PyObject *args, PyObject *kwds) |
| 86 | 1334 { |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1335 return min_max(args, kwds, Py_GT); |
| 86 | 1336 } |
| 1337 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1338 PyDoc_STRVAR(max_doc, |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1339 "max(iterable[, key=func]) -> value\n\ |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1340 max(a, b, c, ...[, key=func]) -> value\n\ |
| 8561 | 1341 \n\ |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
1342 With a single iterable argument, return its largest item.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1343 With two or more arguments, return the largest argument."); |
| 8561 | 1344 |
| 1345 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1346 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1347 builtin_oct(PyObject *self, PyObject *v) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1348 { |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
1349 return PyNumber_ToBase(v, 8); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1350 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1351 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1352 PyDoc_STRVAR(oct_doc, |
| 8561 | 1353 "oct(number) -> string\n\ |
| 1354 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1355 Return the octal representation of an integer or long integer."); |
| 8561 | 1356 |
| 1357 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1358 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1359 builtin_ord(PyObject *self, PyObject* obj) |
| 86 | 1360 { |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1361 long ord; |
|
36521
30aef3ce2b26
Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1362 Py_ssize_t size; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1363 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1364 if (PyBytes_Check(obj)) { |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1365 size = PyBytes_GET_SIZE(obj); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1366 if (size == 1) { |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1367 ord = (long)((unsigned char)*PyBytes_AS_STRING(obj)); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1368 return PyLong_FromLong(ord); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1369 } |
|
41452
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1370 } |
|
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1371 else if (PyUnicode_Check(obj)) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1372 size = PyUnicode_GET_SIZE(obj); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1373 if (size == 1) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1374 ord = (long)*PyUnicode_AS_UNICODE(obj); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1375 return PyLong_FromLong(ord); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1376 } |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1377 #ifndef Py_UNICODE_WIDE |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1378 if (size == 2) { |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1379 /* Decode a valid surrogate pair */ |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1380 int c0 = PyUnicode_AS_UNICODE(obj)[0]; |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1381 int c1 = PyUnicode_AS_UNICODE(obj)[1]; |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1382 if (0xD800 <= c0 && c0 <= 0xDBFF && |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1383 0xDC00 <= c1 && c1 <= 0xDFFF) { |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1384 ord = ((((c0 & 0x03FF) << 10) | (c1 & 0x03FF)) + |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1385 0x00010000); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1386 return PyLong_FromLong(ord); |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1387 } |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1388 } |
|
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1389 #endif |
|
41846
308e632702bf
Enable new I/O. Disable creation of old files.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1390 } |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47097
diff
changeset
|
1391 else if (PyByteArray_Check(obj)) { |
|
41452
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1392 /* XXX Hopefully this is temporary */ |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47097
diff
changeset
|
1393 size = PyByteArray_GET_SIZE(obj); |
|
41452
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1394 if (size == 1) { |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47097
diff
changeset
|
1395 ord = (long)((unsigned char)*PyByteArray_AS_STRING(obj)); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1396 return PyLong_FromLong(ord); |
|
41452
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1397 } |
|
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1398 } |
|
3c339de80010
Support marshal.dump(x, f) where f is not a real file.
Guido van Rossum <guido@python.org>
parents:
41226
diff
changeset
|
1399 else { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1400 PyErr_Format(PyExc_TypeError, |
|
15654
6405f30aa08c
CHange error messages for ord(), using "string" instead of "string or Unicode"
Andrew M. Kuchling <amk@amk.ca>
parents:
15637
diff
changeset
|
1401 "ord() expected string of length 1, but " \ |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1402 "%.200s found", obj->ob_type->tp_name); |
| 86 | 1403 return NULL; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1404 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1405 |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1406 PyErr_Format(PyExc_TypeError, |
|
15654
6405f30aa08c
CHange error messages for ord(), using "string" instead of "string or Unicode"
Andrew M. Kuchling <amk@amk.ca>
parents:
15637
diff
changeset
|
1407 "ord() expected a character, " |
|
36521
30aef3ce2b26
Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1408 "but string of length %zd found", |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1409 size); |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1410 return NULL; |
| 86 | 1411 } |
| 1412 | |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
1413 PyDoc_VAR(ord_doc) = PyDoc_STR( |
| 8561 | 1414 "ord(c) -> integer\n\ |
| 1415 \n\ | |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1416 Return the integer ordinal of a one-character string." |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
1417 ) |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1418 #ifndef Py_UNICODE_WIDE |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
1419 PyDoc_STR( |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1420 "\nA valid surrogate pair is also accepted." |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
1421 ) |
|
42283
18e5ae91bd29
Make chr() and ord() return/accept surrogate pairs in narrow builds.
Guido van Rossum <guido@python.org>
parents:
42142
diff
changeset
|
1422 #endif |
|
42291
3772103200ec
Three patches by Amaury Forgeot d'Arc; SF patch# 1754484.
Guido van Rossum <guido@python.org>
parents:
42283
diff
changeset
|
1423 ; |
| 8561 | 1424 |
| 1425 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1426 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1427 builtin_pow(PyObject *self, PyObject *args) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1428 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1429 PyObject *v, *w, *z = Py_None; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1430 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1431 if (!PyArg_UnpackTuple(args, "pow", 2, 3, &v, &w, &z)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1432 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1433 return PyNumber_Power(v, w, z); |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1434 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1435 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1436 PyDoc_STRVAR(pow_doc, |
| 8561 | 1437 "pow(x, y[, z]) -> number\n\ |
| 1438 \n\ | |
| 1439 With two arguments, equivalent to x**y. With three arguments,\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1440 equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."); |
| 8561 | 1441 |
| 1442 | |
|
28583
a0c002050526
Patch by Chad Netzer (with significant change):
Guido van Rossum <guido@python.org>
parents:
28513
diff
changeset
|
1443 |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1444 static PyObject * |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1445 builtin_print(PyObject *self, PyObject *args, PyObject *kwds) |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1446 { |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1447 static char *kwlist[] = {"sep", "end", "file", 0}; |
|
40922
be41da66ce37
Fix leak in the print function.
Georg Brandl <georg@python.org>
parents:
40788
diff
changeset
|
1448 static PyObject *dummy_args; |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1449 PyObject *sep = NULL, *end = NULL, *file = NULL; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1450 int i, err; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1451 |
|
40922
be41da66ce37
Fix leak in the print function.
Georg Brandl <georg@python.org>
parents:
40788
diff
changeset
|
1452 if (dummy_args == NULL) { |
|
be41da66ce37
Fix leak in the print function.
Georg Brandl <georg@python.org>
parents:
40788
diff
changeset
|
1453 if (!(dummy_args = PyTuple_New(0))) |
|
be41da66ce37
Fix leak in the print function.
Georg Brandl <georg@python.org>
parents:
40788
diff
changeset
|
1454 return NULL; |
|
be41da66ce37
Fix leak in the print function.
Georg Brandl <georg@python.org>
parents:
40788
diff
changeset
|
1455 } |
|
40788
e9a6234b26af
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
Georg Brandl <georg@python.org>
parents:
40774
diff
changeset
|
1456 if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print", |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1457 kwlist, &sep, &end, &file)) |
|
43844
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1458 return NULL; |
|
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1459 if (file == NULL || file == Py_None) { |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1460 file = PySys_GetObject("stdout"); |
|
43844
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1461 /* sys.stdout may be None when FILE* stdout isn't connected */ |
|
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1462 if (file == Py_None) |
|
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1463 Py_RETURN_NONE; |
|
2c97e24b16cf
Another #1415 fix for Windows GUI apps
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
1464 } |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1465 |
|
55057
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1466 if (sep == Py_None) { |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1467 sep = NULL; |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1468 } |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1469 else if (sep && !PyUnicode_Check(sep)) { |
|
40411
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1470 PyErr_Format(PyExc_TypeError, |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42817
diff
changeset
|
1471 "sep must be None or a string, not %.200s", |
|
40411
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1472 sep->ob_type->tp_name); |
|
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1473 return NULL; |
|
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1474 } |
|
55057
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1475 if (end == Py_None) { |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1476 end = NULL; |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1477 } |
|
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1478 else if (end && !PyUnicode_Check(end)) { |
|
40411
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1479 PyErr_Format(PyExc_TypeError, |
|
42854
824b9d52e006
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42817
diff
changeset
|
1480 "end must be None or a string, not %.200s", |
|
40411
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1481 end->ob_type->tp_name); |
|
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1482 return NULL; |
|
b3ed053cc6a1
Check "sep" and "end" for stringness in Print().
Georg Brandl <georg@python.org>
parents:
40410
diff
changeset
|
1483 } |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1484 |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1485 for (i = 0; i < PyTuple_Size(args); i++) { |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1486 if (i > 0) { |
|
55057
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1487 if (sep == NULL) |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1488 err = PyFile_WriteString(" ", file); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1489 else |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1490 err = PyFile_WriteObject(sep, file, |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1491 Py_PRINT_RAW); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1492 if (err) |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1493 return NULL; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1494 } |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1495 err = PyFile_WriteObject(PyTuple_GetItem(args, i), file, |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1496 Py_PRINT_RAW); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1497 if (err) |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1498 return NULL; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1499 } |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1500 |
|
55057
466a71fc625c
refactor logic a little when no sep or end is passed
Benjamin Peterson <benjamin@python.org>
parents:
53953
diff
changeset
|
1501 if (end == NULL) |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1502 err = PyFile_WriteString("\n", file); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1503 else |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1504 err = PyFile_WriteObject(end, file, Py_PRINT_RAW); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1505 if (err) |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1506 return NULL; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1507 |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1508 Py_RETURN_NONE; |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1509 } |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1510 |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1511 PyDoc_STRVAR(print_doc, |
|
45086
7cb6e5617da0
Make print docstring consistent with its docs.
Georg Brandl <georg@python.org>
parents:
45082
diff
changeset
|
1512 "print(value, ..., sep=' ', end='\\n', file=sys.stdout)\n\ |
|
40410
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1513 \n\ |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1514 Prints the values to a stream, or to sys.stdout by default.\n\ |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1515 Optional keyword arguments:\n\ |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1516 file: a file-like object (stream); defaults to the current sys.stdout.\n\ |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1517 sep: string inserted between values, default a space.\n\ |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1518 end: string appended after the last value, default a newline."); |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1519 |
|
2e5011acb414
Add built-in Print() function. This is PEP 3105 except for the name;
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
1520 |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1521 static PyObject * |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1522 builtin_input(PyObject *self, PyObject *args) |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1523 { |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1524 PyObject *promptarg = NULL; |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1525 PyObject *fin = PySys_GetObject("stdin"); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1526 PyObject *fout = PySys_GetObject("stdout"); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1527 PyObject *ferr = PySys_GetObject("stderr"); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1528 PyObject *tmp; |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1529 long fd; |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1530 int tty; |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1531 |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1532 /* Parse arguments */ |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1533 if (!PyArg_UnpackTuple(args, "input", 0, 1, &promptarg)) |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1534 return NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1535 |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1536 /* Check that stdin/out/err are intact */ |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43844
diff
changeset
|
1537 if (fin == NULL || fin == Py_None) { |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1538 PyErr_SetString(PyExc_RuntimeError, |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1539 "input(): lost sys.stdin"); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1540 return NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1541 } |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43844
diff
changeset
|
1542 if (fout == NULL || fout == Py_None) { |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1543 PyErr_SetString(PyExc_RuntimeError, |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1544 "input(): lost sys.stdout"); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1545 return NULL; |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1546 } |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43844
diff
changeset
|
1547 if (ferr == NULL || ferr == Py_None) { |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1548 PyErr_SetString(PyExc_RuntimeError, |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1549 "input(): lost sys.stderr"); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1550 return NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1551 } |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1552 |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1553 /* First of all, flush stderr */ |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1554 tmp = PyObject_CallMethod(ferr, "flush", ""); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1555 if (tmp == NULL) |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1556 PyErr_Clear(); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1557 else |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1558 Py_DECREF(tmp); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1559 |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1560 /* We should only use (GNU) readline if Python's sys.stdin and |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1561 sys.stdout are the same as C's stdin and stdout, because we |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1562 need to pass it those. */ |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1563 tmp = PyObject_CallMethod(fin, "fileno", ""); |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1564 if (tmp == NULL) { |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1565 PyErr_Clear(); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1566 tty = 0; |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1567 } |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1568 else { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1569 fd = PyLong_AsLong(tmp); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1570 Py_DECREF(tmp); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1571 if (fd < 0 && PyErr_Occurred()) |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1572 return NULL; |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1573 tty = fd == fileno(stdin) && isatty(fd); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1574 } |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1575 if (tty) { |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1576 tmp = PyObject_CallMethod(fout, "fileno", ""); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1577 if (tmp == NULL) |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1578 PyErr_Clear(); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1579 else { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1580 fd = PyLong_AsLong(tmp); |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1581 Py_DECREF(tmp); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1582 if (fd < 0 && PyErr_Occurred()) |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1583 return NULL; |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1584 tty = fd == fileno(stdout) && isatty(fd); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1585 } |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1586 } |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1587 |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1588 /* If we're interactive, use (GNU) readline */ |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1589 if (tty) { |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1590 PyObject *po; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1591 char *prompt; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1592 char *s; |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1593 PyObject *stdin_encoding; |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1594 PyObject *result; |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1595 |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1596 stdin_encoding = PyObject_GetAttrString(fin, "encoding"); |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1597 if (!stdin_encoding) |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1598 /* stdin is a text stream, so it must have an |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1599 encoding. */ |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1600 return NULL; |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1601 tmp = PyObject_CallMethod(fout, "flush", ""); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1602 if (tmp == NULL) |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1603 PyErr_Clear(); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1604 else |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1605 Py_DECREF(tmp); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1606 if (promptarg != NULL) { |
|
49261
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1607 PyObject *stringpo; |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1608 PyObject *stdout_encoding; |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1609 stdout_encoding = PyObject_GetAttrString(fout, |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1610 "encoding"); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1611 if (stdout_encoding == NULL) { |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1612 Py_DECREF(stdin_encoding); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1613 return NULL; |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1614 } |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1615 stringpo = PyObject_Str(promptarg); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1616 if (stringpo == NULL) { |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1617 Py_DECREF(stdin_encoding); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1618 Py_DECREF(stdout_encoding); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1619 return NULL; |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1620 } |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1621 po = PyUnicode_AsEncodedString(stringpo, |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1622 _PyUnicode_AsString(stdout_encoding), NULL); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1623 Py_DECREF(stdout_encoding); |
|
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1624 Py_DECREF(stringpo); |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1625 if (po == NULL) { |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1626 Py_DECREF(stdin_encoding); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1627 return NULL; |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1628 } |
|
49261
f0c25e6bbad5
#1688: On Windows, the input() prompt was not correctly displayed if it
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48883
diff
changeset
|
1629 prompt = PyBytes_AsString(po); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1630 if (prompt == NULL) { |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1631 Py_DECREF(stdin_encoding); |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1632 Py_DECREF(po); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1633 return NULL; |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1634 } |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1635 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1636 else { |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1637 po = NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1638 prompt = ""; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1639 } |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1640 s = PyOS_Readline(stdin, stdout, prompt); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1641 Py_XDECREF(po); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1642 if (s == NULL) { |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1643 if (!PyErr_Occurred()) |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1644 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1645 Py_DECREF(stdin_encoding); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1646 return NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1647 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1648 if (*s == '\0') { |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1649 PyErr_SetNone(PyExc_EOFError); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1650 result = NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1651 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1652 else { /* strip trailing '\n' */ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1653 size_t len = strlen(s); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1654 if (len > PY_SSIZE_T_MAX) { |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1655 PyErr_SetString(PyExc_OverflowError, |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1656 "input: input too long"); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1657 result = NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1658 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1659 else { |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1660 result = PyUnicode_Decode |
|
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1661 (s, len-1, |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48601
diff
changeset
|
1662 _PyUnicode_AsString(stdin_encoding), |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1663 NULL); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1664 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1665 } |
|
43216
a311ab2fc1a7
Decode input() with stdin.encoding. Fixes #1097.
Martin v. Löwis <martin@v.loewis.de>
parents:
43172
diff
changeset
|
1666 Py_DECREF(stdin_encoding); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1667 PyMem_FREE(s); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1668 return result; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1669 } |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1670 |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1671 /* Fallback if we're not interactive */ |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1672 if (promptarg != NULL) { |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1673 if (PyFile_WriteObject(promptarg, fout, Py_PRINT_RAW) != 0) |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1674 return NULL; |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1675 } |
|
41888
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1676 tmp = PyObject_CallMethod(fout, "flush", ""); |
|
aa73206c9ce6
Make input9) behave properly with the new I/O library.
Guido van Rossum <guido@python.org>
parents:
41846
diff
changeset
|
1677 if (tmp == NULL) |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1678 PyErr_Clear(); |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1679 else |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
1680 Py_DECREF(tmp); |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1681 return PyFile_GetLine(fin, -1); |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1682 } |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1683 |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1684 PyDoc_STRVAR(input_doc, |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1685 "input([prompt]) -> string\n\ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1686 \n\ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1687 Read a string from standard input. The trailing newline is stripped.\n\ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1688 If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1689 On Unix, GNU readline is used if enabled. The prompt string, if given,\n\ |
|
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
1690 is printed without a trailing newline before reading."); |
| 8561 | 1691 |
| 1692 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1693 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1694 builtin_repr(PyObject *self, PyObject *v) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1695 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1696 return PyObject_Repr(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1697 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1698 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1699 PyDoc_STRVAR(repr_doc, |
| 8561 | 1700 "repr(object) -> string\n\ |
| 1701 \n\ | |
| 1702 Return the canonical string representation of the object.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1703 For most object types, eval(repr(object)) == object."); |
| 8561 | 1704 |
| 1705 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1706 static PyObject * |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
1707 builtin_round(PyObject *self, PyObject *args, PyObject *kwds) |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1708 { |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1709 static PyObject *round_str = NULL; |
|
51145
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1710 PyObject *ndigits = NULL; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
1711 static char *kwlist[] = {"number", "ndigits", 0}; |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1712 PyObject *number, *round; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1713 |
|
51145
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1714 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", |
|
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1715 kwlist, &number, &ndigits)) |
|
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1716 return NULL; |
|
42718
7fe2848fd41d
Implement the round functionality for PEP 3141, and add tests for it.
Alex Martelli <aleaxit@gmail.com>
parents:
42713
diff
changeset
|
1717 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44273
diff
changeset
|
1718 if (Py_TYPE(number)->tp_dict == NULL) { |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44273
diff
changeset
|
1719 if (PyType_Ready(Py_TYPE(number)) < 0) |
|
42760
e3e06b389406
Before calling _PyType_Lookup() the type needs to be initialized.
Guido van Rossum <guido@python.org>
parents:
42753
diff
changeset
|
1720 return NULL; |
|
e3e06b389406
Before calling _PyType_Lookup() the type needs to be initialized.
Guido van Rossum <guido@python.org>
parents:
42753
diff
changeset
|
1721 } |
|
e3e06b389406
Before calling _PyType_Lookup() the type needs to be initialized.
Guido van Rossum <guido@python.org>
parents:
42753
diff
changeset
|
1722 |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1723 if (round_str == NULL) { |
|
45029
ef2d3bf8383d
Merged revisions 60379-60382 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44905
diff
changeset
|
1724 round_str = PyUnicode_InternFromString("__round__"); |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1725 if (round_str == NULL) |
|
42718
7fe2848fd41d
Implement the round functionality for PEP 3141, and add tests for it.
Alex Martelli <aleaxit@gmail.com>
parents:
42713
diff
changeset
|
1726 return NULL; |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1727 } |
|
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1728 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44273
diff
changeset
|
1729 round = _PyType_Lookup(Py_TYPE(number), round_str); |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1730 if (round == NULL) { |
|
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1731 PyErr_Format(PyExc_TypeError, |
|
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1732 "type %.100s doesn't define __round__ method", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44273
diff
changeset
|
1733 Py_TYPE(number)->tp_name); |
|
42718
7fe2848fd41d
Implement the round functionality for PEP 3141, and add tests for it.
Alex Martelli <aleaxit@gmail.com>
parents:
42713
diff
changeset
|
1734 return NULL; |
|
7fe2848fd41d
Implement the round functionality for PEP 3141, and add tests for it.
Alex Martelli <aleaxit@gmail.com>
parents:
42713
diff
changeset
|
1735 } |
|
7fe2848fd41d
Implement the round functionality for PEP 3141, and add tests for it.
Alex Martelli <aleaxit@gmail.com>
parents:
42713
diff
changeset
|
1736 |
|
51145
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1737 if (ndigits == NULL) |
|
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1738 return PyObject_CallFunction(round, "O", number); |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1739 else |
|
51145
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1740 return PyObject_CallFunction(round, "OO", number, ndigits); |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1741 } |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1742 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1743 PyDoc_STRVAR(round_doc, |
|
51145
9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Mark Dickinson <dickinsm@gmail.com>
parents:
50755
diff
changeset
|
1744 "round(number[, ndigits]) -> number\n\ |
| 8561 | 1745 \n\ |
| 1746 Round a number to a given precision in decimal digits (default 0 digits).\n\ | |
| 48432 | 1747 This returns an int when called with one argument, otherwise the\n\ |
|
48401
70a4ec412882
#3191: fix round() docs and docstring.
Georg Brandl <georg@python.org>
parents:
47611
diff
changeset
|
1748 same type as the number. ndigits may be negative."); |
|
42753
077fe7860cc9
Finish the work on __round__ and __trunc__.
Guido van Rossum <guido@python.org>
parents:
42718
diff
changeset
|
1749 |
| 8561 | 1750 |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1751 static PyObject * |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1752 builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1753 { |
|
45061
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1754 PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs; |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1755 PyObject *callable; |
|
45061
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1756 static char *kwlist[] = {"iterable", "key", "reverse", 0}; |
|
36034
fdf0ac36eb74
Fix an int/long mismatch identified here:
Neal Norwitz <nnorwitz@gmail.com>
parents:
35999
diff
changeset
|
1757 int reverse; |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1758 |
|
45061
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1759 /* args 1-3 should match listsort in Objects/listobject.c */ |
|
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1760 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted", |
|
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1761 kwlist, &seq, &keyfunc, &reverse)) |
|
35608
a670a5dd1fc6
Removed a check "if (args != NULL)" which is always True and makes no sense.
Armin Rigo <arigo@tunes.org>
parents:
35567
diff
changeset
|
1762 return NULL; |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1763 |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1764 newlist = PySequence_List(seq); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1765 if (newlist == NULL) |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1766 return NULL; |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1767 |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1768 callable = PyObject_GetAttrString(newlist, "sort"); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1769 if (callable == NULL) { |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1770 Py_DECREF(newlist); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1771 return NULL; |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1772 } |
|
35500
8fa83a9ebc6e
Whitespace normalization.
Georg Brandl <georg@python.org>
parents:
35364
diff
changeset
|
1773 |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1774 newargs = PyTuple_GetSlice(args, 1, 4); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1775 if (newargs == NULL) { |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1776 Py_DECREF(newlist); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1777 Py_DECREF(callable); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1778 return NULL; |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1779 } |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1780 |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1781 v = PyObject_Call(callable, newargs, kwds); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1782 Py_DECREF(newargs); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1783 Py_DECREF(callable); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1784 if (v == NULL) { |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1785 Py_DECREF(newlist); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1786 return NULL; |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1787 } |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1788 Py_DECREF(v); |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1789 return newlist; |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1790 } |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1791 |
|
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
1792 PyDoc_STRVAR(sorted_doc, |
|
45061
b9ee31a26f38
Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().
Raymond Hettinger <python@rcn.com>
parents:
45029
diff
changeset
|
1793 "sorted(iterable, key=None, reverse=False) --> new sorted list"); |
| 8561 | 1794 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1795 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1796 builtin_vars(PyObject *self, PyObject *args) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1797 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1798 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1799 PyObject *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1800 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1801 if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1802 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1803 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1804 d = PyEval_GetLocals(); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1805 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1806 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1807 PyErr_SetString(PyExc_SystemError, |
|
28740
d3297e298211
some more error-message enhancements
Alex Martelli <aleaxit@gmail.com>
parents:
28738
diff
changeset
|
1808 "vars(): no locals!?"); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1809 } |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1810 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1811 Py_INCREF(d); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1812 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1813 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1814 d = PyObject_GetAttrString(v, "__dict__"); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1815 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1816 PyErr_SetString(PyExc_TypeError, |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1817 "vars() argument must have __dict__ attribute"); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1818 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1819 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1820 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1821 return d; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1822 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1823 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1824 PyDoc_STRVAR(vars_doc, |
| 8561 | 1825 "vars([object]) -> dictionary\n\ |
| 1826 \n\ | |
| 1827 Without arguments, equivalent to locals().\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1828 With an argument, equivalent to object.__dict__."); |
| 8561 | 1829 |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1830 static PyObject* |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1831 builtin_sum(PyObject *self, PyObject *args) |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1832 { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1833 PyObject *seq; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1834 PyObject *result = NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1835 PyObject *temp, *item, *iter; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1836 |
|
30774
2d98710f272e
Use PyArg_UnpackTuple() where possible.
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
1837 if (!PyArg_UnpackTuple(args, "sum", 1, 2, &seq, &result)) |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1838 return NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1839 |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1840 iter = PyObject_GetIter(seq); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1841 if (iter == NULL) |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1842 return NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1843 |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1844 if (result == NULL) { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1845 result = PyLong_FromLong(0); |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1846 if (result == NULL) { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1847 Py_DECREF(iter); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1848 return NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1849 } |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1850 } else { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1851 /* reject string values for 'start' parameter */ |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1852 if (PyUnicode_Check(result)) { |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1853 PyErr_SetString(PyExc_TypeError, |
|
28740
d3297e298211
some more error-message enhancements
Alex Martelli <aleaxit@gmail.com>
parents:
28738
diff
changeset
|
1854 "sum() can't sum strings [use ''.join(seq) instead]"); |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1855 Py_DECREF(iter); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1856 return NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1857 } |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47097
diff
changeset
|
1858 if (PyByteArray_Check(result)) { |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1859 PyErr_SetString(PyExc_TypeError, |
|
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1860 "sum() can't sum bytes [use b''.join(seq) instead]"); |
|
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1861 Py_DECREF(iter); |
|
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1862 return NULL; |
|
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1863 } |
|
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1864 |
|
28718
16ef5b9bc789
fixed a potential refcount bug (thanks Raymond!).
Alex Martelli <aleaxit@gmail.com>
parents:
28717
diff
changeset
|
1865 Py_INCREF(result); |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1866 } |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1867 |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1868 #ifndef SLOW_SUM |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1869 /* Fast addition by keeping temporary sums in C instead of new Python objects. |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1870 Assumes all inputs are the same type. If the assumption fails, default |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1871 to the more general routine. |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1872 */ |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1873 if (PyLong_CheckExact(result)) { |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1874 int overflow; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1875 long i_result = PyLong_AsLongAndOverflow(result, &overflow); |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1876 /* If this already overflowed, don't even enter the loop. */ |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1877 if (overflow == 0) { |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1878 Py_DECREF(result); |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1879 result = NULL; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1880 } |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1881 while(result == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1882 item = PyIter_Next(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1883 if (item == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1884 Py_DECREF(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1885 if (PyErr_Occurred()) |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1886 return NULL; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1887 return PyLong_FromLong(i_result); |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1888 } |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1889 if (PyLong_CheckExact(item)) { |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1890 long b = PyLong_AsLongAndOverflow(item, &overflow); |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1891 long x = i_result + b; |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1892 if (overflow == 0 && ((x^i_result) >= 0 || (x^b) >= 0)) { |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1893 i_result = x; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1894 Py_DECREF(item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1895 continue; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1896 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1897 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1898 /* Either overflowed or is not an int. Restore real objects and process normally */ |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1899 result = PyLong_FromLong(i_result); |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1900 temp = PyNumber_Add(result, item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1901 Py_DECREF(result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1902 Py_DECREF(item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1903 result = temp; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1904 if (result == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1905 Py_DECREF(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1906 return NULL; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1907 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1908 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1909 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1910 |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1911 if (PyFloat_CheckExact(result)) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1912 double f_result = PyFloat_AS_DOUBLE(result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1913 Py_DECREF(result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1914 result = NULL; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1915 while(result == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1916 item = PyIter_Next(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1917 if (item == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1918 Py_DECREF(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1919 if (PyErr_Occurred()) |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1920 return NULL; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1921 return PyFloat_FromDouble(f_result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1922 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1923 if (PyFloat_CheckExact(item)) { |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
1924 PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); return 0) |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1925 f_result += PyFloat_AS_DOUBLE(item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1926 PyFPE_END_PROTECT(f_result) |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1927 Py_DECREF(item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1928 continue; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1929 } |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1930 if (PyLong_CheckExact(item)) { |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1931 long value; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1932 int overflow; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1933 value = PyLong_AsLongAndOverflow(item, &overflow); |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1934 if (!overflow) { |
|
47557
98827a21e352
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
1935 PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); return 0) |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1936 f_result += (double)value; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1937 PyFPE_END_PROTECT(f_result) |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1938 Py_DECREF(item); |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1939 continue; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
1940 } |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1941 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1942 result = PyFloat_FromDouble(f_result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1943 temp = PyNumber_Add(result, item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1944 Py_DECREF(result); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1945 Py_DECREF(item); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1946 result = temp; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1947 if (result == NULL) { |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1948 Py_DECREF(iter); |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1949 return NULL; |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1950 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1951 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1952 } |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1953 #endif |
|
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
1954 |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1955 for(;;) { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1956 item = PyIter_Next(iter); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1957 if (item == NULL) { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1958 /* error, or end-of-sequence */ |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1959 if (PyErr_Occurred()) { |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1960 Py_DECREF(result); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1961 result = NULL; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1962 } |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1963 break; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1964 } |
|
56751
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1965 /* It's tempting to use PyNumber_InPlaceAdd instead of |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1966 PyNumber_Add here, to avoid quadratic running time |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1967 when doing 'sum(list_of_lists, [])'. However, this |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1968 would produce a change in behaviour: a snippet like |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1969 |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1970 empty = [] |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1971 sum([[x] for x in range(10)], empty) |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1972 |
|
7dc57b991d83
Merged revisions 75714 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
56594
diff
changeset
|
1973 would change the value of empty. */ |
|
30784
37285a0346c1
regressing the performance bugfix -- Guido wants the performance bug left
Alex Martelli <aleaxit@gmail.com>
parents:
30776
diff
changeset
|
1974 temp = PyNumber_Add(result, item); |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1975 Py_DECREF(result); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1976 Py_DECREF(item); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1977 result = temp; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1978 if (result == NULL) |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1979 break; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1980 } |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1981 Py_DECREF(iter); |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1982 return result; |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1983 } |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1984 |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1985 PyDoc_STRVAR(sum_doc, |
|
47097
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
1986 "sum(iterable[, start]) -> value\n\ |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1987 \n\ |
|
47097
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
1988 Returns the sum of an iterable of numbers (NOT strings) plus the value\n\ |
|
b2403d470b69
Rename enumerate() kw argument name to "iterable" and fix "sequence"->"iterable" in some docstrings.
Georg Brandl <georg@python.org>
parents:
47080
diff
changeset
|
1989 of parameter 'start' (which defaults to 0). When the iterable is\n\ |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40411
diff
changeset
|
1990 empty, returns start."); |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1991 |
|
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
1992 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1993 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1994 builtin_isinstance(PyObject *self, PyObject *args) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1995 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1996 PyObject *inst; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1997 PyObject *cls; |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
1998 int retval; |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1999 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
2000 if (!PyArg_UnpackTuple(args, "isinstance", 2, 2, &inst, &cls)) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2001 return NULL; |
|
10995
0d186c10a70e
Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents:
10529
diff
changeset
|
2002 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2003 retval = PyObject_IsInstance(inst, cls); |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2004 if (retval < 0) |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
2005 return NULL; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2006 return PyBool_FromLong(retval); |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2007 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2008 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2009 PyDoc_STRVAR(isinstance_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2010 "isinstance(object, class-or-type-or-tuple) -> bool\n\ |
| 8561 | 2011 \n\ |
| 2012 Return whether an object is an instance of a class or of a subclass thereof.\n\ | |
|
20307
aa681345bfab
Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
Guido van Rossum <guido@python.org>
parents:
19903
diff
changeset
|
2013 With a type as second argument, return whether that is the object's type.\n\ |
|
aa681345bfab
Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
Guido van Rossum <guido@python.org>
parents:
19903
diff
changeset
|
2014 The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2015 isinstance(x, A) or isinstance(x, B) or ... (etc.)."); |
| 8561 | 2016 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2017 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2018 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2019 builtin_issubclass(PyObject *self, PyObject *args) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2020 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2021 PyObject *derived; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2022 PyObject *cls; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2023 int retval; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2024 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
2025 if (!PyArg_UnpackTuple(args, "issubclass", 2, 2, &derived, &cls)) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2026 return NULL; |
|
10995
0d186c10a70e
Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents:
10529
diff
changeset
|
2027 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2028 retval = PyObject_IsSubclass(derived, cls); |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2029 if (retval < 0) |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2030 return NULL; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2031 return PyBool_FromLong(retval); |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2032 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2033 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2034 PyDoc_STRVAR(issubclass_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2035 "issubclass(C, B) -> bool\n\ |
| 8561 | 2036 \n\ |
|
26612
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
2037 Return whether class C is a subclass (i.e., a derived class) of class B.\n\ |
|
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
2038 When using a tuple as the second argument issubclass(X, (A, B, ...)),\n\ |
|
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
2039 is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.)."); |
| 8561 | 2040 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2041 |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2042 typedef struct { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2043 PyObject_HEAD |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2044 Py_ssize_t tuplesize; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2045 PyObject *ittuple; /* tuple of iterators */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2046 PyObject *result; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2047 } zipobject; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2048 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2049 static PyObject * |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2050 zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2051 { |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2052 zipobject *lz; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2053 Py_ssize_t i; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2054 PyObject *ittuple; /* tuple of iterators */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2055 PyObject *result; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2056 Py_ssize_t tuplesize = PySequence_Length(args); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2057 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2058 if (type == &PyZip_Type && !_PyArg_NoKeywords("zip()", kwds)) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2059 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2060 |
|
39686
aca709f33a6a
SF patch 1546297 (with some tweaks):
Guido van Rossum <guido@python.org>
parents:
39656
diff
changeset
|
2061 /* args must be a tuple */ |
|
aca709f33a6a
SF patch 1546297 (with some tweaks):
Guido van Rossum <guido@python.org>
parents:
39656
diff
changeset
|
2062 assert(PyTuple_Check(args)); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2063 |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2064 /* obtain iterators */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2065 ittuple = PyTuple_New(tuplesize); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2066 if (ittuple == NULL) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2067 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2068 for (i=0; i < tuplesize; ++i) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2069 PyObject *item = PyTuple_GET_ITEM(args, i); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2070 PyObject *it = PyObject_GetIter(item); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2071 if (it == NULL) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2072 if (PyErr_ExceptionMatches(PyExc_TypeError)) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2073 PyErr_Format(PyExc_TypeError, |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2074 "zip argument #%zd must support iteration", |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2075 i+1); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2076 Py_DECREF(ittuple); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2077 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2078 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2079 PyTuple_SET_ITEM(ittuple, i, it); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2080 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2081 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2082 /* create a result holder */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2083 result = PyTuple_New(tuplesize); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2084 if (result == NULL) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2085 Py_DECREF(ittuple); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2086 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2087 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2088 for (i=0 ; i < tuplesize ; i++) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2089 Py_INCREF(Py_None); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2090 PyTuple_SET_ITEM(result, i, Py_None); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2091 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2092 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2093 /* create zipobject structure */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2094 lz = (zipobject *)type->tp_alloc(type, 0); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2095 if (lz == NULL) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2096 Py_DECREF(ittuple); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2097 Py_DECREF(result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2098 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2099 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2100 lz->ittuple = ittuple; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2101 lz->tuplesize = tuplesize; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2102 lz->result = result; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2103 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2104 return (PyObject *)lz; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2105 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2106 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2107 static void |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2108 zip_dealloc(zipobject *lz) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2109 { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2110 PyObject_GC_UnTrack(lz); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2111 Py_XDECREF(lz->ittuple); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2112 Py_XDECREF(lz->result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2113 Py_TYPE(lz)->tp_free(lz); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2114 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2115 |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2116 static int |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2117 zip_traverse(zipobject *lz, visitproc visit, void *arg) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2118 { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2119 Py_VISIT(lz->ittuple); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2120 Py_VISIT(lz->result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2121 return 0; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2122 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2123 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2124 static PyObject * |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2125 zip_next(zipobject *lz) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2126 { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2127 Py_ssize_t i; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2128 Py_ssize_t tuplesize = lz->tuplesize; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2129 PyObject *result = lz->result; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2130 PyObject *it; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2131 PyObject *item; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2132 PyObject *olditem; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2133 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2134 if (tuplesize == 0) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2135 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2136 if (Py_REFCNT(result) == 1) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2137 Py_INCREF(result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2138 for (i=0 ; i < tuplesize ; i++) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2139 it = PyTuple_GET_ITEM(lz->ittuple, i); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2140 item = (*Py_TYPE(it)->tp_iternext)(it); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2141 if (item == NULL) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2142 Py_DECREF(result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2143 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2144 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2145 olditem = PyTuple_GET_ITEM(result, i); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2146 PyTuple_SET_ITEM(result, i, item); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2147 Py_DECREF(olditem); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2148 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2149 } else { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2150 result = PyTuple_New(tuplesize); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2151 if (result == NULL) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2152 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2153 for (i=0 ; i < tuplesize ; i++) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2154 it = PyTuple_GET_ITEM(lz->ittuple, i); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2155 item = (*Py_TYPE(it)->tp_iternext)(it); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2156 if (item == NULL) { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2157 Py_DECREF(result); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2158 return NULL; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2159 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2160 PyTuple_SET_ITEM(result, i, item); |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2161 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2162 } |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2163 return result; |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2164 } |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2165 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2166 PyDoc_STRVAR(zip_doc, |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2167 "zip(iter1 [,iter2 [...]]) --> zip object\n\ |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2168 \n\ |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2169 Return a zip object whose .__next__() method returns a tuple where\n\ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2170 the i-th element comes from the i-th iterable argument. The .__next__()\n\ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2171 method continues until the shortest iterable in the argument sequence\n\ |
|
50076
c7abfab4dcdb
Merged revisions 67525-67527,67529,67548-67549,67551-67552,67555,67578,67586,67593-67594,67596,67605-67606,67609,67612,67616-67617,67632,67635,67638 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49613
diff
changeset
|
2172 is exhausted and then it raises StopIteration."); |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2173 |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2174 PyTypeObject PyZip_Type = { |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2175 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2176 "zip", /* tp_name */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2177 sizeof(zipobject), /* tp_basicsize */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2178 0, /* tp_itemsize */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2179 /* methods */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2180 (destructor)zip_dealloc, /* tp_dealloc */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2181 0, /* tp_print */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2182 0, /* tp_getattr */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2183 0, /* tp_setattr */ |
|
51270
debd14c489b9
Issue #1717: rename tp_compare to tp_reserved. I'll change the
Mark Dickinson <dickinsm@gmail.com>
parents:
51245
diff
changeset
|
2184 0, /* tp_reserved */ |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2185 0, /* tp_repr */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2186 0, /* tp_as_number */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2187 0, /* tp_as_sequence */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2188 0, /* tp_as_mapping */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2189 0, /* tp_hash */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2190 0, /* tp_call */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2191 0, /* tp_str */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2192 PyObject_GenericGetAttr, /* tp_getattro */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2193 0, /* tp_setattro */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2194 0, /* tp_as_buffer */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2195 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2196 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2197 zip_doc, /* tp_doc */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2198 (traverseproc)zip_traverse, /* tp_traverse */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2199 0, /* tp_clear */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2200 0, /* tp_richcompare */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2201 0, /* tp_weaklistoffset */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2202 PyObject_SelfIter, /* tp_iter */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2203 (iternextfunc)zip_next, /* tp_iternext */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2204 0, /* tp_methods */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2205 0, /* tp_members */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2206 0, /* tp_getset */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2207 0, /* tp_base */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2208 0, /* tp_dict */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2209 0, /* tp_descr_get */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2210 0, /* tp_descr_set */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2211 0, /* tp_dictoffset */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2212 0, /* tp_init */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2213 PyType_GenericAlloc, /* tp_alloc */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2214 zip_new, /* tp_new */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2215 PyObject_GC_Del, /* tp_free */ |
|
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2216 }; |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2217 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2218 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2219 static PyMethodDef builtin_methods[] = { |
|
41226
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
2220 {"__build_class__", (PyCFunction)builtin___build_class__, |
|
19f7ff443718
Implement PEP 3115 -- new metaclass syntax and semantics.
Guido van Rossum <guido@python.org>
parents:
41107
diff
changeset
|
2221 METH_VARARGS | METH_KEYWORDS, build_class_doc}, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
2222 {"__import__", (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2223 {"abs", builtin_abs, METH_O, abs_doc}, |
|
34736
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
2224 {"all", builtin_all, METH_O, all_doc}, |
|
81b5a13fa38a
Add two new functions, any() and all().
Raymond Hettinger <python@rcn.com>
parents:
34123
diff
changeset
|
2225 {"any", builtin_any, METH_O, any_doc}, |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47580
diff
changeset
|
2226 {"ascii", builtin_ascii, METH_O, ascii_doc}, |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
2227 {"bin", builtin_bin, METH_O, bin_doc}, |
|
43121
8834e65683e7
Remove chr8, we're not likely to need it at this point
Neal Norwitz <nnorwitz@gmail.com>
parents:
43110
diff
changeset
|
2228 {"chr", builtin_chr, METH_VARARGS, chr_doc}, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41501
diff
changeset
|
2229 {"compile", (PyCFunction)builtin_compile, METH_VARARGS | METH_KEYWORDS, compile_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2230 {"delattr", builtin_delattr, METH_VARARGS, delattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2231 {"dir", builtin_dir, METH_VARARGS, dir_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2232 {"divmod", builtin_divmod, METH_VARARGS, divmod_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2233 {"eval", builtin_eval, METH_VARARGS, eval_doc}, |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39686
diff
changeset
|
2234 {"exec", builtin_exec, METH_VARARGS, exec_doc}, |
|
42817
5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Eric Smith <eric@trueblade.com>
parents:
42760
diff
changeset
|
2235 {"format", builtin_format, METH_VARARGS, format_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2236 {"getattr", builtin_getattr, METH_VARARGS, getattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2237 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2238 {"hasattr", builtin_hasattr, METH_VARARGS, hasattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2239 {"hash", builtin_hash, METH_O, hash_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2240 {"hex", builtin_hex, METH_O, hex_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2241 {"id", builtin_id, METH_O, id_doc}, |
|
40933
a2629be1b1d0
Add raw_input() back, named input(). Revive the old unittests too.
Guido van Rossum <guido@python.org>
parents:
40922
diff
changeset
|
2242 {"input", builtin_input, METH_VARARGS, input_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2243 {"isinstance", builtin_isinstance, METH_VARARGS, isinstance_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2244 {"issubclass", builtin_issubclass, METH_VARARGS, issubclass_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2245 {"iter", builtin_iter, METH_VARARGS, iter_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2246 {"len", builtin_len, METH_O, len_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2247 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, locals_doc}, |
|
34085
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
2248 {"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEYWORDS, max_doc}, |
|
cc9ce6837ea9
SF patch #1077353: add key= argument to min and max
Raymond Hettinger <python@rcn.com>
parents:
33261
diff
changeset
|
2249 {"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEYWORDS, min_doc}, |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
41452
diff
changeset
|
2250 {"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2251 {"oct", builtin_oct, METH_O, oct_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2252 {"ord", builtin_ord, METH_O, ord_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2253 {"pow", builtin_pow, METH_VARARGS, pow_doc}, |
|
40774
793e0323d4d6
Essential changes for print function changes.
Guido van Rossum <guido@python.org>
parents:
40644
diff
changeset
|
2254 {"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2255 {"repr", builtin_repr, METH_O, repr_doc}, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
2256 {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2257 {"setattr", builtin_setattr, METH_VARARGS, setattr_doc}, |
|
31210
c06b570adf12
Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents:
31122
diff
changeset
|
2258 {"sorted", (PyCFunction)builtin_sorted, METH_VARARGS | METH_KEYWORDS, sorted_doc}, |
|
28717
13d0a3c4e465
Adding new built-in function sum, with docs and tests.
Alex Martelli <aleaxit@gmail.com>
parents:
28612
diff
changeset
|
2259 {"sum", builtin_sum, METH_VARARGS, sum_doc}, |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
2260 {"vars", builtin_vars, METH_VARARGS, vars_doc}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
2261 {NULL, NULL}, |
| 86 | 2262 }; |
| 2263 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2264 PyDoc_STRVAR(builtin_doc, |
| 8561 | 2265 "Built-in functions, exceptions, and other objects.\n\ |
| 2266 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
2267 Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices."); |
| 8561 | 2268 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2269 static struct PyModuleDef builtinsmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2270 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2271 "builtins", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2272 builtin_doc, |
|
49613
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49403
diff
changeset
|
2273 -1, /* multiple "initialization" just copies the module dict. */ |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2274 builtin_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2275 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2276 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2277 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2278 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2279 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2280 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2281 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2282 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2283 _PyBuiltin_Init(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2284 { |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2285 PyObject *mod, *dict, *debug; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47557
diff
changeset
|
2286 mod = PyModule_Create(&builtinsmodule); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2287 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2288 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2289 dict = PyModule_GetDict(mod); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2290 |
|
28396
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2291 #ifdef Py_TRACE_REFS |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44064
diff
changeset
|
2292 /* "builtins" exposes a number of statically allocated objects |
|
28396
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2293 * that, before this code was added in 2.3, never showed up in |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2294 * the list of "all objects" maintained by Py_TRACE_REFS. As a |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2295 * result, programs leaking references to None and False (etc) |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2296 * couldn't be diagnosed by examining sys.getobjects(0). |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2297 */ |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2298 #define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0) |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2299 #else |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2300 #define ADD_TO_ALL(OBJECT) (void)0 |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2301 #endif |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2302 |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2303 #define SETBUILTIN(NAME, OBJECT) \ |
|
28396
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2304 if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \ |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2305 return NULL; \ |
|
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2306 ADD_TO_ALL(OBJECT) |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2307 |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2308 SETBUILTIN("None", Py_None); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2309 SETBUILTIN("Ellipsis", Py_Ellipsis); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2310 SETBUILTIN("NotImplemented", Py_NotImplemented); |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2311 SETBUILTIN("False", Py_False); |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2312 SETBUILTIN("True", Py_True); |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2313 SETBUILTIN("bool", &PyBool_Type); |
|
43487
8c10aac37037
Breaking ground for PEP 3137 implementation:
Guido van Rossum <guido@python.org>
parents:
43216
diff
changeset
|
2314 SETBUILTIN("memoryview", &PyMemoryView_Type); |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47097
diff
changeset
|
2315 SETBUILTIN("bytearray", &PyByteArray_Type); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
2316 SETBUILTIN("bytes", &PyBytes_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2317 SETBUILTIN("classmethod", &PyClassMethod_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2318 SETBUILTIN("complex", &PyComplex_Type); |
|
20754
272336648d1f
Rename "dictionary" (type and constructor) to "dict".
Tim Peters <tim.peters@gmail.com>
parents:
20654
diff
changeset
|
2319 SETBUILTIN("dict", &PyDict_Type); |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
2320 SETBUILTIN("enumerate", &PyEnum_Type); |
|
45734
e09bc1c5295b
Issue 2186 and 2187. Move filter from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45382
diff
changeset
|
2321 SETBUILTIN("filter", &PyFilter_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2322 SETBUILTIN("float", &PyFloat_Type); |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
30865
diff
changeset
|
2323 SETBUILTIN("frozenset", &PyFrozenSet_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2324 SETBUILTIN("property", &PyProperty_Type); |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40484
diff
changeset
|
2325 SETBUILTIN("int", &PyLong_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2326 SETBUILTIN("list", &PyList_Type); |
|
45735
7adaab64eb72
Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents:
45734
diff
changeset
|
2327 SETBUILTIN("map", &PyMap_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2328 SETBUILTIN("object", &PyBaseObject_Type); |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41609
diff
changeset
|
2329 SETBUILTIN("range", &PyRange_Type); |
|
30865
41c4e143e6e6
Implement and apply PEP 322, reverse iteration
Raymond Hettinger <python@rcn.com>
parents:
30784
diff
changeset
|
2330 SETBUILTIN("reversed", &PyReversed_Type); |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
30865
diff
changeset
|
2331 SETBUILTIN("set", &PySet_Type); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23832
diff
changeset
|
2332 SETBUILTIN("slice", &PySlice_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2333 SETBUILTIN("staticmethod", &PyStaticMethod_Type); |
|
41558
29ae667f3239
Checkpoint. Manipulated things so that string literals are always
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
2334 SETBUILTIN("str", &PyUnicode_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2335 SETBUILTIN("super", &PySuper_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2336 SETBUILTIN("tuple", &PyTuple_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2337 SETBUILTIN("type", &PyType_Type); |
|
45738
740b5808c57a
Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents:
45735
diff
changeset
|
2338 SETBUILTIN("zip", &PyZip_Type); |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
2339 debug = PyBool_FromLong(Py_OptimizeFlag == 0); |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2340 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2341 Py_XDECREF(debug); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2342 return NULL; |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2343 } |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2344 Py_XDECREF(debug); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2345 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2346 return mod; |
|
28396
d56282c28a1e
Improved new Py_TRACE_REFS gimmicks.
Tim Peters <tim.peters@gmail.com>
parents:
28027
diff
changeset
|
2347 #undef ADD_TO_ALL |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
2348 #undef SETBUILTIN |
| 86 | 2349 } |
