Mercurial > cpython-lru_cache-weakref
annotate Python/exceptions.c @ 18916:2bc648932d44 legacy-trunk
Add mysnprintf.c to Windows build, + squash compiler wngs in mysnprintf.c.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 31 Jul 2001 22:10:29 +0000 |
| parents | 32e7d0898eab |
| children | 09df3254b49d |
| 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" |
|
13996
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
22 #include "osdefs.h" |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
23 |
|
13565
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
24 /* Caution: MS Visual C++ 6 errors if a single string literal exceeds |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
25 * 2Kb. So the module docstring has been broken roughly in half, using |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
26 * compile-time literal concatenation. |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
27 */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
28 static char |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
29 module__doc__[] = |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
30 "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
|
31 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 interpreter.\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 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
|
47 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
|
48 recommended that user defined class based exceptions be derived from the\n\ |
|
13565
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
49 `Exception' class, although this is currently not enforced.\n" |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
50 /* keep string pieces "small" */ |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
51 "\n\ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
52 Exception\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
53 |\n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
54 +-- SystemExit\n\ |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
55 +-- StopIteration\n\ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 +-- StandardError\n\ |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
57 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
58 | +-- KeyboardInterrupt\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
59 | +-- ImportError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
60 | +-- EnvironmentError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
61 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
62 | | +-- IOError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
63 | | +-- OSError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
64 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
65 | | +-- WindowsError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
66 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
67 | +-- EOFError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
68 | +-- RuntimeError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
69 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
70 | | +-- NotImplementedError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
71 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
72 | +-- NameError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
73 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
74 | | +-- UnboundLocalError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
75 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
76 | +-- AttributeError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
77 | +-- SyntaxError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
78 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
79 | | +-- IndentationError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
80 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
81 | | +-- TabError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
82 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
83 | +-- TypeError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
84 | +-- AssertionError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
85 | +-- LookupError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
86 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
87 | | +-- IndexError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
88 | | +-- KeyError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
89 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
90 | +-- ArithmeticError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
91 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
92 | | +-- OverflowError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
93 | | +-- ZeroDivisionError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
94 | | +-- FloatingPointError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
95 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
96 | +-- ValueError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
97 | | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
98 | | +-- UnicodeError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
99 | |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
100 | +-- SystemError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
101 | +-- MemoryError\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
102 |\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
103 +---Warning\n\ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 |\n\ |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
105 +-- UserWarning\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
106 +-- DeprecationWarning\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
107 +-- SyntaxWarning\n\ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
108 +-- RuntimeWarning"; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
109 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
110 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 /* 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
|
112 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
113 populate_methods(PyObject *klass, PyObject *dict, PyMethodDef *methods) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
114 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
115 if (!methods) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
116 return 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
117 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
118 while (methods->ml_name) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 /* get a wrapper for the built-in function */ |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
120 PyObject *func = PyCFunction_New(methods, NULL); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
121 PyObject *meth; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 if (!func) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 return -1; |
|
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 /* 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
|
128 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
|
129 Py_DECREF(func); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 } |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
132 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 /* add method to dictionary */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
134 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
|
135 Py_DECREF(meth); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
136 Py_DECREF(func); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
137 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
138 /* 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
|
139 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
140 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 methods++; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
143 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 return 0; |
|
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 |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
147 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
148 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
149 /* 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
|
150 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
151 make_class(PyObject **klass, PyObject *base, |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
152 char *name, PyMethodDef *methods, |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
153 char *docstr) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
154 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
155 PyObject *dict = PyDict_New(); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
156 PyObject *str = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
157 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
158 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
159 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
160 return -1; |
|
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 /* 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
|
163 * returning NULL. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
164 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
165 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
166 if (docstr) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
167 if (!(str = PyString_FromString(docstr))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
168 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
169 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
|
170 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
171 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
172 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
173 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
|
174 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
175 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
176 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
|
177 Py_DECREF(*klass); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
178 *klass = NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
179 goto finally; |
|
12771
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
182 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
183 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
184 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
185 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
186 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
187 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
188 } |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
191 /* Use this for *args signatures, otherwise just use PyArg_ParseTuple() */ |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
192 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
193 get_self(PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
194 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
195 PyObject *self = PyTuple_GetItem(args, 0); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
196 if (!self) { |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
197 /* Watch out for being called to early in the bootstrapping process */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
198 if (PyExc_TypeError) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
199 PyErr_SetString(PyExc_TypeError, |
| 15318 | 200 "unbound method must be called with instance as first argument"); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
201 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
202 return NULL; |
|
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 return self; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
205 } |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
209 /* 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
|
210 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 * 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
|
212 * 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
|
213 * 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
|
214 * 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
|
215 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
216 * 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
|
217 * 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
|
218 * 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
|
219 * 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
|
220 * explicit bootstrap order. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
221 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
222 * 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
|
223 */ |
|
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 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
226 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
|
227 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
228 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
229 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
230 Exception__init__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
231 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
232 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
234 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
235 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
236 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
237 /* set args attribute */ |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
238 /* XXX size is only a hint */ |
|
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
239 args = PySequence_GetSlice(args, 1, PySequence_Size(args)); |
|
12771
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 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
|
243 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
244 if (status < 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
245 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
246 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
247 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
248 return Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
249 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
250 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
251 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
252 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
253 Exception__str__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
254 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
255 PyObject *out; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
256 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
257 if (!PyArg_ParseTuple(args, "O:__str__", &self)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
258 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
259 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
260 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
261 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
262 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
263 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
264 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
265 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
266 out = PyString_FromString(""); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
267 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
268 case 1: |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
269 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
270 PyObject *tmp = PySequence_GetItem(args, 0); |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
271 if (tmp) { |
|
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
272 out = PyObject_Str(tmp); |
|
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
273 Py_DECREF(tmp); |
|
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
274 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
275 else |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
276 out = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
277 break; |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
278 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
279 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
280 out = PyObject_Str(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
281 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
282 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
283 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
284 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
285 return out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
286 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
287 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
288 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
289 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
290 Exception__getitem__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
291 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
292 PyObject *out; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
293 PyObject *index; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
294 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
295 if (!PyArg_ParseTuple(args, "OO:__getitem__", &self, &index)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
296 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
297 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
298 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
299 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
300 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
301 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
302 out = PyObject_GetItem(args, index); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
303 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
304 return out; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
308 static PyMethodDef |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
309 Exception_methods[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
310 /* 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
|
311 { "__getitem__", Exception__getitem__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
312 { "__str__", Exception__str__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
313 { "__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
|
314 { NULL, NULL } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
315 }; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
318 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
319 make_Exception(char *modulename) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
320 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
321 PyObject *dict = PyDict_New(); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
322 PyObject *str = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
323 PyObject *name = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
324 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
325 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
326 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
327 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
328 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
329 /* 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
|
330 * returning NULL. |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
333 if (!(str = PyString_FromString(modulename))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
334 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
335 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
|
336 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
337 Py_DECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
338 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
|
339 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
340 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
|
341 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
342 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
343 if (!(name = PyString_FromString("Exception"))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
344 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
345 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
346 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
|
347 goto finally; |
|
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 /* 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
|
350 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
|
351 /* 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
|
352 * happen during interpreter shutdown. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
353 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
354 goto finally; |
|
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 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
357 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
358 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
359 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
360 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
361 Py_XDECREF(name); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
362 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
363 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
364 |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
367 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
368 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
|
369 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
370 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
371 TypeError__doc__[] = "Inappropriate argument type."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
372 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
373 static char |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
374 StopIteration__doc__[] = "Signal the end from iterator.next()."; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
375 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
376 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
377 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
378 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
379 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
|
380 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
381 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
382 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
383 SystemExit__init__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
384 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
385 PyObject *code; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
386 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
387 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
388 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
389 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
390 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
391 /* Set args attribute. */ |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
392 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
393 return NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
394 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
395 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
|
396 if (status < 0) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
397 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
398 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
399 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
400 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
401 /* set code attribute */ |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
402 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
403 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
404 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
405 code = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
406 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
407 case 1: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
408 code = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
409 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
410 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
411 Py_INCREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
412 code = args; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
413 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
414 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
415 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
416 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
|
417 Py_DECREF(code); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
418 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
419 if (status < 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
420 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
421 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
422 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
423 return Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
424 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
425 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
426 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
16852
diff
changeset
|
427 static PyMethodDef SystemExit_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
428 { "__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
|
429 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
430 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
431 |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
434 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
435 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
|
436 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
437 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
438 ImportError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
439 "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
|
440 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
441 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
442 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
443 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
444 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
|
445 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
446 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
447 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
448 EnvironmentError__init__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
449 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
450 PyObject *item0 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
451 PyObject *item1 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
452 PyObject *item2 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
453 PyObject *subslice = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
454 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
455 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
456 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
457 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
458 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
459 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
460 return NULL; |
|
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 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
|
463 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
|
464 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
|
465 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
|
466 { |
|
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 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
470 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
471 case 3: |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
472 /* Where a function has a single filename, such as open() or some |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
473 * of the os module functions, PyErr_SetFromErrnoWithFilename() is |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
474 * called, giving a third argument which is the filename. But, so |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
475 * that old code using in-place unpacking doesn't break, e.g.: |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
476 * |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
477 * except IOError, (errno, strerror): |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
478 * |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
479 * 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
|
480 * 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
|
481 * when it was supplied. |
|
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 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
484 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
485 item2 = PySequence_GetItem(args, 2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
486 if (!item0 || !item1 || !item2) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
487 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
488 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
489 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
|
490 PyObject_SetAttrString(self, "strerror", item1) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
491 PyObject_SetAttrString(self, "filename", item2)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
492 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
493 goto finally; |
|
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 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
|
497 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
|
498 goto finally; |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
499 break; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
500 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
501 case 2: |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
502 /* Used when PyErr_SetFromErrno() is called and no filename |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
503 * argument is given. |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
504 */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
505 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
506 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
507 if (!item0 || !item1) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
508 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
509 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
510 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
|
511 PyObject_SetAttrString(self, "strerror", item1)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
512 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
513 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
514 } |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
515 break; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
516 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
517 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
518 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
519 rtnval = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
520 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
521 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
522 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
523 Py_XDECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
524 Py_XDECREF(item1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
525 Py_XDECREF(item2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
526 Py_XDECREF(subslice); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
527 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
528 } |
|
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 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
531 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
532 EnvironmentError__str__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
533 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
534 PyObject *originalself = self; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
535 PyObject *filename; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
536 PyObject *serrno; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
537 PyObject *strerror; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
538 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
539 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
540 if (!PyArg_ParseTuple(args, "O:__str__", &self)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
541 return NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
542 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
543 filename = PyObject_GetAttrString(self, "filename"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
544 serrno = PyObject_GetAttrString(self, "errno"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
545 strerror = PyObject_GetAttrString(self, "strerror"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
546 if (!filename || !serrno || !strerror) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
547 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
548 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
549 if (filename != Py_None) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
550 PyObject *fmt = PyString_FromString("[Errno %s] %s: %s"); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
551 PyObject *repr = PyObject_Repr(filename); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
552 PyObject *tuple = PyTuple_New(3); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
553 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
554 if (!fmt || !repr || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
555 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
556 Py_XDECREF(repr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
557 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
558 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
559 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
560 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
565 rtnval = PyString_Format(fmt, tuple); |
|
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 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
568 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
569 /* 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
|
570 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
571 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
572 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
573 else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
574 PyObject *fmt = PyString_FromString("[Errno %s] %s"); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
575 PyObject *tuple = PyTuple_New(2); |
|
12771
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 if (!fmt || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
578 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
579 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
580 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
581 } |
|
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 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
|
584 PyTuple_SET_ITEM(tuple, 1, strerror); |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
585 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
586 rtnval = PyString_Format(fmt, tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
587 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
588 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
589 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
590 /* 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
|
591 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
592 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
593 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
594 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
595 /* The original Python code said: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
596 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
597 * return StandardError.__str__(self) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
598 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
599 * 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
|
600 * 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
|
601 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
602 rtnval = Exception__str__(originalself, args); |
|
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 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
605 Py_XDECREF(filename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
606 Py_XDECREF(serrno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
607 Py_XDECREF(strerror); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
608 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
609 } |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
612 static |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
613 PyMethodDef EnvironmentError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
614 {"__init__", EnvironmentError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
615 {"__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
|
616 {NULL, NULL} |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
621 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
622 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
623 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
|
624 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
625 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
626 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
|
627 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
628 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
629 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
630 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
|
631 #endif /* MS_WINDOWS */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
632 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
633 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
634 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
|
635 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
636 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
637 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
|
638 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
639 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
640 NotImplementedError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
641 "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
|
642 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
643 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
644 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
|
645 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
646 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
647 UnboundLocalError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
648 "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
|
649 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
650 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
651 AttributeError__doc__[] = "Attribute not found."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
652 |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
655 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
656 SyntaxError__doc__[] = "Invalid syntax."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
657 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
658 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
659 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
660 SyntaxError__classinit__(PyObject *klass) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
661 { |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
662 int retval = 0; |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
663 PyObject *emptystring = PyString_FromString(""); |
|
12771
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 /* Additional class-creation time initializations */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
666 if (!emptystring || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
667 PyObject_SetAttrString(klass, "msg", emptystring) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
668 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
|
669 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
|
670 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
|
671 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
|
672 { |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
673 retval = -1; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
674 } |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
675 Py_XDECREF(emptystring); |
|
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
676 return retval; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
677 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
678 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
679 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
680 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
681 SyntaxError__init__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
682 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
683 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
684 int lenargs; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
685 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
686 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
687 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
688 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
689 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
690 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
691 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
692 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
|
693 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
694 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
695 lenargs = PySequence_Size(args); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
696 if (lenargs >= 1) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
697 PyObject *item0 = PySequence_GetItem(args, 0); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
698 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
699 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
700 if (!item0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
701 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
702 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
|
703 Py_DECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
704 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
705 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
706 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
707 if (lenargs == 2) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
708 PyObject *info = PySequence_GetItem(args, 1); |
|
16852
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
709 PyObject *filename = NULL, *lineno = NULL; |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
710 PyObject *offset = NULL, *text = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
711 int status = 1; |
|
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 if (!info) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
714 goto finally; |
|
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 filename = PySequence_GetItem(info, 0); |
|
16852
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
717 if (filename != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
718 lineno = PySequence_GetItem(info, 1); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
719 if (lineno != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
720 offset = PySequence_GetItem(info, 2); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
721 if (offset != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
722 text = PySequence_GetItem(info, 3); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
723 if (text != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
724 status = |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
725 PyObject_SetAttrString(self, "filename", filename) |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
726 || PyObject_SetAttrString(self, "lineno", lineno) |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
727 || PyObject_SetAttrString(self, "offset", offset) |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
728 || PyObject_SetAttrString(self, "text", text); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
729 Py_DECREF(text); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
730 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
731 Py_DECREF(offset); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
732 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
733 Py_DECREF(lineno); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
734 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
735 Py_DECREF(filename); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
736 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
737 Py_DECREF(info); |
|
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 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
740 goto finally; |
|
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 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
743 rtnval = Py_None; |
|
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 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
746 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
747 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
748 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
749 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
750 |
|
13996
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
751 /* This is called "my_basename" instead of just "basename" to avoid name |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
752 conflicts with glibc; basename is already prototyped if _GNU_SOURCE is |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
753 defined, and Python does define that. */ |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
754 static char * |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
755 my_basename(char *name) |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
756 { |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
757 char *cp = name; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
758 char *result = name; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
759 |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
760 if (name == NULL) |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
761 return "???"; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
762 while (*cp != '\0') { |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
763 if (*cp == SEP) |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
764 result = cp + 1; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
765 ++cp; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
766 } |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
767 return result; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
768 } |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
769 |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
770 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
771 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
772 SyntaxError__str__(PyObject *self, PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
773 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
774 PyObject *msg; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
775 PyObject *str; |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
776 PyObject *filename, *lineno, *result; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
777 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
778 if (!PyArg_ParseTuple(args, "O:__str__", &self)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
779 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
780 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
781 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
|
782 return NULL; |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
783 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
784 str = PyObject_Str(msg); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
785 Py_DECREF(msg); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
786 result = str; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
787 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
788 /* XXX -- do all the additional formatting with filename and |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
789 lineno here */ |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
790 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
791 if (PyString_Check(str)) { |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
792 int have_filename = 0; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
793 int have_lineno = 0; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
794 char *buffer = NULL; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
795 |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
796 if ((filename = PyObject_GetAttrString(self, "filename")) != NULL) |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
797 have_filename = PyString_Check(filename); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
798 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
799 PyErr_Clear(); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
800 |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
801 if ((lineno = PyObject_GetAttrString(self, "lineno")) != NULL) |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
802 have_lineno = PyInt_Check(lineno); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
803 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
804 PyErr_Clear(); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
805 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
806 if (have_filename || have_lineno) { |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
807 int bufsize = PyString_GET_SIZE(str) + 64; |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
808 if (have_filename) |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
809 bufsize += PyString_GET_SIZE(filename); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
810 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
811 buffer = PyMem_Malloc(bufsize); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
812 if (buffer != NULL) { |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
813 if (have_filename && have_lineno) |
|
14068
03401af36b5c
Remove a couple of warnings turned up by "gcc -Wall".
Fred Drake <fdrake@acm.org>
parents:
14054
diff
changeset
|
814 sprintf(buffer, "%s (%s, line %ld)", |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
815 PyString_AS_STRING(str), |
|
13996
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
816 my_basename(PyString_AS_STRING(filename)), |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
817 PyInt_AsLong(lineno)); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
818 else if (have_filename) |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
819 sprintf(buffer, "%s (%s)", |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
820 PyString_AS_STRING(str), |
|
13996
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
821 my_basename(PyString_AS_STRING(filename))); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
822 else if (have_lineno) |
|
14068
03401af36b5c
Remove a couple of warnings turned up by "gcc -Wall".
Fred Drake <fdrake@acm.org>
parents:
14054
diff
changeset
|
823 sprintf(buffer, "%s (line %ld)", |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
824 PyString_AS_STRING(str), |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
825 PyInt_AsLong(lineno)); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
826 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
827 result = PyString_FromString(buffer); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
828 PyMem_FREE(buffer); |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
829 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
830 if (result == NULL) |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
831 result = str; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
832 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
833 Py_DECREF(str); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
834 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
835 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
836 Py_XDECREF(filename); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
837 Py_XDECREF(lineno); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
838 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
839 return result; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
840 } |
|
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 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
16852
diff
changeset
|
843 static PyMethodDef SyntaxError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
844 {"__init__", SyntaxError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
845 {"__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
|
846 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
847 }; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
850 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
851 /* Exception doc strings */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
852 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
853 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
854 AssertionError__doc__[] = "Assertion failed."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
855 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
856 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
857 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
|
858 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
859 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
860 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
|
861 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
862 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
863 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
|
864 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
865 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
866 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
|
867 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
868 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
869 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
|
870 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
871 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
872 ZeroDivisionError__doc__[] = |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
873 "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
|
874 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
875 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
876 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
|
877 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
878 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
879 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
|
880 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
881 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
882 UnicodeError__doc__[] = "Unicode related error."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
883 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
884 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
885 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
|
886 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
887 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
|
888 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
|
889 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
890 static char |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
891 MemoryError__doc__[] = "Out of memory."; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
892 |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
893 static char |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
894 IndentationError__doc__[] = "Improper indentation."; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
895 |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
896 static char |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
897 TabError__doc__[] = "Improper mixture of spaces and tabs."; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
898 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
899 /* Warning category docstrings */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
900 |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
901 static char |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
902 Warning__doc__[] = "Base class for warning categories."; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
903 |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
904 static char |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
905 UserWarning__doc__[] = "Base class for warnings generated by user code."; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
906 |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
907 static char |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
908 DeprecationWarning__doc__[] = |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
909 "Base class for warnings about deprecated features."; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
910 |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
911 static char |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
912 SyntaxWarning__doc__[] = "Base class for warnings about dubious syntax."; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
913 |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
914 static char |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
915 RuntimeWarning__doc__[] = |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
916 "Base class for warnings about dubious runtime behavior."; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
917 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
918 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
919 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
920 /* module global functions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
921 static PyMethodDef functions[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
922 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
923 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
924 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
925 |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
928 /* Global C API defined exceptions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
929 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
930 PyObject *PyExc_Exception; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
931 PyObject *PyExc_StopIteration; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
932 PyObject *PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
933 PyObject *PyExc_ArithmeticError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
934 PyObject *PyExc_LookupError; |
|
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 PyObject *PyExc_AssertionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
937 PyObject *PyExc_AttributeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
938 PyObject *PyExc_EOFError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
939 PyObject *PyExc_FloatingPointError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
940 PyObject *PyExc_EnvironmentError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
941 PyObject *PyExc_IOError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
942 PyObject *PyExc_OSError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
943 PyObject *PyExc_ImportError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
944 PyObject *PyExc_IndexError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
945 PyObject *PyExc_KeyError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
946 PyObject *PyExc_KeyboardInterrupt; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
947 PyObject *PyExc_MemoryError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
948 PyObject *PyExc_NameError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
949 PyObject *PyExc_OverflowError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
950 PyObject *PyExc_RuntimeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
951 PyObject *PyExc_NotImplementedError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
952 PyObject *PyExc_SyntaxError; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
953 PyObject *PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
954 PyObject *PyExc_TabError; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
955 PyObject *PyExc_SystemError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
956 PyObject *PyExc_SystemExit; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
957 PyObject *PyExc_UnboundLocalError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
958 PyObject *PyExc_UnicodeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
959 PyObject *PyExc_TypeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
960 PyObject *PyExc_ValueError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
961 PyObject *PyExc_ZeroDivisionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
962 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
963 PyObject *PyExc_WindowsError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
964 #endif |
|
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 /* 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
|
967 * 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
|
968 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
969 PyObject *PyExc_MemoryErrorInst; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
970 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
971 /* Predefined warning categories */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
972 PyObject *PyExc_Warning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
973 PyObject *PyExc_UserWarning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
974 PyObject *PyExc_DeprecationWarning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
975 PyObject *PyExc_SyntaxWarning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
976 PyObject *PyExc_RuntimeWarning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
977 |
|
12771
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 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
980 /* mapping between exception names and their PyObject ** */ |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
981 static struct { |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
982 char *name; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
983 PyObject **exc; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
984 PyObject **base; /* NULL == PyExc_StandardError */ |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
985 char *docstr; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
986 PyMethodDef *methods; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
987 int (*classinit)(PyObject *); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
988 } exctable[] = { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
989 /* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
990 * 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
|
991 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
992 {"Exception", &PyExc_Exception}, |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
993 {"StopIteration", &PyExc_StopIteration, &PyExc_Exception, |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
994 StopIteration__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
995 {"StandardError", &PyExc_StandardError, &PyExc_Exception, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
996 StandardError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
997 {"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
|
998 /* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
999 * 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
|
1000 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1001 {"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
|
1002 SystemExit_methods}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1003 {"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
|
1004 {"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
|
1005 {"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
|
1006 EnvironmentError_methods}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1007 {"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
|
1008 {"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
|
1009 #ifdef MS_WINDOWS |
|
13973
4e28ca345cfe
Fix the parent of WindowsError - both the comments in this source file, and the previous exceptions.py have WindowsError as a sub-class of OSError.
Mark Hammond <mhammond@skippinet.com.au>
parents:
13657
diff
changeset
|
1010 {"WindowsError", &PyExc_WindowsError, &PyExc_OSError, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1011 WindowsError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1012 #endif /* MS_WINDOWS */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1013 {"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
|
1014 {"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
|
1015 {"NotImplementedError", &PyExc_NotImplementedError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1016 &PyExc_RuntimeError, NotImplementedError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1017 {"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
|
1018 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1019 UnboundLocalError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1020 {"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
|
1021 {"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
|
1022 SyntaxError_methods, SyntaxError__classinit__}, |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1023 {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1024 IndentationError__doc__}, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1025 {"TabError", &PyExc_TabError, &PyExc_IndentationError, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1026 TabError__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1027 {"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
|
1028 {"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
|
1029 {"IndexError", &PyExc_IndexError, &PyExc_LookupError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1030 IndexError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1031 {"KeyError", &PyExc_KeyError, &PyExc_LookupError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1032 KeyError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1033 {"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
|
1034 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1035 OverflowError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1036 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1037 ZeroDivisionError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1038 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1039 FloatingPointError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1040 {"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
|
1041 {"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
|
1042 {"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
|
1043 {"MemoryError", &PyExc_MemoryError, 0, MemoryError__doc__}, |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1044 /* Warning categories */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1045 {"Warning", &PyExc_Warning, &PyExc_Exception, Warning__doc__}, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1046 {"UserWarning", &PyExc_UserWarning, &PyExc_Warning, UserWarning__doc__}, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1047 {"DeprecationWarning", &PyExc_DeprecationWarning, &PyExc_Warning, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1048 DeprecationWarning__doc__}, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1049 {"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__}, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1050 {"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning, |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1051 RuntimeWarning__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1052 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1053 {NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1054 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1055 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1056 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1057 |
|
16837
0e6a3da4f956
SF patch 404928: Support for next Cygwin gcc (2.95.2-8)
Tim Peters <tim.peters@gmail.com>
parents:
16164
diff
changeset
|
1058 DL_EXPORT(void) |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1059 init_exceptions(void) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1060 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1061 char *modulename = "exceptions"; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1062 int modnamesz = strlen(modulename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1063 int i; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1064 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1065 PyObject *me = Py_InitModule(modulename, functions); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1066 PyObject *mydict = PyModule_GetDict(me); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1067 PyObject *bltinmod = PyImport_ImportModule("__builtin__"); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1068 PyObject *bdict = PyModule_GetDict(bltinmod); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1069 PyObject *doc = PyString_FromString(module__doc__); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1070 PyObject *args; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1071 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1072 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
|
1073 Py_DECREF(doc); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1074 if (PyErr_Occurred()) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1075 Py_FatalError("exceptions bootstrapping error."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1076 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1077 /* 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
|
1078 if (make_Exception(modulename) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1079 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
|
1080 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
|
1081 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1082 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
|
1083 } |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1084 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1085 /* 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
|
1086 * 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
|
1087 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1088 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
|
1089 int status; |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1090 char *cname = PyMem_NEW(char, modnamesz+strlen(exctable[i].name)+2); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1091 PyObject *base; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1092 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1093 (void)strcpy(cname, modulename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1094 (void)strcat(cname, "."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1095 (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
|
1096 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1097 if (exctable[i].base == 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1098 base = PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1099 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1100 base = *exctable[i].base; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1101 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1102 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
|
1103 exctable[i].methods, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1104 exctable[i].docstr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1105 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1106 PyMem_DEL(cname); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1107 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1108 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1109 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
|
1110 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1111 if (exctable[i].classinit) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1112 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
|
1113 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1114 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
|
1115 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1116 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1117 /* 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
|
1118 * module. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1119 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1120 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
|
1121 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
|
1122 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1123 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
|
1124 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1125 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1126 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1127 /* 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
|
1128 args = Py_BuildValue("()"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1129 if (!args || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1130 !(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
|
1131 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1132 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
|
1133 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1134 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1135 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1136 /* We're done with __builtin__ */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1137 Py_DECREF(bltinmod); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1138 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1139 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1140 |
|
16837
0e6a3da4f956
SF patch 404928: Support for next Cygwin gcc (2.95.2-8)
Tim Peters <tim.peters@gmail.com>
parents:
16164
diff
changeset
|
1141 DL_EXPORT(void) |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1142 fini_exceptions(void) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1143 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1144 int i; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1145 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1146 Py_XDECREF(PyExc_MemoryErrorInst); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1147 PyExc_MemoryErrorInst = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1148 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1149 for (i=0; exctable[i].name; i++) { |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1150 /* clear the class's dictionary, freeing up circular references |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1151 * between the class and its methods. |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1152 */ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1153 PyObject* cdict = PyObject_GetAttrString(*exctable[i].exc, "__dict__"); |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1154 PyDict_Clear(cdict); |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1155 Py_DECREF(cdict); |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1156 |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1157 /* Now decref the exception class */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1158 Py_XDECREF(*exctable[i].exc); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1159 *exctable[i].exc = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1160 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1161 } |
