annotate Python/exceptions.c @ 37473:20ffc2ca03e0 legacy-trunk

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