Mercurial > cpython-lru_cache-weakref
annotate Python/exceptions.c @ 36786:57322cb2ca11 legacy-trunk
Patch #1440601: Add col_offset attribute to AST nodes.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Wed, 01 Mar 2006 22:49:05 +0000 |
| parents | 25f8e6dde4a3 |
| children | 42487d8cf338 |
| 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 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
11 * written by Fredrik Lundh |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 * 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
|
13 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 * 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
|
15 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 #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
|
18 #include "osdefs.h" |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 |
|
13565
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
20 /* 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
|
21 * 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
|
22 * compile-time literal concatenation. |
|
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
23 */ |
|
22629
7230e01c3c49
add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents:
22121
diff
changeset
|
24 |
|
7230e01c3c49
add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents:
22121
diff
changeset
|
25 /* NOTE: If the exception class hierarchy changes, don't forget to update |
|
7230e01c3c49
add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents:
22121
diff
changeset
|
26 * Doc/lib/libexcs.tex! |
|
7230e01c3c49
add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents:
22121
diff
changeset
|
27 */ |
|
7230e01c3c49
add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents:
22121
diff
changeset
|
28 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
29 PyDoc_STRVAR(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\ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
32 Exceptions found here are defined both in the exceptions module and the \n\ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
33 built-in namespace. It is recommended that user-defined exceptions inherit \n\ |
|
36781
25f8e6dde4a3
Document PEP 352 changes. Also added GeneratorExit.
Brett Cannon <bcannon@gmail.com>
parents:
36751
diff
changeset
|
34 from Exception. See the documentation for the exception inheritance hierarchy.\n\ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
35 " |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
36 |
|
13565
e558eb228a46
Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents:
13539
diff
changeset
|
37 /* keep string pieces "small" */ |
|
36781
25f8e6dde4a3
Document PEP 352 changes. Also added GeneratorExit.
Brett Cannon <bcannon@gmail.com>
parents:
36751
diff
changeset
|
38 /* XXX(bcannon): exception hierarchy in Lib/test/exception_hierarchy.txt */ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
39 ); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
40 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
41 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
42 /* 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
|
43 static int |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
44 populate_methods(PyObject *klass, PyMethodDef *methods) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 { |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
46 PyObject *module; |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
47 int status = -1; |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
48 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
49 if (!methods) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 return 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
51 |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
52 module = PyString_FromString("exceptions"); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
53 if (!module) |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
54 return 0; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
55 while (methods->ml_name) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 /* get a wrapper for the built-in function */ |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
57 PyObject *func = PyCFunction_NewEx(methods, NULL, module); |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
58 PyObject *meth; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
59 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
60 if (!func) |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
61 goto status; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
62 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
63 /* 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
|
64 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
|
65 Py_DECREF(func); |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
66 goto status; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 } |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
68 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
69 /* add method to dictionary */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
70 status = PyObject_SetAttrString(klass, methods->ml_name, meth); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
71 Py_DECREF(meth); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
72 Py_DECREF(func); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
73 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 /* 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
|
75 if (status) |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
76 goto status; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
78 methods++; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
79 } |
|
27559
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
80 status = 0; |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
81 status: |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
82 Py_DECREF(module); |
|
faabd9867fb8
Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26550
diff
changeset
|
83 return status; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
85 |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
86 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
87 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
88 /* 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
|
89 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
90 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
|
91 char *name, PyMethodDef *methods, |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
92 char *docstr) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
93 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
94 PyObject *dict = PyDict_New(); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
95 PyObject *str = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
97 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
99 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
100 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
101 /* 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
|
102 * returning NULL. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
105 if (docstr) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
106 if (!(str = PyString_FromString(docstr))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
107 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
108 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
|
109 goto finally; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
112 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
|
113 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
114 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
115 if (populate_methods(*klass, methods)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
116 Py_DECREF(*klass); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
117 *klass = NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
118 goto finally; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
120 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
121 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
126 return status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
127 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
128 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
129 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 /* 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
|
131 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
132 get_self(PyObject *args) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
134 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
|
135 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
|
136 /* 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
|
137 if (PyExc_TypeError) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
138 PyErr_SetString(PyExc_TypeError, |
| 15318 | 139 "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
|
140 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
143 return self; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
145 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
146 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
147 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
148 /* 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
|
149 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
150 * First thing we create is the base class for all exceptions, called |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
151 * appropriately BaseException. 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
|
152 * 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
|
153 * 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
|
154 * |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
155 * Next, Exception is created since it is the common subclass for the rest of |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
156 * the needed exceptions for this bootstrapping to work. StandardError is |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
157 * created (which is quite simple) followed by |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
158 * 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
|
159 * 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
|
160 * 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
|
161 * explicit bootstrap order. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
162 * |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
163 * All classes after BaseException can be created using PyErr_NewException(). |
|
12771
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 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
166 PyDoc_STRVAR(BaseException__doc__, "Common base class for all exceptions"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
167 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
168 /* |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
169 Set args and message attributes. |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
170 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
171 Assumes self and args have already been set properly with set_self, etc. |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
172 */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
173 static int |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
174 set_args_and_message(PyObject *self, PyObject *args) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
175 { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
176 PyObject *message_val; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
177 Py_ssize_t args_len = PySequence_Length(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
178 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
179 if (args_len < 0) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
180 return 0; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
181 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
182 /* set args */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
183 if (PyObject_SetAttrString(self, "args", args) < 0) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
184 return 0; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
185 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
186 /* set message */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
187 if (args_len == 1) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
188 message_val = PySequence_GetItem(args, 0); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
189 else |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
190 message_val = PyString_FromString(""); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
191 if (!message_val) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
192 return 0; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
193 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
194 if (PyObject_SetAttrString(self, "message", message_val) < 0) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
195 Py_DECREF(message_val); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
196 return 0; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
197 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
198 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
199 Py_DECREF(message_val); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
200 return 1; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
201 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
202 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
203 static PyObject * |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
204 BaseException__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
|
205 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
206 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
207 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
208 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
209 /* set args and message attribute */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
210 args = PySequence_GetSlice(args, 1, PySequence_Length(args)); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
212 return NULL; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
213 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
214 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
215 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
216 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
217 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
218 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
219 Py_DECREF(args); |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
220 Py_RETURN_NONE; |
|
12771
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
223 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
224 static PyObject * |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
225 BaseException__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
|
226 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
227 PyObject *out; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
228 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
229 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
|
230 return NULL; |
|
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 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
234 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
235 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
236 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
237 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
238 out = PyString_FromString(""); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
239 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
240 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
|
241 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
242 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
|
243 if (tmp) { |
|
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
244 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
|
245 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
|
246 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
247 else |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
248 out = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
249 break; |
|
13484
67fd19d74528
Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents:
13453
diff
changeset
|
250 } |
|
25320
14ad560f4a97
Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
Guido van Rossum <guido@python.org>
parents:
25110
diff
changeset
|
251 case -1: |
|
14ad560f4a97
Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
Guido van Rossum <guido@python.org>
parents:
25110
diff
changeset
|
252 PyErr_Clear(); |
|
14ad560f4a97
Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
Guido van Rossum <guido@python.org>
parents:
25110
diff
changeset
|
253 /* Fall through */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
254 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
255 out = PyObject_Str(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
256 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
257 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
258 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
259 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
260 return out; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
261 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
262 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
263 #ifdef Py_USING_UNICODE |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
264 static PyObject * |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
265 BaseException__unicode__(PyObject *self, PyObject *args) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
266 { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
267 Py_ssize_t args_len; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
268 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
269 if (!PyArg_ParseTuple(args, "O:__unicode__", &self)) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
270 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
271 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
272 args = PyObject_GetAttrString(self, "args"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
273 if (!args) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
274 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
275 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
276 args_len = PySequence_Size(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
277 if (args_len < 0) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
278 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
279 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
280 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
281 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
282 if (args_len == 0) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
283 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
284 return PyUnicode_FromUnicode(NULL, 0); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
285 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
286 else if (args_len == 1) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
287 PyObject *temp = PySequence_GetItem(args, 0); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
288 if (!temp) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
289 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
290 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
291 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
292 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
293 return PyObject_Unicode(temp); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
294 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
295 else { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
296 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
297 return PyObject_Unicode(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
298 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
299 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
300 #endif /* Py_USING_UNICODE */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
301 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
302 static PyObject * |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
303 BaseException__repr__(PyObject *self, PyObject *args) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
304 { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
305 PyObject *args_attr; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
306 Py_ssize_t args_len; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
307 PyObject *repr_suffix; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
308 PyObject *repr; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
309 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
310 if (!PyArg_ParseTuple(args, "O:__repr__", &self)) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
311 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
312 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
313 args_attr = PyObject_GetAttrString(self, "args"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
314 if (!args_attr) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
315 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
316 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
317 args_len = PySequence_Length(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
318 if (args_len < 0) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
319 Py_DECREF(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
320 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
321 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
322 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
323 if (args_len == 0) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
324 Py_DECREF(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
325 repr_suffix = PyString_FromString("()"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
326 if (!repr_suffix) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
327 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
328 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
329 else { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
330 PyObject *args_repr; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
331 /*PyObject *right_paren; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
332 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
333 repr_suffix = PyString_FromString("(*"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
334 if (!repr_suffix) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
335 Py_DECREF(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
336 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
337 }*/ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
338 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
339 args_repr = PyObject_Repr(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
340 Py_DECREF(args_attr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
341 if (!args_repr) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
342 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
343 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
344 repr_suffix = args_repr; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
345 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
346 /*PyString_ConcatAndDel(&repr_suffix, args_repr); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
347 if (!repr_suffix) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
348 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
349 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
350 right_paren = PyString_FromString(")"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
351 if (!right_paren) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
352 Py_DECREF(repr_suffix); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
353 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
354 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
355 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
356 PyString_ConcatAndDel(&repr_suffix, right_paren); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
357 if (!repr_suffix) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
358 return NULL;*/ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
359 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
360 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
361 repr = PyString_FromString(self->ob_type->tp_name); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
362 if (!repr) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
363 Py_DECREF(repr_suffix); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
364 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
365 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
366 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
367 PyString_ConcatAndDel(&repr, repr_suffix); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
368 return repr; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
369 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
370 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
371 static PyObject * |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
372 BaseException__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
|
373 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
374 PyObject *out; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
375 PyObject *index; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
376 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
377 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
|
378 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
379 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
380 args = PyObject_GetAttrString(self, "args"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
381 if (!args) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
382 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
383 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
384 out = PyObject_GetItem(args, index); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
385 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
386 return out; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
389 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
390 static PyMethodDef |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
391 BaseException_methods[] = { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
392 /* methods for the BaseException class */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
393 {"__getitem__", BaseException__getitem__, METH_VARARGS}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
394 {"__repr__", BaseException__repr__, METH_VARARGS}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
395 {"__str__", BaseException__str__, METH_VARARGS}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
396 #ifdef Py_USING_UNICODE |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
397 {"__unicode__", BaseException__unicode__, METH_VARARGS}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
398 #endif /* Py_USING_UNICODE */ |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
399 {"__init__", BaseException__init__, METH_VARARGS}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
400 {NULL, NULL } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
401 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
402 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
403 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
404 static int |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
405 make_BaseException(char *modulename) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
406 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
407 PyObject *dict = PyDict_New(); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
408 PyObject *str = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
409 PyObject *name = NULL; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
410 PyObject *emptytuple = NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
411 PyObject *argstuple = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
412 int status = -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
413 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
414 if (!dict) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
415 return -1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
416 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
417 /* 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
|
418 * returning NULL. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
419 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
420 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
421 if (!(str = PyString_FromString(modulename))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
422 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
423 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
|
424 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
425 Py_DECREF(str); |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
426 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
427 if (!(str = PyString_FromString(BaseException__doc__))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
428 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
429 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
|
430 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
431 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
432 if (!(name = PyString_FromString("BaseException"))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
433 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
434 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
435 if (!(emptytuple = PyTuple_New(0))) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
436 goto finally; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
437 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
438 if (!(argstuple = PyTuple_Pack(3, name, emptytuple, dict))) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
439 goto finally; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
440 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
441 if (!(PyExc_BaseException = PyType_Type.tp_new(&PyType_Type, argstuple, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
442 NULL))) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
443 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
444 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
445 /* Now populate the dictionary with the method suite */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
446 if (populate_methods(PyExc_BaseException, BaseException_methods)) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
447 /* Don't need to reclaim PyExc_BaseException here because that'll |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
448 * happen during interpreter shutdown. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
449 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
450 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
451 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
452 status = 0; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
453 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
454 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
455 Py_XDECREF(dict); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
456 Py_XDECREF(str); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
457 Py_XDECREF(name); |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
458 Py_XDECREF(emptytuple); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
459 Py_XDECREF(argstuple); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
460 return status; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
463 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
464 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
465 PyDoc_STRVAR(Exception__doc__, "Common base class for all non-exit exceptions."); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
466 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
467 PyDoc_STRVAR(StandardError__doc__, |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
468 "Base class for all standard Python exceptions that do not represent" |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
469 "interpreter exiting."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
470 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
471 PyDoc_STRVAR(TypeError__doc__, "Inappropriate argument type."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
472 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
473 PyDoc_STRVAR(StopIteration__doc__, "Signal the end from iterator.next()."); |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
33256
diff
changeset
|
474 PyDoc_STRVAR(GeneratorExit__doc__, "Request that a generator exit."); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
475 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
476 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
477 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
478 PyDoc_STRVAR(SystemExit__doc__, "Request to exit from the interpreter."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
479 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
480 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
481 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
482 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
|
483 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
484 PyObject *code; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
485 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
486 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
487 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
488 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
489 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
490 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
|
491 return NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
492 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
493 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
494 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
495 return NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
496 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
497 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
498 /* set code attribute */ |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
499 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
500 case 0: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
501 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
502 code = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
503 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
504 case 1: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
505 code = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
506 break; |
|
25325
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
507 case -1: |
|
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
508 PyErr_Clear(); |
|
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
509 /* Fall through */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
510 default: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
511 Py_INCREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
512 code = args; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
513 break; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
514 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
515 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
516 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
|
517 Py_DECREF(code); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
518 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
519 if (status < 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
520 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
521 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
522 Py_RETURN_NONE; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
523 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
524 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
525 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
16852
diff
changeset
|
526 static PyMethodDef SystemExit_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
527 { "__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
|
528 {NULL, NULL} |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
531 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
532 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
533 PyDoc_STRVAR(KeyboardInterrupt__doc__, "Program interrupted by user."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
534 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
535 PyDoc_STRVAR(ImportError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
536 "Import can't find module, or can't find name in module."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
537 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
538 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
539 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
540 PyDoc_STRVAR(EnvironmentError__doc__, "Base class for I/O related errors."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
541 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
542 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
543 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
544 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
|
545 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
546 PyObject *item0 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
547 PyObject *item1 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
548 PyObject *item2 = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
549 PyObject *subslice = NULL; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
550 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
551 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
552 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
553 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
554 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
555 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
|
556 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
557 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
558 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
559 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
560 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
561 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
562 |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
563 if (PyObject_SetAttrString(self, "errno", Py_None) || |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
564 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
|
565 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
|
566 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
567 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
568 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
569 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
570 switch (PySequence_Size(args)) { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
571 case 3: |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
572 /* 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
|
573 * 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
|
574 * 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
|
575 * 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
|
576 * |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
577 * except IOError, (errno, strerror): |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
578 * |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
579 * 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
|
580 * 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
|
581 * when it was supplied. |
|
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 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
584 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
585 item2 = PySequence_GetItem(args, 2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
586 if (!item0 || !item1 || !item2) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
587 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
588 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
589 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
|
590 PyObject_SetAttrString(self, "strerror", item1) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
591 PyObject_SetAttrString(self, "filename", item2)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
592 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
593 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
594 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
595 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
596 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
|
597 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
|
598 goto finally; |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
599 break; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
600 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
601 case 2: |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
602 /* 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
|
603 * argument is given. |
|
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
604 */ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
605 item0 = PySequence_GetItem(args, 0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
606 item1 = PySequence_GetItem(args, 1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
607 if (!item0 || !item1) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
608 goto finally; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
609 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
610 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
|
611 PyObject_SetAttrString(self, "strerror", item1)) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
612 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
613 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
614 } |
|
13453
d6198e703602
EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents:
13283
diff
changeset
|
615 break; |
|
25325
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
616 |
|
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
617 case -1: |
|
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
618 PyErr_Clear(); |
|
6b62ab8485eb
Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25320
diff
changeset
|
619 break; |
|
12771
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 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
623 rtnval = Py_None; |
|
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 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
626 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
627 Py_XDECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
628 Py_XDECREF(item1); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
629 Py_XDECREF(item2); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
630 Py_XDECREF(subslice); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
631 return rtnval; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
634 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
635 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
636 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
|
637 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
638 PyObject *originalself = self; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
639 PyObject *filename; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
640 PyObject *serrno; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
641 PyObject *strerror; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
642 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
643 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
644 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
|
645 return NULL; |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
646 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
647 filename = PyObject_GetAttrString(self, "filename"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
648 serrno = PyObject_GetAttrString(self, "errno"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
649 strerror = PyObject_GetAttrString(self, "strerror"); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
650 if (!filename || !serrno || !strerror) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
651 goto finally; |
|
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 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
|
654 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
|
655 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
|
656 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
|
657 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
658 if (!fmt || !repr || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
659 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
660 Py_XDECREF(repr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
661 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
662 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
663 } |
|
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 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
|
666 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
|
667 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
|
668 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
669 rtnval = PyString_Format(fmt, tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
670 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
671 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
672 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
673 /* 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
|
674 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
675 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
676 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
681 if (!fmt || !tuple) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
682 Py_XDECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
683 Py_XDECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
684 goto finally; |
|
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 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
687 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
|
688 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
|
689 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
690 rtnval = PyString_Format(fmt, tuple); |
|
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 Py_DECREF(fmt); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
693 Py_DECREF(tuple); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
694 /* 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
|
695 serrno = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
696 strerror = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
697 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
698 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
699 /* The original Python code said: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
700 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
701 * return StandardError.__str__(self) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
702 * |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
703 * but there is no StandardError__str__() function; we happen to |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
704 * know that's just a pass through to BaseException__str__(). |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
705 */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
706 rtnval = BaseException__str__(originalself, args); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
707 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
708 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
709 Py_XDECREF(filename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
710 Py_XDECREF(serrno); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
711 Py_XDECREF(strerror); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
712 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
713 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
714 |
|
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 static |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
717 PyMethodDef EnvironmentError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
718 {"__init__", EnvironmentError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
719 {"__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
|
720 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
721 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
722 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
723 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
724 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
725 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
726 PyDoc_STRVAR(IOError__doc__, "I/O operation failed."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
727 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
728 PyDoc_STRVAR(OSError__doc__, "OS system call failed."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
729 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
730 #ifdef MS_WINDOWS |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
731 PyDoc_STRVAR(WindowsError__doc__, "MS-Windows OS system call failed."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
732 #endif /* MS_WINDOWS */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
733 |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
734 #ifdef __VMS |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
735 static char |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
736 VMSError__doc__[] = "OpenVMS OS system call failed."; |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
737 #endif |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
738 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
739 PyDoc_STRVAR(EOFError__doc__, "Read beyond end of file."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
740 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
741 PyDoc_STRVAR(RuntimeError__doc__, "Unspecified run-time error."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
742 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
743 PyDoc_STRVAR(NotImplementedError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
744 "Method or function hasn't been implemented yet."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
745 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
746 PyDoc_STRVAR(NameError__doc__, "Name not found globally."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
747 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
748 PyDoc_STRVAR(UnboundLocalError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
749 "Local name referenced but not bound to a value."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
750 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
751 PyDoc_STRVAR(AttributeError__doc__, "Attribute not found."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
752 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
753 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
754 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
755 PyDoc_STRVAR(SyntaxError__doc__, "Invalid syntax."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
756 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
757 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
758 static int |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
759 SyntaxError__classinit__(PyObject *klass) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
760 { |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
761 int retval = 0; |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
762 PyObject *emptystring = PyString_FromString(""); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
763 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
764 /* Additional class-creation time initializations */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
765 if (!emptystring || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
766 PyObject_SetAttrString(klass, "msg", emptystring) || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
767 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
|
768 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
|
769 PyObject_SetAttrString(klass, "offset", Py_None) || |
|
22121
d4406fbfcb4e
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21072
diff
changeset
|
770 PyObject_SetAttrString(klass, "text", Py_None) || |
|
d4406fbfcb4e
Patch #50002: Display line information for bad \x escapes:
Martin v. Löwis <martin@v.loewis.de>
parents:
21072
diff
changeset
|
771 PyObject_SetAttrString(klass, "print_file_and_line", Py_None)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
772 { |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
773 retval = -1; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
774 } |
|
14054
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
775 Py_XDECREF(emptystring); |
|
e8301612e7d8
SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents:
14013
diff
changeset
|
776 return retval; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
777 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
778 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
779 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
780 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
781 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
|
782 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
783 PyObject *rtnval = NULL; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
784 int lenargs; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
785 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
786 if (!(self = get_self(args))) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
787 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
788 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
789 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
|
790 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
791 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
792 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
793 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
794 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
795 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
796 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13565
diff
changeset
|
797 lenargs = PySequence_Size(args); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
798 if (lenargs >= 1) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
799 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
|
800 int status; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
801 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
802 if (!item0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
803 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
804 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
|
805 Py_DECREF(item0); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
806 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
807 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
808 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
809 if (lenargs == 2) { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
810 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
|
811 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
|
812 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
|
813 int status = 1; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
814 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
815 if (!info) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
816 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
817 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
818 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
|
819 if (filename != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
820 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
|
821 if (lineno != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
822 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
|
823 if (offset != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
824 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
|
825 if (text != NULL) { |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
826 status = |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
827 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
|
828 || 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
|
829 || 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
|
830 || 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
|
831 Py_DECREF(text); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
832 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
833 Py_DECREF(offset); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
834 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
835 Py_DECREF(lineno); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
836 } |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
837 Py_DECREF(filename); |
|
847844248c6f
SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents:
16837
diff
changeset
|
838 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
839 Py_DECREF(info); |
|
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 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
842 goto finally; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
843 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
844 Py_INCREF(Py_None); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
845 rtnval = Py_None; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
846 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
847 finally: |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
848 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
849 return rtnval; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
850 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
851 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
852 |
|
13996
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
853 /* 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
|
854 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
|
855 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
|
856 static char * |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
857 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
|
858 { |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
859 char *cp = name; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
860 char *result = name; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
861 |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
862 if (name == NULL) |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
863 return "???"; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
864 while (*cp != '\0') { |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
865 if (*cp == SEP) |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
866 result = cp + 1; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
867 ++cp; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
868 } |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
869 return result; |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
870 } |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
871 |
|
d8069efcd76e
my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents:
13991
diff
changeset
|
872 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
873 static PyObject * |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
874 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
|
875 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
876 PyObject *msg; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
877 PyObject *str; |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
878 PyObject *filename, *lineno, *result; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
879 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
880 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
|
881 return NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
882 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
883 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
|
884 return NULL; |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
885 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
886 str = PyObject_Str(msg); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
887 Py_DECREF(msg); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
888 result = str; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
889 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
890 /* 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
|
891 lineno here */ |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
892 |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
893 if (str != NULL && PyString_Check(str)) { |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
894 int have_filename = 0; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
895 int have_lineno = 0; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
896 char *buffer = NULL; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
897 |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
898 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
|
899 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
|
900 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
901 PyErr_Clear(); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
902 |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
903 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
|
904 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
|
905 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
906 PyErr_Clear(); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
907 |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
908 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
|
909 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
|
910 if (have_filename) |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
911 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
|
912 |
|
21072
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
913 buffer = PyMem_MALLOC(bufsize); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
914 if (buffer != NULL) { |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
915 if (have_filename && have_lineno) |
|
21072
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
916 PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
917 PyString_AS_STRING(str), |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
918 my_basename(PyString_AS_STRING(filename)), |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
919 PyInt_AsLong(lineno)); |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
920 else if (have_filename) |
|
21072
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
921 PyOS_snprintf(buffer, bufsize, "%s (%s)", |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
922 PyString_AS_STRING(str), |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
923 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
|
924 else if (have_lineno) |
|
21072
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
925 PyOS_snprintf(buffer, bufsize, "%s (line %ld)", |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
926 PyString_AS_STRING(str), |
|
639c0a3ae8dc
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20279
diff
changeset
|
927 PyInt_AsLong(lineno)); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
928 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
929 result = PyString_FromString(buffer); |
|
14013
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
930 PyMem_FREE(buffer); |
|
6c7fa523726f
SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents:
13996
diff
changeset
|
931 |
|
13991
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
932 if (result == NULL) |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
933 result = str; |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
934 else |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
935 Py_DECREF(str); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
936 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
937 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
938 Py_XDECREF(filename); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
939 Py_XDECREF(lineno); |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
940 } |
|
7834a113ce24
SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents:
13973
diff
changeset
|
941 return result; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
942 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
943 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
944 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
16852
diff
changeset
|
945 static PyMethodDef SyntaxError_methods[] = { |
|
13182
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
946 {"__init__", SyntaxError__init__, METH_VARARGS}, |
|
1e302d996d58
replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12968
diff
changeset
|
947 {"__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
|
948 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
949 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
950 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
951 |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
952 static PyObject * |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
953 KeyError__str__(PyObject *self, PyObject *args) |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
954 { |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
955 PyObject *argsattr; |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
956 PyObject *result; |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
957 |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
958 if (!PyArg_ParseTuple(args, "O:__str__", &self)) |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
959 return NULL; |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
960 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
961 argsattr = PyObject_GetAttrString(self, "args"); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
962 if (!argsattr) |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
963 return NULL; |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
964 |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
965 /* If args is a tuple of exactly one item, apply repr to args[0]. |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
966 This is done so that e.g. the exception raised by {}[''] prints |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
967 KeyError: '' |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
968 rather than the confusing |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
969 KeyError |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
970 alone. The downside is that if KeyError is raised with an explanatory |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
971 string, that string will be displayed in quotes. Too bad. |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
972 If args is anything else, use the default BaseException__str__(). |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
973 */ |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
974 if (PyTuple_Check(argsattr) && PyTuple_GET_SIZE(argsattr) == 1) { |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
975 PyObject *key = PyTuple_GET_ITEM(argsattr, 0); |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
976 result = PyObject_Repr(key); |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
977 } |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
978 else |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
979 result = BaseException__str__(self, args); |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
980 |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
981 Py_DECREF(argsattr); |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
982 return result; |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
983 } |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
984 |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
985 static PyMethodDef KeyError_methods[] = { |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
986 {"__str__", KeyError__str__, METH_VARARGS}, |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
987 {NULL, NULL} |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
988 }; |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
989 |
|
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
990 |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
991 #ifdef Py_USING_UNICODE |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
992 static |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
993 int get_int(PyObject *exc, const char *name, Py_ssize_t *value) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
994 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
995 PyObject *attr = PyObject_GetAttrString(exc, (char *)name); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
996 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
997 if (!attr) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
998 return -1; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
999 if (PyInt_Check(attr)) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1000 *value = PyInt_AS_LONG(attr); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1001 } else if (PyLong_Check(attr)) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1002 *value = (size_t)PyLong_AsLongLong(attr); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1003 if (*value == -1) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1004 Py_DECREF(attr); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1005 return -1; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1006 } |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1007 } else { |
|
25093
ae1469e468a0
Limit the length of attribute names in exception messages
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1008 PyErr_Format(PyExc_TypeError, "%.200s attribute must be int", name); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1009 Py_DECREF(attr); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1010 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1011 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1012 Py_DECREF(attr); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1013 return 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1014 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1015 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1016 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1017 static |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1018 int set_ssize_t(PyObject *exc, const char *name, Py_ssize_t value) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1019 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1020 PyObject *obj = PyInt_FromSsize_t(value); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1021 int result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1022 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1023 if (!obj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1024 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1025 result = PyObject_SetAttrString(exc, (char *)name, obj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1026 Py_DECREF(obj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1027 return result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1028 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1029 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1030 static |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1031 PyObject *get_string(PyObject *exc, const char *name) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1032 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1033 PyObject *attr = PyObject_GetAttrString(exc, (char *)name); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1034 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1035 if (!attr) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1036 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1037 if (!PyString_Check(attr)) { |
|
25093
ae1469e468a0
Limit the length of attribute names in exception messages
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1038 PyErr_Format(PyExc_TypeError, "%.200s attribute must be str", name); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1039 Py_DECREF(attr); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1040 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1041 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1042 return attr; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1043 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1044 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1045 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1046 static |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1047 int set_string(PyObject *exc, const char *name, const char *value) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1048 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1049 PyObject *obj = PyString_FromString(value); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1050 int result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1051 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1052 if (!obj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1053 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1054 result = PyObject_SetAttrString(exc, (char *)name, obj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1055 Py_DECREF(obj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1056 return result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1057 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1058 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1059 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1060 static |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1061 PyObject *get_unicode(PyObject *exc, const char *name) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1062 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1063 PyObject *attr = PyObject_GetAttrString(exc, (char *)name); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1064 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1065 if (!attr) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1066 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1067 if (!PyUnicode_Check(attr)) { |
|
25093
ae1469e468a0
Limit the length of attribute names in exception messages
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1068 PyErr_Format(PyExc_TypeError, "%.200s attribute must be unicode", name); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1069 Py_DECREF(attr); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1070 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1071 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1072 return attr; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1073 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1074 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1075 PyObject * PyUnicodeEncodeError_GetEncoding(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1076 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1077 return get_string(exc, "encoding"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1078 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1079 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1080 PyObject * PyUnicodeDecodeError_GetEncoding(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1081 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1082 return get_string(exc, "encoding"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1083 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1084 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1085 PyObject *PyUnicodeEncodeError_GetObject(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1086 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1087 return get_unicode(exc, "object"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1088 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1089 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1090 PyObject *PyUnicodeDecodeError_GetObject(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1091 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1092 return get_string(exc, "object"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1093 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1094 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1095 PyObject *PyUnicodeTranslateError_GetObject(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1096 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1097 return get_unicode(exc, "object"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1098 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1099 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1100 int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1101 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1102 if (!get_int(exc, "start", start)) { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1103 PyObject *object = PyUnicodeEncodeError_GetObject(exc); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1104 Py_ssize_t size; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1105 if (!object) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1106 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1107 size = PyUnicode_GET_SIZE(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1108 if (*start<0) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1109 *start = 0; /*XXX check for values <0*/ |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1110 if (*start>=size) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1111 *start = size-1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1112 Py_DECREF(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1113 return 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1114 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1115 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1116 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1117 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1118 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1119 int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1120 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1121 if (!get_int(exc, "start", start)) { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1122 PyObject *object = PyUnicodeDecodeError_GetObject(exc); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1123 Py_ssize_t size; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1124 if (!object) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1125 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1126 size = PyString_GET_SIZE(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1127 if (*start<0) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1128 *start = 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1129 if (*start>=size) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1130 *start = size-1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1131 Py_DECREF(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1132 return 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1133 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1134 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1135 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1136 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1137 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1138 int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1139 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1140 return PyUnicodeEncodeError_GetStart(exc, start); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1141 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1142 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1143 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1144 int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1145 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1146 return set_ssize_t(exc, "start", start); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1147 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1148 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1149 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1150 int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1151 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1152 return set_ssize_t(exc, "start", start); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1153 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1154 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1155 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1156 int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1157 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1158 return set_ssize_t(exc, "start", start); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1159 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1160 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1161 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1162 int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1163 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1164 if (!get_int(exc, "end", end)) { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1165 PyObject *object = PyUnicodeEncodeError_GetObject(exc); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1166 Py_ssize_t size; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1167 if (!object) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1168 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1169 size = PyUnicode_GET_SIZE(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1170 if (*end<1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1171 *end = 1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1172 if (*end>size) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1173 *end = size; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1174 Py_DECREF(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1175 return 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1176 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1177 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1178 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1179 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1180 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1181 int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1182 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1183 if (!get_int(exc, "end", end)) { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1184 PyObject *object = PyUnicodeDecodeError_GetObject(exc); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1185 Py_ssize_t size; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1186 if (!object) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1187 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1188 size = PyString_GET_SIZE(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1189 if (*end<1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1190 *end = 1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1191 if (*end>size) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1192 *end = size; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1193 Py_DECREF(object); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1194 return 0; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1195 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1196 return -1; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1197 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1198 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1199 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1200 int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1201 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1202 return PyUnicodeEncodeError_GetEnd(exc, start); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1203 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1204 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1205 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1206 int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1207 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1208 return set_ssize_t(exc, "end", end); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1209 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1210 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1211 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1212 int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1213 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1214 return set_ssize_t(exc, "end", end); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1215 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1216 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1217 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1218 int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1219 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1220 return set_ssize_t(exc, "end", end); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1221 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1222 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1223 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1224 PyObject *PyUnicodeEncodeError_GetReason(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1225 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1226 return get_string(exc, "reason"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1227 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1228 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1229 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1230 PyObject *PyUnicodeDecodeError_GetReason(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1231 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1232 return get_string(exc, "reason"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1233 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1234 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1235 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1236 PyObject *PyUnicodeTranslateError_GetReason(PyObject *exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1237 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1238 return get_string(exc, "reason"); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1239 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1240 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1241 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1242 int PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1243 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1244 return set_string(exc, "reason", reason); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1245 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1246 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1247 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1248 int PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1249 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1250 return set_string(exc, "reason", reason); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1251 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1252 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1253 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1254 int PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1255 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1256 return set_string(exc, "reason", reason); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1257 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1258 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1259 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1260 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1261 UnicodeError__init__(PyObject *self, PyObject *args, PyTypeObject *objecttype) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1262 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1263 PyObject *rtnval = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1264 PyObject *encoding; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1265 PyObject *object; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1266 PyObject *start; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1267 PyObject *end; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1268 PyObject *reason; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1269 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1270 if (!(self = get_self(args))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1271 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1272 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1273 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1274 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1275 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1276 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1277 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1278 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1279 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1280 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1281 if (!PyArg_ParseTuple(args, "O!O!O!O!O!", |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1282 &PyString_Type, &encoding, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1283 objecttype, &object, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1284 &PyInt_Type, &start, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1285 &PyInt_Type, &end, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1286 &PyString_Type, &reason)) |
|
30152
0813b33610cc
Fix refcount leak in the UnicodeError constructor:
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
1287 goto finally; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1288 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1289 if (PyObject_SetAttrString(self, "encoding", encoding)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1290 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1291 if (PyObject_SetAttrString(self, "object", object)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1292 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1293 if (PyObject_SetAttrString(self, "start", start)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1294 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1295 if (PyObject_SetAttrString(self, "end", end)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1296 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1297 if (PyObject_SetAttrString(self, "reason", reason)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1298 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1299 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1300 Py_INCREF(Py_None); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1301 rtnval = Py_None; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1302 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1303 finally: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1304 Py_DECREF(args); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1305 return rtnval; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1306 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1307 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1308 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1309 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1310 UnicodeEncodeError__init__(PyObject *self, PyObject *args) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1311 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1312 return UnicodeError__init__(self, args, &PyUnicode_Type); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1313 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1314 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1315 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1316 UnicodeEncodeError__str__(PyObject *self, PyObject *arg) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1317 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1318 PyObject *encodingObj = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1319 PyObject *objectObj = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1320 Py_ssize_t start; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1321 Py_ssize_t end; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1322 PyObject *reasonObj = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1323 PyObject *result = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1324 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1325 self = arg; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1326 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1327 if (!(encodingObj = PyUnicodeEncodeError_GetEncoding(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1328 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1329 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1330 if (!(objectObj = PyUnicodeEncodeError_GetObject(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1331 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1332 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1333 if (PyUnicodeEncodeError_GetStart(self, &start)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1334 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1335 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1336 if (PyUnicodeEncodeError_GetEnd(self, &end)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1337 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1338 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1339 if (!(reasonObj = PyUnicodeEncodeError_GetReason(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1340 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1341 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1342 if (end==start+1) { |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1343 int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start]; |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1344 char badchar_str[20]; |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1345 if (badchar <= 0xff) |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1346 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1347 else if (badchar <= 0xffff) |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1348 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1349 else |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1350 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1351 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1352 "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1353 PyString_AS_STRING(encodingObj), |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1354 badchar_str, |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1355 start, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1356 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1357 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1358 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1359 else { |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1360 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1361 "'%.400s' codec can't encode characters in position %zd-%zd: %.400s", |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1362 PyString_AS_STRING(encodingObj), |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1363 start, |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1364 (end-1), |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1365 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1366 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1367 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1368 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1369 error: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1370 Py_XDECREF(reasonObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1371 Py_XDECREF(objectObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1372 Py_XDECREF(encodingObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1373 return result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1374 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1375 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1376 static PyMethodDef UnicodeEncodeError_methods[] = { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1377 {"__init__", UnicodeEncodeError__init__, METH_VARARGS}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1378 {"__str__", UnicodeEncodeError__str__, METH_O}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1379 {NULL, NULL} |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1380 }; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1381 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1382 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1383 PyObject * PyUnicodeEncodeError_Create( |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1384 const char *encoding, const Py_UNICODE *object, Py_ssize_t length, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1385 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1386 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1387 return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1388 encoding, object, length, start, end, reason); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1389 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1390 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1391 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1392 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1393 UnicodeDecodeError__init__(PyObject *self, PyObject *args) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1394 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1395 return UnicodeError__init__(self, args, &PyString_Type); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1396 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1397 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1398 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1399 UnicodeDecodeError__str__(PyObject *self, PyObject *arg) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1400 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1401 PyObject *encodingObj = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1402 PyObject *objectObj = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1403 Py_ssize_t start; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1404 Py_ssize_t end; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1405 PyObject *reasonObj = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1406 PyObject *result = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1407 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1408 self = arg; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1409 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1410 if (!(encodingObj = PyUnicodeDecodeError_GetEncoding(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1411 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1412 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1413 if (!(objectObj = PyUnicodeDecodeError_GetObject(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1414 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1415 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1416 if (PyUnicodeDecodeError_GetStart(self, &start)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1417 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1418 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1419 if (PyUnicodeDecodeError_GetEnd(self, &end)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1420 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1421 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1422 if (!(reasonObj = PyUnicodeDecodeError_GetReason(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1423 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1424 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1425 if (end==start+1) { |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1426 /* FromFormat does not support %02x, so format that separately */ |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1427 char byte[4]; |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1428 PyOS_snprintf(byte, sizeof(byte), "%02x", |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1429 ((int)PyString_AS_STRING(objectObj)[start])&0xff); |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1430 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1431 "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1432 PyString_AS_STRING(encodingObj), |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1433 byte, |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1434 start, |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1435 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1436 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1437 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1438 else { |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1439 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1440 "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s", |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1441 PyString_AS_STRING(encodingObj), |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1442 start, |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1443 (end-1), |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1444 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1445 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1446 } |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1447 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1448 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1449 error: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1450 Py_XDECREF(reasonObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1451 Py_XDECREF(objectObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1452 Py_XDECREF(encodingObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1453 return result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1454 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1455 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1456 static PyMethodDef UnicodeDecodeError_methods[] = { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1457 {"__init__", UnicodeDecodeError__init__, METH_VARARGS}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1458 {"__str__", UnicodeDecodeError__str__, METH_O}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1459 {NULL, NULL} |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1460 }; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1461 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1462 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1463 PyObject * PyUnicodeDecodeError_Create( |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1464 const char *encoding, const char *object, Py_ssize_t length, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1465 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1466 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1467 assert(length < INT_MAX); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1468 assert(start < INT_MAX); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1469 assert(end < INT_MAX); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1470 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#iis", |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1471 encoding, object, (int)length, (int)start, (int)end, reason); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1472 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1473 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1474 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1475 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1476 UnicodeTranslateError__init__(PyObject *self, PyObject *args) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1477 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1478 PyObject *rtnval = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1479 PyObject *object; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1480 PyObject *start; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1481 PyObject *end; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1482 PyObject *reason; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1483 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1484 if (!(self = get_self(args))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1485 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1486 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1487 if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1488 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1489 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1490 if (!set_args_and_message(self, args)) { |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1491 Py_DECREF(args); |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1492 return NULL; |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1493 } |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1494 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1495 if (!PyArg_ParseTuple(args, "O!O!O!O!", |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1496 &PyUnicode_Type, &object, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1497 &PyInt_Type, &start, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1498 &PyInt_Type, &end, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1499 &PyString_Type, &reason)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1500 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1501 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1502 if (PyObject_SetAttrString(self, "object", object)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1503 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1504 if (PyObject_SetAttrString(self, "start", start)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1505 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1506 if (PyObject_SetAttrString(self, "end", end)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1507 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1508 if (PyObject_SetAttrString(self, "reason", reason)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1509 goto finally; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1510 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1511 rtnval = Py_None; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1512 Py_INCREF(rtnval); |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1513 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1514 finally: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1515 Py_DECREF(args); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1516 return rtnval; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1517 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1518 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1519 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1520 static PyObject * |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1521 UnicodeTranslateError__str__(PyObject *self, PyObject *arg) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1522 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1523 PyObject *objectObj = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1524 Py_ssize_t start; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1525 Py_ssize_t end; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1526 PyObject *reasonObj = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1527 PyObject *result = NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1528 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1529 self = arg; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1530 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1531 if (!(objectObj = PyUnicodeTranslateError_GetObject(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1532 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1533 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1534 if (PyUnicodeTranslateError_GetStart(self, &start)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1535 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1536 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1537 if (PyUnicodeTranslateError_GetEnd(self, &end)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1538 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1539 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1540 if (!(reasonObj = PyUnicodeTranslateError_GetReason(self))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1541 goto error; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1542 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1543 if (end==start+1) { |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1544 int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start]; |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1545 char badchar_str[20]; |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1546 if (badchar <= 0xff) |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1547 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1548 else if (badchar <= 0xffff) |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1549 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28049
diff
changeset
|
1550 else |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1551 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1552 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1553 "can't translate character u'\\%s' in position %zd: %.400s", |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1554 badchar_str, |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1555 start, |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1556 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1557 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1558 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1559 else { |
|
36513
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1560 result = PyString_FromFormat( |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1561 "can't translate characters in position %zd-%zd: %.400s", |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1562 start, |
|
445c0aa811ca
Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1563 (end-1), |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1564 PyString_AS_STRING(reasonObj) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1565 ); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1566 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1567 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1568 error: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1569 Py_XDECREF(reasonObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1570 Py_XDECREF(objectObj); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1571 return result; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1572 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1573 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1574 static PyMethodDef UnicodeTranslateError_methods[] = { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1575 {"__init__", UnicodeTranslateError__init__, METH_VARARGS}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1576 {"__str__", UnicodeTranslateError__str__, METH_O}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1577 {NULL, NULL} |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1578 }; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1579 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1580 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1581 PyObject * PyUnicodeTranslateError_Create( |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1582 const Py_UNICODE *object, Py_ssize_t length, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1583 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1584 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1585 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#iis", |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1586 object, length, start, end, reason); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1587 } |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
1588 #endif |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1589 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1590 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1591 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1592 /* Exception doc strings */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1593 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1594 PyDoc_STRVAR(AssertionError__doc__, "Assertion failed."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1595 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1596 PyDoc_STRVAR(LookupError__doc__, "Base class for lookup errors."); |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1597 |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1598 PyDoc_STRVAR(IndexError__doc__, "Sequence index out of range."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1599 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1600 PyDoc_STRVAR(KeyError__doc__, "Mapping key not found."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1601 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1602 PyDoc_STRVAR(ArithmeticError__doc__, "Base class for arithmetic errors."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1603 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1604 PyDoc_STRVAR(OverflowError__doc__, "Result too large to be represented."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1605 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1606 PyDoc_STRVAR(ZeroDivisionError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1607 "Second argument to a division or modulo operation was zero."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1608 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1609 PyDoc_STRVAR(FloatingPointError__doc__, "Floating point operation failed."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1610 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1611 PyDoc_STRVAR(ValueError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1612 "Inappropriate argument value (of correct type)."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1613 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1614 PyDoc_STRVAR(UnicodeError__doc__, "Unicode related error."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1615 |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
1616 #ifdef Py_USING_UNICODE |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1617 PyDoc_STRVAR(UnicodeEncodeError__doc__, "Unicode encoding error."); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1618 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1619 PyDoc_STRVAR(UnicodeDecodeError__doc__, "Unicode decoding error."); |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1620 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1621 PyDoc_STRVAR(UnicodeTranslateError__doc__, "Unicode translation error."); |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
1622 #endif |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1623 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1624 PyDoc_STRVAR(SystemError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1625 "Internal error in the Python interpreter.\n\ |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1626 \n\ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1627 Please report this to the Python maintainer, along with the traceback,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1628 the Python version, and the hardware/OS platform and version."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1629 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1630 PyDoc_STRVAR(ReferenceError__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1631 "Weak ref proxy used after referent went away."); |
|
20279
8b3ea7335c1b
weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents:
19433
diff
changeset
|
1632 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1633 PyDoc_STRVAR(MemoryError__doc__, "Out of memory."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1634 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1635 PyDoc_STRVAR(IndentationError__doc__, "Improper indentation."); |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1636 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1637 PyDoc_STRVAR(TabError__doc__, "Improper mixture of spaces and tabs."); |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1638 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1639 /* Warning category docstrings */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1640 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1641 PyDoc_STRVAR(Warning__doc__, "Base class for warning categories."); |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1642 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1643 PyDoc_STRVAR(UserWarning__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1644 "Base class for warnings generated by user code."); |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1645 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1646 PyDoc_STRVAR(DeprecationWarning__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1647 "Base class for warnings about deprecated features."); |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1648 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1649 PyDoc_STRVAR(PendingDeprecationWarning__doc__, |
|
23564
3f242cdd0904
As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents:
22629
diff
changeset
|
1650 "Base class for warnings about features which will be deprecated " |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1651 "in the future."); |
|
23564
3f242cdd0904
As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents:
22629
diff
changeset
|
1652 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1653 PyDoc_STRVAR(SyntaxWarning__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1654 "Base class for warnings about dubious syntax."); |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1655 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1656 PyDoc_STRVAR(OverflowWarning__doc__, |
|
33256
6641d0542592
Stop producing or using OverflowWarning. PEP 237 thought this would
Tim Peters <tim.peters@gmail.com>
parents:
30683
diff
changeset
|
1657 "Base class for warnings about numeric overflow. Won't exist in Python 2.5."); |
|
19433
5d81c6bff306
Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1658 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1659 PyDoc_STRVAR(RuntimeWarning__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23564
diff
changeset
|
1660 "Base class for warnings about dubious runtime behavior."); |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1661 |
|
24818
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1662 PyDoc_STRVAR(FutureWarning__doc__, |
|
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1663 "Base class for warnings about constructs that will change semantically " |
|
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1664 "in the future."); |
|
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1665 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1666 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1667 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1668 /* module global functions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1669 static PyMethodDef functions[] = { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1670 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1671 {NULL, NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1672 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1673 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1674 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1675 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1676 /* Global C API defined exceptions */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1677 |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1678 PyObject *PyExc_BaseException; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1679 PyObject *PyExc_Exception; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1680 PyObject *PyExc_StopIteration; |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
33256
diff
changeset
|
1681 PyObject *PyExc_GeneratorExit; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1682 PyObject *PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1683 PyObject *PyExc_ArithmeticError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1684 PyObject *PyExc_LookupError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1685 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1686 PyObject *PyExc_AssertionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1687 PyObject *PyExc_AttributeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1688 PyObject *PyExc_EOFError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1689 PyObject *PyExc_FloatingPointError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1690 PyObject *PyExc_EnvironmentError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1691 PyObject *PyExc_IOError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1692 PyObject *PyExc_OSError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1693 PyObject *PyExc_ImportError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1694 PyObject *PyExc_IndexError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1695 PyObject *PyExc_KeyError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1696 PyObject *PyExc_KeyboardInterrupt; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1697 PyObject *PyExc_MemoryError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1698 PyObject *PyExc_NameError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1699 PyObject *PyExc_OverflowError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1700 PyObject *PyExc_RuntimeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1701 PyObject *PyExc_NotImplementedError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1702 PyObject *PyExc_SyntaxError; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1703 PyObject *PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1704 PyObject *PyExc_TabError; |
|
20279
8b3ea7335c1b
weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents:
19433
diff
changeset
|
1705 PyObject *PyExc_ReferenceError; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1706 PyObject *PyExc_SystemError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1707 PyObject *PyExc_SystemExit; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1708 PyObject *PyExc_UnboundLocalError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1709 PyObject *PyExc_UnicodeError; |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1710 PyObject *PyExc_UnicodeEncodeError; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1711 PyObject *PyExc_UnicodeDecodeError; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1712 PyObject *PyExc_UnicodeTranslateError; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1713 PyObject *PyExc_TypeError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1714 PyObject *PyExc_ValueError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1715 PyObject *PyExc_ZeroDivisionError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1716 #ifdef MS_WINDOWS |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1717 PyObject *PyExc_WindowsError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1718 #endif |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1719 #ifdef __VMS |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1720 PyObject *PyExc_VMSError; |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1721 #endif |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1722 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1723 /* Pre-computed MemoryError instance. Best to create this as early as |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1724 * possible and not wait until a MemoryError is actually raised! |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1725 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1726 PyObject *PyExc_MemoryErrorInst; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1727 |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1728 /* Predefined warning categories */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1729 PyObject *PyExc_Warning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1730 PyObject *PyExc_UserWarning; |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1731 PyObject *PyExc_DeprecationWarning; |
|
23564
3f242cdd0904
As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents:
22629
diff
changeset
|
1732 PyObject *PyExc_PendingDeprecationWarning; |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1733 PyObject *PyExc_SyntaxWarning; |
|
33256
6641d0542592
Stop producing or using OverflowWarning. PEP 237 thought this would
Tim Peters <tim.peters@gmail.com>
parents:
30683
diff
changeset
|
1734 /* PyExc_OverflowWarning should be removed for Python 2.5 */ |
|
19433
5d81c6bff306
Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1735 PyObject *PyExc_OverflowWarning; |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1736 PyObject *PyExc_RuntimeWarning; |
|
24818
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1737 PyObject *PyExc_FutureWarning; |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1738 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1739 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1740 |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1741 /* 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
|
1742 static struct { |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1743 char *name; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1744 PyObject **exc; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1745 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
|
1746 char *docstr; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1747 PyMethodDef *methods; |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1748 int (*classinit)(PyObject *); |
|
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1749 } exctable[] = { |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1750 /* |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1751 * The first four classes MUST appear in exactly this order |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1752 */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1753 {"BaseException", &PyExc_BaseException}, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1754 {"Exception", &PyExc_Exception, &PyExc_BaseException, Exception__doc__}, |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1755 {"StopIteration", &PyExc_StopIteration, &PyExc_Exception, |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
1756 StopIteration__doc__}, |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
33256
diff
changeset
|
1757 {"GeneratorExit", &PyExc_GeneratorExit, &PyExc_Exception, |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
33256
diff
changeset
|
1758 GeneratorExit__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1759 {"StandardError", &PyExc_StandardError, &PyExc_Exception, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1760 StandardError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1761 {"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
|
1762 /* |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1763 * 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
|
1764 */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1765 {"SystemExit", &PyExc_SystemExit, &PyExc_BaseException, SystemExit__doc__, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1766 SystemExit_methods}, |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1767 {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, &PyExc_BaseException, |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1768 KeyboardInterrupt__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1769 {"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
|
1770 {"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
|
1771 EnvironmentError_methods}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1772 {"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
|
1773 {"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
|
1774 #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
|
1775 {"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
|
1776 WindowsError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1777 #endif /* MS_WINDOWS */ |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1778 #ifdef __VMS |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1779 {"VMSError", &PyExc_VMSError, &PyExc_OSError, |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1780 VMSError__doc__}, |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26318
diff
changeset
|
1781 #endif |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1782 {"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
|
1783 {"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
|
1784 {"NotImplementedError", &PyExc_NotImplementedError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1785 &PyExc_RuntimeError, NotImplementedError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1786 {"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
|
1787 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1788 UnboundLocalError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1789 {"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
|
1790 {"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
|
1791 SyntaxError_methods, SyntaxError__classinit__}, |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1792 {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1793 IndentationError__doc__}, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1794 {"TabError", &PyExc_TabError, &PyExc_IndentationError, |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13484
diff
changeset
|
1795 TabError__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1796 {"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
|
1797 {"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
|
1798 {"IndexError", &PyExc_IndexError, &PyExc_LookupError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1799 IndexError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1800 {"KeyError", &PyExc_KeyError, &PyExc_LookupError, |
|
25110
0401a0ead1eb
Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents:
25094
diff
changeset
|
1801 KeyError__doc__, KeyError_methods}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1802 {"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
|
1803 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1804 OverflowError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1805 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1806 ZeroDivisionError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1807 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1808 FloatingPointError__doc__}, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1809 {"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
|
1810 {"UnicodeError", &PyExc_UnicodeError, &PyExc_ValueError, UnicodeError__doc__}, |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
1811 #ifdef Py_USING_UNICODE |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1812 {"UnicodeEncodeError", &PyExc_UnicodeEncodeError, &PyExc_UnicodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1813 UnicodeEncodeError__doc__, UnicodeEncodeError_methods}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1814 {"UnicodeDecodeError", &PyExc_UnicodeDecodeError, &PyExc_UnicodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1815 UnicodeDecodeError__doc__, UnicodeDecodeError_methods}, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1816 {"UnicodeTranslateError", &PyExc_UnicodeTranslateError, &PyExc_UnicodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24818
diff
changeset
|
1817 UnicodeTranslateError__doc__, UnicodeTranslateError_methods}, |
|
26318
910fa739f4a4
Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents:
25325
diff
changeset
|
1818 #endif |
|
20279
8b3ea7335c1b
weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents:
19433
diff
changeset
|
1819 {"ReferenceError", &PyExc_ReferenceError, 0, ReferenceError__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1820 {"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
|
1821 {"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
|
1822 /* Warning categories */ |
|
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1823 {"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
|
1824 {"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
|
1825 {"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
|
1826 DeprecationWarning__doc__}, |
|
23564
3f242cdd0904
As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents:
22629
diff
changeset
|
1827 {"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning, |
|
3f242cdd0904
As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents:
22629
diff
changeset
|
1828 PendingDeprecationWarning__doc__}, |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1829 {"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__}, |
|
33256
6641d0542592
Stop producing or using OverflowWarning. PEP 237 thought this would
Tim Peters <tim.peters@gmail.com>
parents:
30683
diff
changeset
|
1830 /* OverflowWarning should be removed for Python 2.5 */ |
|
19433
5d81c6bff306
Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1831 {"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning, |
|
5d81c6bff306
Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
1832 OverflowWarning__doc__}, |
|
15590
1e756f93bf5d
Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents:
15318
diff
changeset
|
1833 {"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
|
1834 RuntimeWarning__doc__}, |
|
24818
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1835 {"FutureWarning", &PyExc_FutureWarning, &PyExc_Warning, |
|
31d2860089e6
Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents:
24420
diff
changeset
|
1836 FutureWarning__doc__}, |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1837 /* Sentinel */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1838 {NULL} |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1839 }; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1840 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1841 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1842 |
|
24420
36e2fd3f08f7
Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
1843 void |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1844 _PyExc_Init(void) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1845 { |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1846 char *modulename = "exceptions"; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35298
diff
changeset
|
1847 Py_ssize_t modnamesz = strlen(modulename); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1848 int i; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1849 PyObject *me, *mydict, *bltinmod, *bdict, *doc, *args; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1850 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1851 me = Py_InitModule(modulename, functions); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1852 if (me == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1853 goto err; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1854 mydict = PyModule_GetDict(me); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1855 if (mydict == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1856 goto err; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1857 bltinmod = PyImport_ImportModule("__builtin__"); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1858 if (bltinmod == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1859 goto err; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1860 bdict = PyModule_GetDict(bltinmod); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1861 if (bdict == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1862 goto err; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1863 doc = PyString_FromString(module__doc__); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1864 if (doc == NULL) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1865 goto err; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1866 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1867 i = 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
|
1868 Py_DECREF(doc); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1869 if (i < 0) { |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1870 err: |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1871 Py_FatalError("exceptions bootstrapping error."); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1872 return; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1873 } |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1874 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1875 /* This is the base class of all exceptions, so make it first. */ |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1876 if (make_BaseException(modulename) || |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1877 PyDict_SetItemString(mydict, "BaseException", PyExc_BaseException) || |
|
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1878 PyDict_SetItemString(bdict, "BaseException", PyExc_BaseException)) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1879 { |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36513
diff
changeset
|
1880 Py_FatalError("Base class `BaseException' could not be created."); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1881 } |
|
16164
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1882 |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1883 /* 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
|
1884 * 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
|
1885 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1886 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
|
1887 int status; |
|
13657
6a5314a6c2c2
Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1888 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
|
1889 PyObject *base; |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1890 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1891 (void)strcpy(cname, modulename); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1892 (void)strcat(cname, "."); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1893 (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
|
1894 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1895 if (exctable[i].base == 0) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1896 base = PyExc_StandardError; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1897 else |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1898 base = *exctable[i].base; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1899 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1900 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
|
1901 exctable[i].methods, |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1902 exctable[i].docstr); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1903 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1904 PyMem_DEL(cname); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1905 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1906 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1907 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
|
1908 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1909 if (exctable[i].classinit) { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1910 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
|
1911 if (status) |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1912 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
|
1913 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1914 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1915 /* 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
|
1916 * module. |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1917 */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1918 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
|
1919 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
|
1920 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1921 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
|
1922 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1923 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1924 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1925 /* Now we need to pre-allocate a MemoryError instance */ |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30152
diff
changeset
|
1926 args = PyTuple_New(0); |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1927 if (!args || |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1928 !(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
|
1929 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1930 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
|
1931 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1932 Py_DECREF(args); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1933 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1934 /* We're done with __builtin__ */ |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1935 Py_DECREF(bltinmod); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1936 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1937 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1938 |
|
24420
36e2fd3f08f7
Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
1939 void |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
1940 _PyExc_Fini(void) |
|
12771
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1941 { |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1942 int i; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1943 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1944 Py_XDECREF(PyExc_MemoryErrorInst); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1945 PyExc_MemoryErrorInst = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1946 |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1947 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
|
1948 /* 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
|
1949 * between the class and its methods. |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1950 */ |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1951 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
|
1952 PyDict_Clear(cdict); |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1953 Py_DECREF(cdict); |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1954 |
|
2208a03d05a3
Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents:
15590
diff
changeset
|
1955 /* 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
|
1956 Py_XDECREF(*exctable[i].exc); |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1957 *exctable[i].exc = NULL; |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1958 } |
|
52c6ac2d16a8
The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1959 } |
