annotate Python/exceptions.c @ 36758:3e19271efc46 legacy-trunk

Use %zd format characters for Py_ssize_t types.
author Thomas Wouters <thomas@python.org>
date Wed, 01 Mar 2006 05:38:39 +0000
parents 8e04de2480e4
children 25f8e6dde4a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1 /* This module provides the suite of standard class-based exceptions for
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
2 * Python's builtin module. This is a complete C implementation of what,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
3 * in Python 1.5.2, was contained in the exceptions.py module. The problem
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
4 * there was that if exceptions.py could not be imported for some reason,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
5 * the entire interpreter would abort.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
6 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
7 * By moving the exceptions into C and statically linking, we can guarantee
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
8 * that the standard exceptions will always be available.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
9 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
10 * history:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
11 * 98-08-19 fl created (for pyexe)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
12 * 00-02-08 fl updated for 1.5.2
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
13 * 26-May-2000 baw vetted for Python 1.6
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
14 * XXX
12771
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 * written by Fredrik Lundh
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
17 * 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
18 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
19 * 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
20 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
21
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
22 #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
23 #include "osdefs.h"
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
24
13565
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
25 /* 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
26 * 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
27 * compile-time literal concatenation.
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
28 */
22629
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
29
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
30 /* 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
31 * 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
32 */
7230e01c3c49 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex
Skip Montanaro <skip@pobox.com>
parents: 22121
diff changeset
33
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
34 PyDoc_STRVAR(module__doc__,
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
35 "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
36 \n\
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
37 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
38 built-in namespace. It is recommended that user-defined exceptions inherit \n\
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
39 from Exception.\n\
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
40 "
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
41
13565
e558eb228a46 Worm around MSVC6 error on single string literal > 2Kb.
Tim Peters <tim.peters@gmail.com>
parents: 13539
diff changeset
42 /* keep string pieces "small" */
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
43 /* XXX exception hierarchy from 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
44 );
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
45
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
46
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
47 /* 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
48 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
49 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
50 {
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
51 PyObject *module;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
52 int status = -1;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
53
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
54 if (!methods)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
55 return 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
56
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
57 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
58 if (!module)
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
59 return 0;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
60 while (methods->ml_name) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
61 /* 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
62 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
63 PyObject *meth;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
64
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
65 if (!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
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
68 /* 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
69 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
70 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
71 goto status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
72 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
73
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
74 /* 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
75 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
76 Py_DECREF(meth);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
77 Py_DECREF(func);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
78
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
79 /* 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
80 if (status)
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
81 goto status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
82
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
83 methods++;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
84 }
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
85 status = 0;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
86 status:
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
87 Py_DECREF(module);
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
88 return status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
89 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
90
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
91
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
92
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
93 /* 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
94 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
95 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
96 char *name, PyMethodDef *methods,
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
97 char *docstr)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
98 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
99 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
100 PyObject *str = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
101 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
102
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
103 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
104 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
105
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
106 /* 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
107 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
108 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
109
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
110 if (docstr) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
111 if (!(str = PyString_FromString(docstr)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
112 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
113 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
114 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
115 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
116
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
117 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
118 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
119
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
120 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
121 Py_DECREF(*klass);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
122 *klass = NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
123 goto finally;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
124 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
125
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
126 status = 0;
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 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
129 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
130 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
131 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
132 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
133
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
134
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
135 /* 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
136 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
137 get_self(PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
138 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
139 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
140 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
141 /* 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
142 if (PyExc_TypeError) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
143 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14068
diff changeset
144 "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
145 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
146 return NULL;
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 return self;
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
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
151
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
152
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
153 /* 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
154 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
155 * 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
156 * 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
157 * 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
158 * 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
159 *
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
160 * 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
161 * 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
162 * 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
163 * 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
164 * 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
165 * 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
166 * explicit bootstrap order.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
167 *
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
168 * 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
169 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
170
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
171 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
172
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
173 /*
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 attributes.
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 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
177 */
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
178 static int
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
179 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
180 {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
181 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
182 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
183
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
184 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
185 return 0;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
186
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
187 /* set args */
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
188 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
189 return 0;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
190
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
191 /* set message */
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
192 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
193 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
194 else
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
195 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
196 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
197 return 0;
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 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
200 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
201 return 0;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
202 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
203
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
204 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
205 return 1;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
206 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
207
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
208 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
209 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
210 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
211 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
212 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
213
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
214 /* 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
215 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
216 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
217 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
218
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
219 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
220 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
221 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
222 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
223
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
224 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
225 Py_RETURN_NONE;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
226 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
227
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
228
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
229 static PyObject *
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
230 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
231 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
232 PyObject *out;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
233
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
234 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
235 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
236
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
237 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
238 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
239 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
240
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
241 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
242 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
243 out = PyString_FromString("");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
244 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
245 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
246 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
247 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
248 if (tmp) {
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
249 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
250 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
251 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
252 else
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
253 out = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
254 break;
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
255 }
25320
14ad560f4a97 Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
Guido van Rossum <guido@python.org>
parents: 25110
diff changeset
256 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
257 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
258 /* Fall through */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
259 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
260 out = PyObject_Str(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
261 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
262 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
263
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
264 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
265 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
266 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
267
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
268 #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
269 static PyObject *
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
270 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
271 {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
272 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
273
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
274 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
275 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
276
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
277 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
278 if (!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 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
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 NULL;
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
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
287 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
288 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
289 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
290 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
291 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
292 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
293 if (!temp) {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
294 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
295 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
296 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
297 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
298 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
299 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
300 else {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
301 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
302 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
303 }
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 #endif /* Py_USING_UNICODE */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
306
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
307 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
308 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
309 {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
310 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
311 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
312 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
313 PyObject *repr;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
314
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
315 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
316 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
317
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
318 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
319 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
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 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
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 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
326 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
327
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
328 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
329 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
330 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
331 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
332 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
333 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
334 else {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
335 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
336 /*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
337
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
338 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
339 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
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 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
342 }*/
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 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
345 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
346 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
347 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
348
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
349 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
350
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
351 /*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
352 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
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 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
356 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
357 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
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 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
362 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
363 return NULL;*/
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
364 }
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 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
367 if (!repr) {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
368 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
369 return NULL;
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
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
372 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
373 return repr;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
374 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
375
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
376 static PyObject *
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
377 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
378 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
379 PyObject *out;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
380 PyObject *index;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
381
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
382 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
383 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
384
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
385 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
386 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
387 return NULL;
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 out = PyObject_GetItem(args, index);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
390 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
391 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
392 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
393
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
394
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
395 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
396 BaseException_methods[] = {
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
397 /* 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
398 {"__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
399 {"__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
400 {"__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
401 #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
402 {"__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
403 #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
404 {"__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
405 {NULL, NULL }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
406 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
407
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
408
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
409 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
410 make_BaseException(char *modulename)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
411 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
412 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
413 PyObject *str = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
414 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
415 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
416 PyObject *argstuple = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
417 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
418
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
419 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
420 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
421
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
422 /* 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
423 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
424 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
425
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
426 if (!(str = PyString_FromString(modulename)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
427 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
428 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
429 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
430 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
431
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
432 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
433 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
434 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
435 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
436
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
437 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
438 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
439
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
440 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
441 goto finally;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
442
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
443 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
444 goto finally;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
445
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
446 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
447 NULL)))
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
448 goto finally;
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 /* 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
451 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
452 /* 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
453 * happen during interpreter shutdown.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
454 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
455 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
456
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
457 status = 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
458
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
459 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
460 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
461 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
462 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
463 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
464 Py_XDECREF(argstuple);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
465 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
466 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
467
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
468
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
469
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
470 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
471
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
472 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
473 "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
474 "interpreter exiting.");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
475
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
476 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
477
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
478 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
479 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
480
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
481
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
482
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
483 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
484
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
485
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
486 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
487 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
488 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
489 PyObject *code;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
490 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
491
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
492 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
493 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
494
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
495 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
496 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
497
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
498 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
499 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
500 return NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
501 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
502
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
503 /* set code attribute */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
504 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
505 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
506 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
507 code = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
508 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
509 case 1:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
510 code = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
511 break;
25325
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
512 case -1:
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
513 PyErr_Clear();
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
514 /* Fall through */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
515 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
516 Py_INCREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
517 code = args;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
518 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
519 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
520
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
521 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
522 Py_DECREF(code);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
523 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
524 if (status < 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
525 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
526
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
527 Py_RETURN_NONE;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
528 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
529
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
530
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
531 static PyMethodDef SystemExit_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
532 { "__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
533 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
534 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
535
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
536
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
537
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
538 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
539
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
540 PyDoc_STRVAR(ImportError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
541 "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
542
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
543
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
544
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
545 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
546
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
547
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
548 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
549 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
550 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
551 PyObject *item0 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
552 PyObject *item1 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
553 PyObject *item2 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
554 PyObject *subslice = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
555 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
556
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
557 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
558 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
559
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
560 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
561 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
562
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
563 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
564 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
565 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
566 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
567
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
568 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
569 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
570 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
571 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
572 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
573 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
574
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
575 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
576 case 3:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
577 /* 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
578 * 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
579 * 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
580 * 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
581 *
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
582 * except IOError, (errno, strerror):
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
583 *
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
584 * 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
585 * 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
586 * when it was supplied.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
587 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
588 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
589 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
590 item2 = PySequence_GetItem(args, 2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
591 if (!item0 || !item1 || !item2)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
592 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
593
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
594 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
595 PyObject_SetAttrString(self, "strerror", item1) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
596 PyObject_SetAttrString(self, "filename", item2))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
597 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
598 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
599 }
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 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
602 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
603 goto finally;
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
604 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
605
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
606 case 2:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
607 /* 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
608 * argument is given.
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
609 */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
610 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
611 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
612 if (!item0 || !item1)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
613 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
614
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
615 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
616 PyObject_SetAttrString(self, "strerror", item1))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
617 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
618 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
619 }
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
620 break;
25325
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
621
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
622 case -1:
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
623 PyErr_Clear();
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
624 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
625 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
626
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
627 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
628 rtnval = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
629
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
630 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
631 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
632 Py_XDECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
633 Py_XDECREF(item1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
634 Py_XDECREF(item2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
635 Py_XDECREF(subslice);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
636 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
637 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
638
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
639
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
640 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
641 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
642 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
643 PyObject *originalself = self;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
644 PyObject *filename;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
645 PyObject *serrno;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
646 PyObject *strerror;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
647 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
648
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
649 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
650 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
651
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
652 filename = PyObject_GetAttrString(self, "filename");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
653 serrno = PyObject_GetAttrString(self, "errno");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
654 strerror = PyObject_GetAttrString(self, "strerror");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
655 if (!filename || !serrno || !strerror)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
656 goto finally;
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 (filename != Py_None) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
659 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
660 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
661 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
662
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
663 if (!fmt || !repr || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
664 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
665 Py_XDECREF(repr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
666 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
667 goto finally;
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
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
670 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
671 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
672 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
673
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
674 rtnval = PyString_Format(fmt, tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
675
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
676 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
677 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
678 /* 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
679 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
680 strerror = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
681 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
682 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
683 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
684 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
685
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
686 if (!fmt || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
687 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
688 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
689 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
690 }
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 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
693 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
694
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
695 rtnval = PyString_Format(fmt, tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
696
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
697 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
698 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
699 /* 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
700 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
701 strerror = NULL;
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 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
704 /* The original Python code said:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
705 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
706 * return StandardError.__str__(self)
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 * 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
709 * 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
710 */
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
711 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
712
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
713 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
714 Py_XDECREF(filename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
715 Py_XDECREF(serrno);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
716 Py_XDECREF(strerror);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
717 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
718 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
719
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
720
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
721 static
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
722 PyMethodDef EnvironmentError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
723 {"__init__", EnvironmentError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
724 {"__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
725 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
726 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
727
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
728
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
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
731 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
732
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
733 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
734
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
735 #ifdef MS_WINDOWS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
736 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
737 #endif /* MS_WINDOWS */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
738
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
739 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
740 static char
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
741 VMSError__doc__[] = "OpenVMS OS system call failed.";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
742 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
743
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
744 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
745
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
746 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
747
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
748 PyDoc_STRVAR(NotImplementedError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
749 "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
750
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
751 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
752
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
753 PyDoc_STRVAR(UnboundLocalError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
754 "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
755
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
756 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
757
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
758
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
759
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
760 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
761
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
762
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
763 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
764 SyntaxError__classinit__(PyObject *klass)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
765 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
766 int retval = 0;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
767 PyObject *emptystring = PyString_FromString("");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
768
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
769 /* Additional class-creation time initializations */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
770 if (!emptystring ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
771 PyObject_SetAttrString(klass, "msg", emptystring) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
772 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
773 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
774 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
775 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
776 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
777 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
778 retval = -1;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
779 }
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
780 Py_XDECREF(emptystring);
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
781 return retval;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
782 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
783
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
784
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
785 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
786 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
787 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
788 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
789 int lenargs;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
790
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
791 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
792 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
793
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
794 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
795 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
796
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
797 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
798 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
799 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
800 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
801
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
802 lenargs = PySequence_Size(args);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
803 if (lenargs >= 1) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
804 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
805 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
806
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
807 if (!item0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
808 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
809 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
810 Py_DECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
811 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
812 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
813 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
814 if (lenargs == 2) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
815 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
816 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
817 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
818 int status = 1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
819
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
820 if (!info)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
821 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
822
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
823 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
824 if (filename != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
825 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
826 if (lineno != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
827 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
828 if (offset != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
829 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
830 if (text != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
831 status =
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
832 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
833 || 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
834 || 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
835 || 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
836 Py_DECREF(text);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
837 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
838 Py_DECREF(offset);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
839 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
840 Py_DECREF(lineno);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
841 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
842 Py_DECREF(filename);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
843 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
844 Py_DECREF(info);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
845
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
846 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
847 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
848 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
849 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
850 rtnval = Py_None;
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 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
853 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
854 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
855 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
856
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
857
13996
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
858 /* 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
859 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
860 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
861 static char *
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
862 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
863 {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
864 char *cp = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
865 char *result = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
866
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
867 if (name == NULL)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
868 return "???";
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
869 while (*cp != '\0') {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
870 if (*cp == SEP)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
871 result = cp + 1;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
872 ++cp;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
873 }
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
874 return result;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
875 }
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
876
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
877
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
878 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
879 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
880 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
881 PyObject *msg;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
882 PyObject *str;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
883 PyObject *filename, *lineno, *result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
884
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
885 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
886 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
887
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
888 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
889 return NULL;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
890
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
891 str = PyObject_Str(msg);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
892 Py_DECREF(msg);
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
893 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
894
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
895 /* 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
896 lineno here */
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
897
25110
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
898 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
899 int have_filename = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
900 int have_lineno = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
901 char *buffer = NULL;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
902
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
903 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
904 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
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();
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
907
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
908 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
909 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
910 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
911 PyErr_Clear();
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
912
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
913 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
914 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
915 if (have_filename)
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
916 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
917
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
918 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
919 if (buffer != NULL) {
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
920 if (have_filename && have_lineno)
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, line %ld)",
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)),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
924 PyInt_AsLong(lineno));
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
925 else if (have_filename)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
926 PyOS_snprintf(buffer, bufsize, "%s (%s)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
927 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
928 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
929 else if (have_lineno)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
930 PyOS_snprintf(buffer, bufsize, "%s (line %ld)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
931 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
932 PyInt_AsLong(lineno));
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
933
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
934 result = PyString_FromString(buffer);
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
935 PyMem_FREE(buffer);
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
936
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
937 if (result == NULL)
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
938 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
939 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
940 Py_DECREF(str);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
941 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
942 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
943 Py_XDECREF(filename);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
944 Py_XDECREF(lineno);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
945 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
946 return result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
947 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
948
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
949
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
950 static PyMethodDef SyntaxError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
951 {"__init__", SyntaxError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
952 {"__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
953 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
954 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
955
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
956
25110
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
957 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
958 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
959 {
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
960 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
961 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
962
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
963 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
964 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
965
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
966 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
967 if (!argsattr)
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
968 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
969
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
970 /* 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
971 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
972 KeyError: ''
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
973 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
974 KeyError
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
975 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
976 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
977 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
978 */
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
979 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
980 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
981 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
982 }
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
983 else
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
984 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
985
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
986 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
987 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
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 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
991 {"__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
992 {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
993 };
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
994
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
995
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
996 #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
997 static
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
998 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
999 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1000 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
1001
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1002 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
1003 return -1;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1004 if (PyInt_Check(attr)) {
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1005 *value = PyInt_AS_LONG(attr);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1006 } else if (PyLong_Check(attr)) {
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1007 *value = (size_t)PyLong_AsLongLong(attr);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1008 if (*value == -1) {
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1009 Py_DECREF(attr);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1010 return -1;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1011 }
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1012 } else {
25093
ae1469e468a0 Limit the length of attribute names in exception messages
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1013 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
1014 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
1015 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
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 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
1018 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
1019 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1020
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1021
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1022 static
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1023 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
1024 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1025 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
1026 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
1027
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1028 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
1029 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
1030 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
1031 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
1032 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
1033 }
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1036 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
1037 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1038 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
1039
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1040 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
1041 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
1042 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
1043 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
1044 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
1045 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
1046 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1047 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1050
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1051 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1052 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
1053 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1054 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
1055 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
1056
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1057 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
1058 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
1059 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
1060 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
1061 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
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
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1066 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
1067 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1068 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
1069
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1070 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
1071 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
1072 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
1073 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
1074 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
1075 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
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 attr;
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 * 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
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 * 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
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_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
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 *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
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_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
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 *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
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_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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1100 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
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 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
1103 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1104
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1105 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
1106 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1107 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
1108 PyObject *object = PyUnicodeEncodeError_GetObject(exc);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1109 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
1110 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
1111 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
1112 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
1113 if (*start<0)
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1114 *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
1115 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
1116 *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
1117 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
1118 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
1119 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1120 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
1121 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1122
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1123
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1124 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
1125 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1126 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
1127 PyObject *object = PyUnicodeDecodeError_GetObject(exc);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1128 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
1129 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
1130 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
1131 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
1132 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
1133 *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
1134 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
1135 *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
1136 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
1137 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
1138 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1139 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
1140 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1143 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
1144 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1145 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
1146 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1149 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
1150 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1151 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
1152 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1155 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
1156 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1157 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
1158 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1161 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
1162 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1163 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
1164 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1165
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1166
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1167 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
1168 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1169 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
1170 PyObject *object = PyUnicodeEncodeError_GetObject(exc);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1171 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
1172 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
1173 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
1174 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
1175 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
1176 *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
1177 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
1178 *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
1179 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
1180 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
1181 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1182 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
1183 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1184
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1185
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1186 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
1187 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1188 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
1189 PyObject *object = PyUnicodeDecodeError_GetObject(exc);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1190 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
1191 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
1192 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
1193 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
1194 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
1195 *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
1196 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
1197 *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
1198 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
1199 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
1200 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1201 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
1202 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1205 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
1206 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1207 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
1208 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1211 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
1212 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1213 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
1214 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1217 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
1218 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1219 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
1220 }
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
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1223 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
1224 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1225 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
1226 }
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 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
1230 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1231 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
1232 }
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 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
1236 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1237 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
1238 }
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 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
1242 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1243 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
1244 }
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 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
1248 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1249 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
1250 }
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 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
1254 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1255 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
1256 }
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 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
1260 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1261 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1264
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1265 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
1266 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
1267 {
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 *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
1269 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
1270 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
1271 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
1272 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
1273 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
1274
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1275 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
1276 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
1277
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1278 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
1279 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
1280
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1281 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
1282 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
1283 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1284 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1285
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1286 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
1287 &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
1288 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
1289 &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
1290 &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
1291 &PyString_Type, &reason))
30152
0813b33610cc Fix refcount leak in the UnicodeError constructor:
Walter Dörwald <walter@livinglogic.de>
parents: 30138
diff changeset
1292 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
1293
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1294 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
1295 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
1296 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
1297 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
1298 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
1299 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
1300 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
1301 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
1302 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
1303 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
1304
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1305 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
1306 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
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 finally:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1309 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
1310 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
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
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 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
1315 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
1316 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1317 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
1318 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1319
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1320 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
1321 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
1322 {
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 *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
1324 PyObject *objectObj = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1325 Py_ssize_t start;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1326 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
1327 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
1328 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
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 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
1331
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1332 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
1333 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
1334
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1335 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
1336 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
1337
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1338 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
1339 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
1340
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1341 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
1342 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
1343
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1344 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
1345 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
1346
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1347 if (end==start+1) {
30137
df654861ccf6 Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents: 28049
diff changeset
1348 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
1349 char badchar_str[20];
30137
df654861ccf6 Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents: 28049
diff changeset
1350 if (badchar <= 0xff)
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1351 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
1352 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
1353 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
1354 else
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1355 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
1356 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1357 "'%.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
1358 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
1359 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
1360 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1361 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
1362 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1363 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1364 else {
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1365 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1366 "'%.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
1367 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
1368 start,
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1369 (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
1370 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
1371 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1372 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1373
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1374 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1375 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
1376 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
1377 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
1378 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
1379 }
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 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
1382 {"__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
1383 {"__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
1384 {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
1385 };
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1386
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1387
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1388 PyObject * PyUnicodeEncodeError_Create(
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1389 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
1390 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
1391 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1392 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
1393 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
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
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 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
1398 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
1399 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1400 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
1401 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1402
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1403 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
1404 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
1405 {
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 *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
1407 PyObject *objectObj = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1408 Py_ssize_t start;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1409 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
1410 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
1411 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
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 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
1414
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1415 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
1416 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
1417
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1418 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
1419 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
1420
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1421 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
1422 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
1423
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1424 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
1425 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
1426
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1427 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
1428 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
1429
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1430 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
1431 /* 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
1432 char byte[4];
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1433 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
1434 ((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
1435 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1436 "'%.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
1437 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
1438 byte,
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1439 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
1440 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
1441 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1442 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1443 else {
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1444 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1445 "'%.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
1446 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
1447 start,
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1448 (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
1449 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
1450 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1451 }
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1452
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1453
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1454 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1455 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
1456 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
1457 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
1458 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
1459 }
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 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
1462 {"__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
1463 {"__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
1464 {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
1465 };
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1466
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1467
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1468 PyObject * PyUnicodeDecodeError_Create(
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1469 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
1470 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
1471 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1472 assert(length < INT_MAX);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1473 assert(start < INT_MAX);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1474 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
1475 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
1476 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1479
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1480 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
1481 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
1482 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1483 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
1484 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
1485 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
1486 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
1487 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
1488
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1489 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
1490 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
1491
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1492 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
1493 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
1494
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1495 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
1496 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
1497 return NULL;
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1498 }
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1499
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1500 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
1501 &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
1502 &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
1503 &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
1504 &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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1507 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
1508 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
1509 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
1510 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
1511 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
1512 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
1513 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
1514 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
1515
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1516 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
1517 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
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 finally:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1520 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
1521 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1524
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1525 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
1526 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
1527 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1528 PyObject *objectObj = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1529 Py_ssize_t start;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1530 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
1531 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
1532 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
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 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
1535
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1536 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
1537 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
1538
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1539 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
1540 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
1541
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1542 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
1543 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
1544
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1545 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
1546 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
1547
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1548 if (end==start+1) {
30137
df654861ccf6 Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents: 28049
diff changeset
1549 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
1550 char badchar_str[20];
30137
df654861ccf6 Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents: 28049
diff changeset
1551 if (badchar <= 0xff)
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1552 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
1553 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
1554 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
1555 else
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1556 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
1557 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1558 "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
1559 badchar_str,
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1560 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
1561 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
1562 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1563 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1564 else {
36513
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1565 result = PyString_FromFormat(
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1566 "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
1567 start,
445c0aa811ca Use PyString_FromFormat for formatting error messages.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1568 (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
1569 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
1570 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1571 }
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 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1574 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
1575 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
1576 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
1577 }
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 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
1580 {"__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
1581 {"__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
1582 {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
1583 };
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1586 PyObject * PyUnicodeTranslateError_Create(
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1587 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
1588 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
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 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
1591 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
1592 }
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
1593 #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
1594
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1595
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1596
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1597 /* Exception doc strings */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1598
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1599 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
1600
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1601 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
1602
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1603 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
1604
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1605 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
1606
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1607 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
1608
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1609 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
1610
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1611 PyDoc_STRVAR(ZeroDivisionError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1612 "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
1613
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1614 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
1615
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1616 PyDoc_STRVAR(ValueError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1617 "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
1618
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1619 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
1620
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
1621 #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
1622 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
1623
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1624 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
1625
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1626 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
1627 #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
1628
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1629 PyDoc_STRVAR(SystemError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1630 "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
1631 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1632 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
1633 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
1634
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1635 PyDoc_STRVAR(ReferenceError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1636 "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
1637
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1638 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
1639
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1640 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
1641
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1642 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
1643
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1644 /* Warning category docstrings */
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(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
1647
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1648 PyDoc_STRVAR(UserWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1649 "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
1650
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1651 PyDoc_STRVAR(DeprecationWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1652 "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
1653
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1654 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
1655 "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
1656 "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
1657
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1658 PyDoc_STRVAR(SyntaxWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1659 "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
1660
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1661 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
1662 "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
1663
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1664 PyDoc_STRVAR(RuntimeWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1665 "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
1666
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1667 PyDoc_STRVAR(FutureWarning__doc__,
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1668 "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
1669 "in the future.");
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1670
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1671
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 /* module global functions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1674 static PyMethodDef functions[] = {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1675 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1676 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1677 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1678
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1679
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1680
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1681 /* Global C API defined exceptions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1682
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1683 PyObject *PyExc_BaseException;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1684 PyObject *PyExc_Exception;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1685 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
1686 PyObject *PyExc_GeneratorExit;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1687 PyObject *PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1688 PyObject *PyExc_ArithmeticError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1689 PyObject *PyExc_LookupError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1690
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1691 PyObject *PyExc_AssertionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1692 PyObject *PyExc_AttributeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1693 PyObject *PyExc_EOFError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1694 PyObject *PyExc_FloatingPointError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1695 PyObject *PyExc_EnvironmentError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1696 PyObject *PyExc_IOError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1697 PyObject *PyExc_OSError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1698 PyObject *PyExc_ImportError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1699 PyObject *PyExc_IndexError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1700 PyObject *PyExc_KeyError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1701 PyObject *PyExc_KeyboardInterrupt;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1702 PyObject *PyExc_MemoryError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1703 PyObject *PyExc_NameError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1704 PyObject *PyExc_OverflowError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1705 PyObject *PyExc_RuntimeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1706 PyObject *PyExc_NotImplementedError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1707 PyObject *PyExc_SyntaxError;
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1708 PyObject *PyExc_IndentationError;
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1709 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
1710 PyObject *PyExc_ReferenceError;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1711 PyObject *PyExc_SystemError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1712 PyObject *PyExc_SystemExit;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1713 PyObject *PyExc_UnboundLocalError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1714 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
1715 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
1716 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
1717 PyObject *PyExc_UnicodeTranslateError;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1718 PyObject *PyExc_TypeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1719 PyObject *PyExc_ValueError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1720 PyObject *PyExc_ZeroDivisionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1721 #ifdef MS_WINDOWS
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1722 PyObject *PyExc_WindowsError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1723 #endif
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1724 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1725 PyObject *PyExc_VMSError;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1726 #endif
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1727
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1728 /* 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
1729 * 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
1730 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1731 PyObject *PyExc_MemoryErrorInst;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1732
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1733 /* Predefined warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1734 PyObject *PyExc_Warning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1735 PyObject *PyExc_UserWarning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1736 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
1737 PyObject *PyExc_PendingDeprecationWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1738 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
1739 /* 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
1740 PyObject *PyExc_OverflowWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1741 PyObject *PyExc_RuntimeWarning;
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1742 PyObject *PyExc_FutureWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1743
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1744
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1745
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1746 /* 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
1747 static struct {
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1748 char *name;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1749 PyObject **exc;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1750 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
1751 char *docstr;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1752 PyMethodDef *methods;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1753 int (*classinit)(PyObject *);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1754 } exctable[] = {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1755 /*
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1756 * 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
1757 */
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1758 {"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
1759 {"Exception", &PyExc_Exception, &PyExc_BaseException, Exception__doc__},
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1760 {"StopIteration", &PyExc_StopIteration, &PyExc_Exception,
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1761 StopIteration__doc__},
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 33256
diff changeset
1762 {"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
1763 GeneratorExit__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1764 {"StandardError", &PyExc_StandardError, &PyExc_Exception,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1765 StandardError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1766 {"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
1767 /*
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1768 * 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
1769 */
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1770 {"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
1771 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
1772 {"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
1773 KeyboardInterrupt__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1774 {"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
1775 {"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
1776 EnvironmentError_methods},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1777 {"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
1778 {"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
1779 #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
1780 {"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
1781 WindowsError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1782 #endif /* MS_WINDOWS */
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1783 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1784 {"VMSError", &PyExc_VMSError, &PyExc_OSError,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1785 VMSError__doc__},
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1786 #endif
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1787 {"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
1788 {"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
1789 {"NotImplementedError", &PyExc_NotImplementedError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1790 &PyExc_RuntimeError, NotImplementedError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1791 {"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
1792 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1793 UnboundLocalError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1794 {"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
1795 {"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
1796 SyntaxError_methods, SyntaxError__classinit__},
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1797 {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1798 IndentationError__doc__},
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1799 {"TabError", &PyExc_TabError, &PyExc_IndentationError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1800 TabError__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1801 {"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
1802 {"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
1803 {"IndexError", &PyExc_IndexError, &PyExc_LookupError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1804 IndexError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1805 {"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
1806 KeyError__doc__, KeyError_methods},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1807 {"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
1808 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1809 OverflowError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1810 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1811 ZeroDivisionError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1812 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1813 FloatingPointError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1814 {"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
1815 {"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
1816 #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
1817 {"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
1818 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
1819 {"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
1820 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
1821 {"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
1822 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
1823 #endif
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
1824 {"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
1825 {"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
1826 {"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
1827 /* Warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1828 {"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
1829 {"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
1830 {"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
1831 DeprecationWarning__doc__},
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
1832 {"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
1833 PendingDeprecationWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1834 {"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
1835 /* 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
1836 {"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
1837 OverflowWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1838 {"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
1839 RuntimeWarning__doc__},
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1840 {"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
1841 FutureWarning__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1842 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1843 {NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1844 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1845
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1846
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1847
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1848 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1849 _PyExc_Init(void)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1850 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1851 char *modulename = "exceptions";
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35298
diff changeset
1852 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
1853 int i;
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1854 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
1855
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1856 me = Py_InitModule(modulename, functions);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1857 if (me == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1858 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1859 mydict = PyModule_GetDict(me);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1860 if (mydict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1861 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1862 bltinmod = PyImport_ImportModule("__builtin__");
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1863 if (bltinmod == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1864 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1865 bdict = PyModule_GetDict(bltinmod);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1866 if (bdict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1867 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1868 doc = PyString_FromString(module__doc__);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1869 if (doc == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1870 goto err;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1871
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1872 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
1873 Py_DECREF(doc);
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1874 if (i < 0) {
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1875 err:
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1876 Py_FatalError("exceptions bootstrapping error.");
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1877 return;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1878 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1879
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1880 /* 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
1881 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
1882 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
1883 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
1884 {
36751
8e04de2480e4 PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents: 36513
diff changeset
1885 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
1886 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1887
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1888 /* 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
1889 * 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
1890 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1891 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
1892 int status;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1893 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
1894 PyObject *base;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1895
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1896 (void)strcpy(cname, modulename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1897 (void)strcat(cname, ".");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1898 (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
1899
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1900 if (exctable[i].base == 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1901 base = PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1902 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1903 base = *exctable[i].base;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1904
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1905 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
1906 exctable[i].methods,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1907 exctable[i].docstr);
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 PyMem_DEL(cname);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1910
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("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
1913
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1914 if (exctable[i].classinit) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1915 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
1916 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1917 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
1918 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1919
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1920 /* 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
1921 * module.
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 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
1924 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
1925 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1926 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
1927 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1928 }
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 /* 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
1931 args = PyTuple_New(0);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1932 if (!args ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1933 !(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
1934 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1935 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
1936 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1937 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1938
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1939 /* We're done with __builtin__ */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1940 Py_DECREF(bltinmod);
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
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1943
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1944 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1945 _PyExc_Fini(void)
12771
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 int i;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1948
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1949 Py_XDECREF(PyExc_MemoryErrorInst);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1950 PyExc_MemoryErrorInst = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1951
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1952 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
1953 /* 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
1954 * between the class and its methods.
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1955 */
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1956 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
1957 PyDict_Clear(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1958 Py_DECREF(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1959
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1960 /* 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
1961 Py_XDECREF(*exctable[i].exc);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1962 *exctable[i].exc = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1963 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1964 }