Mercurial > cpython-lru_cache-weakref
annotate Python/exceptions.c @ 13283:3e07a7315af5 legacy-trunk
init_exceptions(): Decref `doc' so it doesn't leak.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Sat, 01 Jul 2000 04:45:52 +0000 |
| parents | 1e302d996d58 |
| children | d6198e703602 |
| rev | line source |
|---|---|
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1 /* This module provides the suite of standard class-based exceptions for |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 * Python's builtin module. This is a complete C implementation of what, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3 * in Python 1.5.2, was contained in the exceptions.py module. The problem |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 * there was that if exceptions.py could not be imported for some reason, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
5 * the entire interpreter would abort. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
7 * By moving the exceptions into C and statically linking, we can guarantee |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 * that the standard exceptions will always be available. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
9 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 * history: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
11 * 98-08-19 fl created (for pyexe) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 * 00-02-08 fl updated for 1.5.2 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 * 26-May-2000 baw vetted for Python 1.6 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
15 * written by Fredrik Lundh |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 * modifications, additions, cleanups, and proofreading by Barry Warsaw |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
18 * Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
20 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
21 #include "Python.h" |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
22 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
23 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
24 module__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
25 "Python's standard exception class hierarchy.\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
26 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
27 Before Python 1.5, the standard exceptions were all simple string objects.\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
28 In Python 1.5, the standard exceptions were converted to classes organized\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
29 into a relatively flat hierarchy. String-based standard exceptions were\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
30 optional, or used as a fallback if some problem occurred while importing\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
31 the exception module. With Python 1.6, optional string-based standard\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
32 exceptions were removed (along with the -X command line flag).\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
33 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
34 The class exceptions were implemented in such a way as to be almost\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
35 completely backward compatible. Some tricky uses of IOError could\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
36 potentially have broken, but by Python 1.6, all of these should have\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
37 been fixed. As of Python 1.6, the class-based standard exceptions are\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
38 now implemented in C, and are guaranteed to exist in the Python\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
39 interpreter.\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
40 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
41 Here is a rundown of the class hierarchy. The classes found here are\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
42 inserted into both the exceptions module and the `built-in' module. It is\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
43 recommended that user defined class based exceptions be derived from the\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
44 `Exception' class, although this is currently not enforced.\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
46 Exception\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
48 +-- SystemExit\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
49 +-- StandardError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
51 +-- KeyboardInterrupt\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
52 +-- ImportError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
53 +-- EnvironmentError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
54 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
55 | +-- IOError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 | +-- OSError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
57 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
58 | +-- WindowsError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
59 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
60 +-- EOFError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
61 +-- RuntimeError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
62 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
63 | +-- NotImplementedError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
64 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
65 +-- NameError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
66 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 | +-- UnboundLocalError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
68 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
69 +-- AttributeError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
70 +-- SyntaxError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
71 +-- TypeError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
72 +-- AssertionError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
73 +-- LookupError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
75 | +-- IndexError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
76 | +-- KeyError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
78 +-- ArithmeticError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
79 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
80 | +-- OverflowError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
81 | +-- ZeroDivisionError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
82 | +-- FloatingPointError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
83 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 +-- ValueError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
85 | |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
86 | +-- UnicodeError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
87 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
88 +-- SystemError\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
89 +-- MemoryError"; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
90 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
91 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
92 /* Helper function for populating a dictionary with method wrappers. */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
93 static int |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
94 populate_methods(PyObject* klass, PyObject* dict, PyMethodDef* methods) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
95 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 if (!methods) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
97 return 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
99 while (methods->ml_name) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
100 /* get a wrapper for the built-in function */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
101 PyObject* func = PyCFunction_New(methods, NULL); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
102 PyObject* meth; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
105 if (!func) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
106 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
107 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
108 /* turn the function into an unbound method */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
109 if (!(meth = PyMethod_New(func, NULL, klass))) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
110 Py_DECREF(func); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
112 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
113 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
114 /* add method to dictionary */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
115 status = PyDict_SetItemString(dict, methods->ml_name, meth); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
116 Py_DECREF(meth); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
117 Py_DECREF(func); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
118 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 /* stop now if an error occurred, otherwise do the next method */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
120 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
121 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 methods++; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 return 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
126 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
127 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
128 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
129 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 /* This function is used to create all subsequent exception classes. */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 static int |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
132 make_class(PyObject** klass, PyObject* base, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 char* name, PyMethodDef* methods, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
134 char* docstr) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
135 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
136 PyObject* dict = PyDict_New(); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
137 PyObject* str = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
138 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
139 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
140 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
143 /* If an error occurs from here on, goto finally instead of explicitly |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 * returning NULL. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
145 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
146 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
147 if (docstr) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
148 if (!(str = PyString_FromString(docstr))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
149 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
150 if (PyDict_SetItemString(dict, "__doc__", str)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
151 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
152 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
153 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
154 if (!(*klass = PyErr_NewException(name, base, dict))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
155 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
156 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
157 if (populate_methods(*klass, dict, methods)) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
158 Py_DECREF(*klass); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
159 *klass = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
160 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
161 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
162 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
163 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
164 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
165 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
166 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
167 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
168 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
169 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
170 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
171 /* Use this for *args signatures, otherwise just use PyArg_ParseTuple() */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
172 static PyObject* get_self(PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
173 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
174 PyObject* self = PyTuple_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
175 if (!self) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
176 /* Watch out for being called to early in the bootstapping process */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
177 if (PyExc_TypeError) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
178 PyErr_SetString(PyExc_TypeError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
179 "unbound method must be called with class instance 1st argument"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
180 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
181 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
182 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
183 return self; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
184 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
185 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
186 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
187 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
188 /* Notes on bootstrapping the exception classes. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
189 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
190 * First thing we create is the base class for all exceptions, called |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
191 * appropriately enough: Exception. Creation of this class makes no |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
192 * assumptions about the existence of any other exception class -- except |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
193 * for TypeError, which can conditionally exist. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
194 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
195 * Next, StandardError is created (which is quite simple) followed by |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
196 * TypeError, because the instantiation of other exceptions can potentially |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
197 * throw a TypeError. Once these exceptions are created, all the others |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
198 * can be created in any order. See the static exctable below for the |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
199 * explicit bootstrap order. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
200 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
201 * All classes after Exception can be created using PyErr_NewException(). |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
202 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
203 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
204 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
205 Exception__doc__[] = "Common base class for all exceptions."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
206 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
207 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
208 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
209 Exception__init__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
210 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
212 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
213 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
214 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
215 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
216 /* set args attribute */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
217 args = PySequence_GetSlice(args, 1, PySequence_Length(args)); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
218 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
219 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
220 status = PyObject_SetAttrString(self, "args", args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
221 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
222 if (status < 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
223 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
224 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
225 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
226 return Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
227 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
228 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
229 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
230 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
231 Exception__str__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
232 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 PyObject* out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
234 PyObject* tmp; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
235 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
236 if (!PyArg_ParseTuple(args, "O", &self)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
237 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
238 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
239 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
240 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
241 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
242 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
243 switch (PySequence_Length(args)) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
244 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
245 out = PyString_FromString(""); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
246 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
247 case 1: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
248 if (!(tmp = PySequence_GetItem(args, 0))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
249 out = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
250 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
251 out = PyObject_Str(tmp); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
252 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
253 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
254 out = PyObject_Str(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
255 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
256 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
257 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
258 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
259 return out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
260 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
261 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
262 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
263 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
264 Exception__getitem__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
265 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
266 PyObject* out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
267 PyObject* index; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
268 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
269 if (!PyArg_ParseTuple(args, "OO", &self, &index)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
270 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
271 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
272 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
273 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
274 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
275 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
276 out = PyObject_GetItem(args, index); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
277 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
278 return out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
279 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
280 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
281 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
282 static PyMethodDef |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
283 Exception_methods[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
284 /* methods for the Exception class */ |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
285 { "__getitem__", Exception__getitem__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
286 { "__str__", Exception__str__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
287 { "__init__", Exception__init__, METH_VARARGS}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
288 { NULL, NULL } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
289 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
290 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
291 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
292 static int |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
293 make_Exception(char* modulename) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
294 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
295 PyObject* dict = PyDict_New(); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
296 PyObject* str = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
297 PyObject* name = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
298 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
299 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
300 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
301 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
302 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
303 /* If an error occurs from here on, goto finally instead of explicitly |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
304 * returning NULL. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
305 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
306 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
307 if (!(str = PyString_FromString(modulename))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
308 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
309 if (PyDict_SetItemString(dict, "__module__", str)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
310 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
311 Py_DECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
312 if (!(str = PyString_FromString(Exception__doc__))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
313 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
314 if (PyDict_SetItemString(dict, "__doc__", str)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
315 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
316 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
317 if (!(name = PyString_FromString("Exception"))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
318 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
319 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
320 if (!(PyExc_Exception = PyClass_New(NULL, dict, name))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
321 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
322 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
323 /* Now populate the dictionary with the method suite */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
324 if (populate_methods(PyExc_Exception, dict, Exception_methods)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
325 /* Don't need to reclaim PyExc_Exception here because that'll |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
326 * happen during interpreter shutdown. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
327 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
328 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
329 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
330 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
331 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
332 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
333 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
334 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
335 Py_XDECREF(name); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
336 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
337 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
338 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
339 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
340 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
341 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
342 StandardError__doc__[] = "Base class for all standard Python exceptions."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
343 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
344 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
345 TypeError__doc__[] = "Inappropriate argument type."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
346 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
347 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
348 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
349 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
350 SystemExit__doc__[] = "Request to exit from the interpreter."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
351 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
352 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
353 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
354 SystemExit__init__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
355 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
356 PyObject* code; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
357 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
358 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
359 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
360 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
361 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
362 /* Set args attribute. */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
363 if (!(args = PySequence_GetSlice(args, 1, PySequence_Length(args)))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
364 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
365 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
366 status = PyObject_SetAttrString(self, "args", args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
367 if (status < 0) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
368 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
369 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
370 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
371 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
372 /* set code attribute */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
373 switch (PySequence_Length(args)) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
374 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
375 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
376 code = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
377 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
378 case 1: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
379 code = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
380 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
381 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
382 Py_INCREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
383 code = args; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
384 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
385 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
386 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
387 status = PyObject_SetAttrString(self, "code", code); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
388 Py_DECREF(code); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
389 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
390 if (status < 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
391 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
392 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
393 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
394 return Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
395 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
396 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
397 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
398 PyMethodDef SystemExit_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
399 { "__init__", SystemExit__init__, METH_VARARGS}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
400 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
401 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
402 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
403 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
404 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
405 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
406 KeyboardInterrupt__doc__[] = "Program interrupted by user."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
407 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
408 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
409 ImportError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
410 "Import can't find module, or can't find name in module."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
411 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
412 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
413 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
414 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
415 EnvironmentError__doc__[] = "Base class for I/O related errors."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
416 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
417 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
418 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
419 EnvironmentError__init__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
420 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
421 PyObject* item0 = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
422 PyObject* item1 = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
423 PyObject* item2 = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
424 PyObject* subslice = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
425 PyObject* rtnval = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
426 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
427 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
428 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
429 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
430 if (!(args = PySequence_GetSlice(args, 1, PySequence_Length(args)))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
431 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
432 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
433 if (PyObject_SetAttrString(self, "args", args) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
434 PyObject_SetAttrString(self, "errno", Py_None) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
435 PyObject_SetAttrString(self, "strerror", Py_None) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
436 PyObject_SetAttrString(self, "filename", Py_None)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
437 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
438 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
439 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
440 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
441 switch (PySequence_Length(args)) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
442 case 3: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
443 /* open() errors give third argument which is the filename. But so |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
444 * common in-place unpacking doesn't break, e.g.: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
445 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
446 * except IOError, (errno, strerror): |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
447 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
448 * we hack args so that it only contains two items. This also |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
449 * means we need our own __str__() which prints out the filename |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
450 * when it was supplied. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
451 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
452 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
453 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
454 item2 = PySequence_GetItem(args, 2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
455 if (!item0 || !item1 || !item2) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
456 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
457 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
458 if (PyObject_SetAttrString(self, "errno", item0) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
459 PyObject_SetAttrString(self, "strerror", item1) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
460 PyObject_SetAttrString(self, "filename", item2)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
461 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
462 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
463 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
464 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
465 subslice = PySequence_GetSlice(args, 0, 2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
466 if (!subslice || PyObject_SetAttrString(self, "args", subslice)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
467 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
468 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
469 case 2: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
470 /* common case: PyErr_SetFromErrno() */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
471 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
472 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
473 if (!item0 || !item1) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
474 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
475 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
476 if (PyObject_SetAttrString(self, "errno", item0) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
477 PyObject_SetAttrString(self, "strerror", item1)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
478 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
479 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
480 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
481 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
482 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
483 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
484 rtnval = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
485 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
486 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
487 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
488 Py_XDECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
489 Py_XDECREF(item1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
490 Py_XDECREF(item2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
491 Py_XDECREF(subslice); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
492 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
493 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
494 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
495 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
496 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
497 EnvironmentError__str__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
498 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
499 PyObject* originalself = self; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
500 PyObject* filename; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
501 PyObject* serrno; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
502 PyObject* strerror; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
503 PyObject* rtnval = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
504 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
505 if (!PyArg_ParseTuple(args, "O", &self)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
506 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
507 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
508 filename = PyObject_GetAttrString(self, "filename"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
509 serrno = PyObject_GetAttrString(self, "errno"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
510 strerror = PyObject_GetAttrString(self, "strerror"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
511 if (!filename || !serrno || !strerror) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
512 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
513 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
514 if (filename != Py_None) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
515 PyObject* fmt = PyString_FromString("[Errno %s] %s: %s"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
516 PyObject* repr = PyObject_Repr(filename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
517 PyObject* tuple = PyTuple_New(3); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
518 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
519 if (!fmt || !repr || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
520 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
521 Py_XDECREF(repr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
522 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
523 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
524 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
525 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
526 PyTuple_SET_ITEM(tuple, 0, serrno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
527 PyTuple_SET_ITEM(tuple, 1, strerror); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
528 PyTuple_SET_ITEM(tuple, 2, repr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
529 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
530 rtnval = PyString_Format(fmt, tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
531 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
532 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
533 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
534 /* already freed because tuple owned only reference */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
535 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
536 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
537 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
538 else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
539 PyObject* fmt = PyString_FromString("[Errno %s] %s"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
540 PyObject* tuple = PyTuple_New(2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
541 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
542 if (!fmt || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
543 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
544 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
545 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
546 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
547 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
548 PyTuple_SET_ITEM(tuple, 0, serrno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
549 PyTuple_SET_ITEM(tuple, 1, strerror); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
550 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
551 rtnval = PyString_Format(fmt, tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
552 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
553 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
554 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
555 /* already freed because tuple owned only reference */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
556 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
557 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
558 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
559 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
560 /* The original Python code said: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
561 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
562 * return StandardError.__str__(self) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
563 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
564 * but there is no StandardError__str__() function; we happen to |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
565 * know that's just a pass through to Exception__str__(). |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
566 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
567 rtnval = Exception__str__(originalself, args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
568 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
569 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
570 Py_XDECREF(filename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
571 Py_XDECREF(serrno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
572 Py_XDECREF(strerror); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
573 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
574 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
575 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
576 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
577 static |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
578 PyMethodDef EnvironmentError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
579 {"__init__", EnvironmentError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
580 {"__str__", EnvironmentError__str__, METH_VARARGS}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
581 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
582 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
583 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
584 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
585 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
586 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
587 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
588 IOError__doc__[] = "I/O operation failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
589 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
590 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
591 OSError__doc__[] = "OS system call failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
592 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
593 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
594 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
595 WindowsError__doc__[] = "MS-Windows OS system call failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
596 #endif /* MS_WINDOWS */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
597 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
598 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
599 EOFError__doc__[] = "Read beyond end of file."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
600 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
601 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
602 RuntimeError__doc__[] = "Unspecified run-time error."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
603 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
604 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
605 NotImplementedError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
606 "Method or function hasn't been implemented yet."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
607 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
608 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
609 NameError__doc__[] = "Name not found globally."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
610 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
611 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
612 UnboundLocalError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
613 "Local name referenced but not bound to a value."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
614 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
615 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
616 AttributeError__doc__[] = "Attribute not found."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
617 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
618 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
619 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
620 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
621 SyntaxError__doc__[] = "Invalid syntax."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
622 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
623 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
624 static int |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
625 SyntaxError__classinit__(PyObject* klass) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
626 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
627 PyObject* emptystring = PyString_FromString(""); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
628 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
629 /* Additional class-creation time initializations */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
630 if (!emptystring || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
631 PyObject_SetAttrString(klass, "msg", emptystring) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
632 PyObject_SetAttrString(klass, "filename", Py_None) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
633 PyObject_SetAttrString(klass, "lineno", Py_None) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
634 PyObject_SetAttrString(klass, "offset", Py_None) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
635 PyObject_SetAttrString(klass, "text", Py_None)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
636 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
637 Py_XDECREF(emptystring); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
638 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
639 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
640 Py_DECREF(emptystring); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
641 return 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
642 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
643 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
644 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
645 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
646 SyntaxError__init__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
647 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
648 PyObject* rtnval = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
649 int lenargs; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
650 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
651 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
652 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
653 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
654 if (!(args = PySequence_GetSlice(args, 1, PySequence_Length(args)))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
655 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
656 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
657 if (PyObject_SetAttrString(self, "args", args)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
658 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
659 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
660 lenargs = PySequence_Length(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
661 if (lenargs >= 1) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
662 PyObject* item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
663 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
664 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
665 if (!item0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
666 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
667 status = PyObject_SetAttrString(self, "msg", item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
668 Py_DECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
669 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
670 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
671 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
672 if (lenargs == 2) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
673 PyObject* info = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
674 PyObject *filename, *lineno, *offset, *text; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
675 int status = 1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
676 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
677 if (!info) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
678 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
679 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
680 filename = PySequence_GetItem(info, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
681 lineno = PySequence_GetItem(info, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
682 offset = PySequence_GetItem(info, 2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
683 text = PySequence_GetItem(info, 3); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
684 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
685 Py_DECREF(info); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
686 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
687 if (filename && lineno && offset && text) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
688 status = PyObject_SetAttrString(self, "filename", filename) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
689 PyObject_SetAttrString(self, "lineno", lineno) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
690 PyObject_SetAttrString(self, "offset", offset) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
691 PyObject_SetAttrString(self, "text", text); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
692 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
693 Py_XDECREF(filename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
694 Py_XDECREF(lineno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
695 Py_XDECREF(offset); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
696 Py_XDECREF(text); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
697 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
698 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
699 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
700 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
701 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
702 rtnval = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
703 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
704 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
705 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
706 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
707 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
708 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
709 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
710 static PyObject* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
711 SyntaxError__str__(PyObject* self, PyObject* args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
712 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
713 PyObject* msg; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
714 PyObject* str; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
715 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
716 if (!PyArg_ParseTuple(args, "O", &self)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
717 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
718 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
719 if (!(msg = PyObject_GetAttrString(self, "msg"))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
720 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
721 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
722 str = PyObject_Str(msg); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
723 Py_DECREF(msg); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
724 return str; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
725 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
726 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
727 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
728 PyMethodDef SyntaxError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
729 {"__init__", SyntaxError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
730 {"__str__", SyntaxError__str__, METH_VARARGS}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
731 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
732 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
733 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
734 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
735 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
736 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
737 AssertionError__doc__[] = "Assertion failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
738 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
739 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
740 LookupError__doc__[] = "Base class for lookup errors."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
741 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
742 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
743 IndexError__doc__[] = "Sequence index out of range."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
744 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
745 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
746 KeyError__doc__[] = "Mapping key not found."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
747 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
748 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
749 ArithmeticError__doc__[] = "Base class for arithmetic errors."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
750 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
751 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
752 OverflowError__doc__[] = "Result too large to be represented."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
753 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
754 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
755 ZeroDivisionError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
756 "Second argument to a division or modulo operation was zero."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
757 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
758 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
759 FloatingPointError__doc__[] = "Floating point operation failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
760 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
761 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
762 ValueError__doc__[] = "Inappropriate argument value (of correct type)."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
763 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
764 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
765 UnicodeError__doc__[] = "Unicode related error."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
766 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
767 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
768 SystemError__doc__[] = "Internal error in the Python interpreter.\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
769 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
770 Please report this to the Python maintainer, along with the traceback,\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
771 the Python version, and the hardware/OS platform and version."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
772 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
773 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
774 MemoryError__doc__[] = "Out of memory."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
775 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
776 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
777 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
778 /* module global functions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
779 static PyMethodDef functions[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
780 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
781 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
782 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
783 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
784 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
785 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
786 /* Global C API defined exceptions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
787 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
788 PyObject *PyExc_Exception; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
789 PyObject *PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
790 PyObject *PyExc_ArithmeticError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
791 PyObject *PyExc_LookupError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
792 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
793 PyObject *PyExc_AssertionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
794 PyObject *PyExc_AttributeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
795 PyObject *PyExc_EOFError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
796 PyObject *PyExc_FloatingPointError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
797 PyObject *PyExc_EnvironmentError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
798 PyObject *PyExc_IOError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
799 PyObject *PyExc_OSError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
800 PyObject *PyExc_ImportError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
801 PyObject *PyExc_IndexError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
802 PyObject *PyExc_KeyError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
803 PyObject *PyExc_KeyboardInterrupt; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
804 PyObject *PyExc_MemoryError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
805 PyObject *PyExc_NameError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
806 PyObject *PyExc_OverflowError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
807 PyObject *PyExc_RuntimeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
808 PyObject *PyExc_NotImplementedError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
809 PyObject *PyExc_SyntaxError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
810 PyObject *PyExc_SystemError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
811 PyObject *PyExc_SystemExit; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
812 PyObject *PyExc_UnboundLocalError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
813 PyObject *PyExc_UnicodeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
814 PyObject *PyExc_TypeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
815 PyObject *PyExc_ValueError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
816 PyObject *PyExc_ZeroDivisionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
817 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
818 PyObject *PyExc_WindowsError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
819 #endif |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
820 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
821 /* Pre-computed MemoryError instance. Best to create this as early as |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
822 * possibly and not wait until a MemoryError is actually raised! |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
823 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
824 PyObject *PyExc_MemoryErrorInst; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
825 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
826 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
827 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
828 /* mapping between exception names and their PyObject** */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
829 static struct |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
830 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
831 char* name; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
832 PyObject** exc; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
833 PyObject** base; /* NULL == PyExc_StandardError */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
834 char* docstr; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
835 PyMethodDef* methods; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
836 int (*classinit)(PyObject*); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
837 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
838 exctable[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
839 /* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
840 * The first three classes MUST appear in exactly this order |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
841 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
842 {"Exception", &PyExc_Exception}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
843 {"StandardError", &PyExc_StandardError, &PyExc_Exception, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
844 StandardError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
845 {"TypeError", &PyExc_TypeError, 0, TypeError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
846 /* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
847 * The rest appear in depth-first order of the hierarchy |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
848 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
849 {"SystemExit", &PyExc_SystemExit, &PyExc_Exception, SystemExit__doc__, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
850 SystemExit_methods}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
851 {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, 0, KeyboardInterrupt__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
852 {"ImportError", &PyExc_ImportError, 0, ImportError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
853 {"EnvironmentError", &PyExc_EnvironmentError, 0, EnvironmentError__doc__, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
854 EnvironmentError_methods}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
855 {"IOError", &PyExc_IOError, &PyExc_EnvironmentError, IOError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
856 {"OSError", &PyExc_OSError, &PyExc_EnvironmentError, OSError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
857 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
858 {"WindowsError", &PyExc_WindowsError, &PyExc_EnvironmentError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
859 WindowsError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
860 #endif /* MS_WINDOWS */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
861 {"EOFError", &PyExc_EOFError, 0, EOFError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
862 {"RuntimeError", &PyExc_RuntimeError, 0, RuntimeError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
863 {"NotImplementedError", &PyExc_NotImplementedError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
864 &PyExc_RuntimeError, NotImplementedError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
865 {"NameError", &PyExc_NameError, 0, NameError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
866 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
867 UnboundLocalError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
868 {"AttributeError", &PyExc_AttributeError, 0, AttributeError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
869 {"SyntaxError", &PyExc_SyntaxError, 0, SyntaxError__doc__, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
870 SyntaxError_methods, SyntaxError__classinit__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
871 {"AssertionError", &PyExc_AssertionError, 0, AssertionError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
872 {"LookupError", &PyExc_LookupError, 0, LookupError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
873 {"IndexError", &PyExc_IndexError, &PyExc_LookupError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
874 IndexError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
875 {"KeyError", &PyExc_KeyError, &PyExc_LookupError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
876 KeyError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
877 {"ArithmeticError", &PyExc_ArithmeticError, 0, ArithmeticError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
878 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
879 OverflowError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
880 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
881 ZeroDivisionError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
882 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
883 FloatingPointError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
884 {"ValueError", &PyExc_ValueError, 0, ValueError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
885 {"UnicodeError", &PyExc_UnicodeError, &PyExc_ValueError, UnicodeError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
886 {"SystemError", &PyExc_SystemError, 0, SystemError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
887 {"MemoryError", &PyExc_MemoryError, 0, MemoryError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
888 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
889 {NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
890 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
891 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
892 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
893 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
894 void |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
895 #ifdef WIN32 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
896 __declspec(dllexport) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
897 #endif /* WIN32 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
898 init_exceptions() |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
899 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
900 char* modulename = "exceptions"; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
901 int modnamesz = strlen(modulename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
902 int i; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
903 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
904 PyObject* me = Py_InitModule(modulename, functions); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
905 PyObject* mydict = PyModule_GetDict(me); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
906 PyObject* bltinmod = PyImport_ImportModule("__builtin__"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
907 PyObject* bdict = PyModule_GetDict(bltinmod); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
908 PyObject* doc = PyString_FromString(module__doc__); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
909 PyObject* args; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
910 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
911 PyDict_SetItemString(mydict, "__doc__", doc); |
|
13283
3e07a7315af5
init_exceptions(): Decref `doc' so it doesn't leak.
Barry Warsaw <barry@python.org>
parents:
13182
diff
changeset
|
912 Py_DECREF(doc); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
913 if (PyErr_Occurred()) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
914 Py_FatalError("exceptions bootstrapping error."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
915 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
916 /* This is the base class of all exceptions, so make it first. */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
917 if (make_Exception(modulename) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
918 PyDict_SetItemString(mydict, "Exception", PyExc_Exception) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
919 PyDict_SetItemString(bdict, "Exception", PyExc_Exception)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
920 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
921 Py_FatalError("Base class `Exception' could not be created."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
922 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
923 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
924 /* Now we can programmatically create all the remaining exceptions. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
925 * Remember to start the loop at 1 to skip Exceptions. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
926 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
927 for (i=1; exctable[i].name; i++) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
928 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
929 char* cname = PyMem_NEW(char, modnamesz+strlen(exctable[i].name)+2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
930 PyObject* base; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
931 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
932 (void)strcpy(cname, modulename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
933 (void)strcat(cname, "."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
934 (void)strcat(cname, exctable[i].name); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
935 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
936 if (exctable[i].base == 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
937 base = PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
938 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
939 base = *exctable[i].base; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
940 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
941 status = make_class(exctable[i].exc, base, cname, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
942 exctable[i].methods, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
943 exctable[i].docstr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
944 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
945 PyMem_DEL(cname); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
946 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
947 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
948 Py_FatalError("Standard exception classes could not be created."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
949 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
950 if (exctable[i].classinit) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
951 status = (*exctable[i].classinit)(*exctable[i].exc); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
952 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
953 Py_FatalError("An exception class could not be initialized."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
954 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
955 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
956 /* Now insert the class into both this module and the __builtin__ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
957 * module. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
958 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
959 if (PyDict_SetItemString(mydict, exctable[i].name, *exctable[i].exc) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
960 PyDict_SetItemString(bdict, exctable[i].name, *exctable[i].exc)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
961 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
962 Py_FatalError("Module dictionary insertion problem."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
963 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
964 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
965 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
966 /* Now we need to pre-allocate a MemoryError instance */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
967 args = Py_BuildValue("()"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
968 if (!args || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
969 !(PyExc_MemoryErrorInst = PyEval_CallObject(PyExc_MemoryError, args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
970 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
971 Py_FatalError("Cannot pre-allocate MemoryError instance\n"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
972 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
973 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
974 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
975 /* We're done with __builtin__ */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
976 Py_DECREF(bltinmod); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
977 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
978 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
979 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
980 void |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
981 #ifdef WIN32 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
982 __declspec(dllexport) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
983 #endif /* WIN32 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
984 fini_exceptions() |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
985 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
986 int i; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
987 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
988 Py_XDECREF(PyExc_MemoryErrorInst); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
989 PyExc_MemoryErrorInst = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
990 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
991 for (i=0; exctable[i].name; i++) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
992 Py_XDECREF(*exctable[i].exc); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
993 *exctable[i].exc = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
994 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
995 } |
