Mercurial > cpython-lru_cache-weakref
annotate Objects/exceptions.c @ 51330:ca423008fa4a legacy-trunk
#5144: document that PySys_SetArgv prepends the script directory (or the empty string) to sys.path.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 05 Feb 2009 10:37:07 +0000 |
| parents | e158c70511fe |
| children | 0415417cfd48 |
| rev | line source |
|---|---|
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1 /* |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
2 * New exceptions.c written in Iceland by Richard Jones and Georg Brandl. |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
3 * |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
4 * Thanks go to Tim Peters and Michael Hudson for debugging. |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
5 */ |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
6 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
7 #define PY_SSIZE_T_CLEAN |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
8 #include <Python.h> |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
9 #include "structmember.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
10 #include "osdefs.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
11 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
12 #define MAKE_IT_NONE(x) (x) = Py_None; Py_INCREF(Py_None); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
13 #define EXC_MODULE_NAME "exceptions." |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
14 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
15 /* NOTE: If the exception class hierarchy changes, don't forget to update |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
16 * Lib/test/exception_hierarchy.txt |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
17 */ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
18 |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
19 PyDoc_STRVAR(exceptions_doc, "Python's standard exception class hierarchy.\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
20 \n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
21 Exceptions found here are defined both in the exceptions module and the\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
22 built-in namespace. It is recommended that user-defined exceptions\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
23 inherit from Exception. See the documentation for the exception\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
24 inheritance hierarchy.\n\ |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
25 "); |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
26 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
27 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
28 * BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
29 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
30 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
31 BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
32 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
33 PyBaseExceptionObject *self; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
34 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
35 self = (PyBaseExceptionObject *)type->tp_alloc(type, 0); |
|
41435
46d0f4057705
Add some missing NULL checks which trigger crashes on low-memory conditions.
Georg Brandl <georg@python.org>
parents:
40908
diff
changeset
|
36 if (!self) |
|
46d0f4057705
Add some missing NULL checks which trigger crashes on low-memory conditions.
Georg Brandl <georg@python.org>
parents:
40908
diff
changeset
|
37 return NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
38 /* the dict is created on the fly in PyObject_GenericSetAttr */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
39 self->message = self->dict = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
40 |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
41 self->args = PyTuple_New(0); |
|
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
42 if (!self->args) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
43 Py_DECREF(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
44 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
45 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
46 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
47 self->message = PyString_FromString(""); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
48 if (!self->message) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
49 Py_DECREF(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
50 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
51 } |
|
42688
62eee79de923
Revert accidental checkins from last commit.
Georg Brandl <georg@python.org>
parents:
42687
diff
changeset
|
52 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
53 return (PyObject *)self; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
54 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
55 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
56 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
57 BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
58 { |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
59 if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) |
|
38510
13fedd0d0f26
Do the check for no keyword arguments in __init__ so that
Georg Brandl <georg@python.org>
parents:
38508
diff
changeset
|
60 return -1; |
|
13fedd0d0f26
Do the check for no keyword arguments in __init__ so that
Georg Brandl <georg@python.org>
parents:
38508
diff
changeset
|
61 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
62 Py_DECREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
63 self->args = args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
64 Py_INCREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
65 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
66 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
67 Py_CLEAR(self->message); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
68 self->message = PyTuple_GET_ITEM(self->args, 0); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
69 Py_INCREF(self->message); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
70 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
71 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
72 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
73 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
74 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
75 BaseException_clear(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
76 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
77 Py_CLEAR(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
78 Py_CLEAR(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
79 Py_CLEAR(self->message); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
80 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
81 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
82 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
83 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
84 BaseException_dealloc(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
85 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
86 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
87 BaseException_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
88 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
89 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
90 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
91 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
92 BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
93 { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
94 Py_VISIT(self->dict); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
95 Py_VISIT(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
96 Py_VISIT(self->message); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
97 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
98 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
99 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
100 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
101 BaseException_str(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
102 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
103 PyObject *out; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
104 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
105 switch (PyTuple_GET_SIZE(self->args)) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
106 case 0: |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
107 out = PyString_FromString(""); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
108 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
109 case 1: |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
110 out = PyObject_Str(PyTuple_GET_ITEM(self->args, 0)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
111 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
112 default: |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
113 out = PyObject_Str(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
114 break; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
115 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
116 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
117 return out; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
118 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
119 |
|
47914
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
120 #ifdef Py_USING_UNICODE |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
121 static PyObject * |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
122 BaseException_unicode(PyBaseExceptionObject *self) |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
123 { |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
124 PyObject *out; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
125 |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
126 switch (PyTuple_GET_SIZE(self->args)) { |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
127 case 0: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
128 out = PyUnicode_FromString(""); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
129 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
130 case 1: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
131 out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0)); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
132 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
133 default: |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
134 out = PyObject_Unicode(self->args); |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
135 break; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
136 } |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
137 |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
138 return out; |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
139 } |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
140 #endif |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
141 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
142 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
143 BaseException_repr(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
144 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
145 PyObject *repr_suffix; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
146 PyObject *repr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
147 char *name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
148 char *dot; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
149 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
150 repr_suffix = PyObject_Repr(self->args); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
151 if (!repr_suffix) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
152 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
153 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
154 name = (char *)Py_TYPE(self)->tp_name; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
155 dot = strrchr(name, '.'); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
156 if (dot != NULL) name = dot+1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
157 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
158 repr = PyString_FromString(name); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
159 if (!repr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
160 Py_DECREF(repr_suffix); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
161 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
162 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
163 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
164 PyString_ConcatAndDel(&repr, repr_suffix); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
165 return repr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
166 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
167 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
168 /* Pickling support */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
169 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
170 BaseException_reduce(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
171 { |
|
38505
4f8586946c8f
Restore exception pickle support. #1497319.
Georg Brandl <georg@python.org>
parents:
38476
diff
changeset
|
172 if (self->args && self->dict) |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
173 return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
174 else |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
175 return PyTuple_Pack(2, Py_TYPE(self), self->args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
176 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
177 |
|
38532
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
178 /* |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
179 * Needed for backward compatibility, since exceptions used to store |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
180 * all their attributes in the __dict__. Code is taken from cPickle's |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
181 * load_build function. |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
182 */ |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
183 static PyObject * |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
184 BaseException_setstate(PyObject *self, PyObject *state) |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
185 { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
186 PyObject *d_key, *d_value; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
187 Py_ssize_t i = 0; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
188 |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
189 if (state != Py_None) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
190 if (!PyDict_Check(state)) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
191 PyErr_SetString(PyExc_TypeError, "state is not a dictionary"); |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
192 return NULL; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
193 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
194 while (PyDict_Next(state, &i, &d_key, &d_value)) { |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
195 if (PyObject_SetAttr(self, d_key, d_value) < 0) |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
196 return NULL; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
197 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
198 } |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
199 Py_RETURN_NONE; |
|
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
200 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
201 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
202 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
203 static PyMethodDef BaseException_methods[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
204 {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS }, |
|
38532
db2d8aa9fe3d
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
Georg Brandl <georg@python.org>
parents:
38510
diff
changeset
|
205 {"__setstate__", (PyCFunction)BaseException_setstate, METH_O }, |
|
47914
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
206 #ifdef Py_USING_UNICODE |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
207 {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS }, |
|
1bc543944daa
Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
Nick Coghlan <ncoghlan@gmail.com>
parents:
47527
diff
changeset
|
208 #endif |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
209 {NULL, NULL, 0, NULL}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
210 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
211 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
212 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
213 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
214 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
215 BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
216 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
217 if (PyErr_WarnPy3k("__getitem__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
218 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
219 return NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
220 return PySequence_GetItem(self->args, index); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
221 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
222 |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
223 static PyObject * |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
224 BaseException_getslice(PyBaseExceptionObject *self, |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
225 Py_ssize_t start, Py_ssize_t stop) |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
226 { |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
227 if (PyErr_WarnPy3k("__getslice__ not supported for exception " |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
228 "classes in 3.x; use args attribute", 1) < 0) |
|
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46107
diff
changeset
|
229 return NULL; |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
230 return PySequence_GetSlice(self->args, start, stop); |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
231 } |
|
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
232 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
233 static PySequenceMethods BaseException_as_sequence = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
234 0, /* sq_length; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
235 0, /* sq_concat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
236 0, /* sq_repeat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
237 (ssizeargfunc)BaseException_getitem, /* sq_item; */ |
|
39863
4888d2d4d292
Allow exceptions to be directly sliced again
Brett Cannon <bcannon@gmail.com>
parents:
39818
diff
changeset
|
238 (ssizessizeargfunc)BaseException_getslice, /* sq_slice; */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
239 0, /* sq_ass_item; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
240 0, /* sq_ass_slice; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
241 0, /* sq_contains; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
242 0, /* sq_inplace_concat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
243 0 /* sq_inplace_repeat; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
244 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
245 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
246 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
247 BaseException_get_dict(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
248 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
249 if (self->dict == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
250 self->dict = PyDict_New(); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
251 if (!self->dict) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
252 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
253 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
254 Py_INCREF(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
255 return self->dict; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
256 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
257 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
258 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
259 BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
260 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
261 if (val == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
262 PyErr_SetString(PyExc_TypeError, "__dict__ may not be deleted"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
263 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
264 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
265 if (!PyDict_Check(val)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
266 PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
267 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
268 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
269 Py_CLEAR(self->dict); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
270 Py_INCREF(val); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
271 self->dict = val; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
272 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
273 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
274 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
275 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
276 BaseException_get_args(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
277 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
278 if (self->args == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
279 Py_INCREF(Py_None); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
280 return Py_None; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
281 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
282 Py_INCREF(self->args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
283 return self->args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
284 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
285 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
286 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
287 BaseException_set_args(PyBaseExceptionObject *self, PyObject *val) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
288 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
289 PyObject *seq; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
290 if (val == NULL) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
291 PyErr_SetString(PyExc_TypeError, "args may not be deleted"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
292 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
293 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
294 seq = PySequence_Tuple(val); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
295 if (!seq) return -1; |
|
38476
d3383063491f
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Georg Brandl <georg@python.org>
parents:
38469
diff
changeset
|
296 Py_CLEAR(self->args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
297 self->args = seq; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
298 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
299 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
300 |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
301 static PyObject * |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
302 BaseException_get_message(PyBaseExceptionObject *self) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
303 { |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
304 int ret; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
305 ret = PyErr_WarnEx(PyExc_DeprecationWarning, |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
306 "BaseException.message has been deprecated as " |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
307 "of Python 2.6", 1); |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
308 if (ret < 0) |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
309 return NULL; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
310 |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
311 Py_INCREF(self->message); |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
312 return self->message; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
313 } |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
314 |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
315 static int |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
316 BaseException_set_message(PyBaseExceptionObject *self, PyObject *val) |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
317 { |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
318 int ret; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
319 ret = PyErr_WarnEx(PyExc_DeprecationWarning, |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
320 "BaseException.message has been deprecated as " |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
321 "of Python 2.6", 1); |
|
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
322 if (ret < 0) |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
323 return -1; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
324 Py_INCREF(val); |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
325 Py_DECREF(self->message); |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
326 self->message = val; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
327 return 0; |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
328 } |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
329 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
330 static PyGetSetDef BaseException_getset[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
331 {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
332 {"args", (getter)BaseException_get_args, (setter)BaseException_set_args}, |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
333 {"message", (getter)BaseException_get_message, |
|
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
334 (setter)BaseException_set_message}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
335 {NULL}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
336 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
337 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
338 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
339 static PyTypeObject _PyExc_BaseException = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
340 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
341 0, /*ob_size*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
342 EXC_MODULE_NAME "BaseException", /*tp_name*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
343 sizeof(PyBaseExceptionObject), /*tp_basicsize*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
344 0, /*tp_itemsize*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
345 (destructor)BaseException_dealloc, /*tp_dealloc*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
346 0, /*tp_print*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
347 0, /*tp_getattr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
348 0, /*tp_setattr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
349 0, /* tp_compare; */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
350 (reprfunc)BaseException_repr, /*tp_repr*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
351 0, /*tp_as_number*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
352 &BaseException_as_sequence, /*tp_as_sequence*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
353 0, /*tp_as_mapping*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
354 0, /*tp_hash */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
355 0, /*tp_call*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
356 (reprfunc)BaseException_str, /*tp_str*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
357 PyObject_GenericGetAttr, /*tp_getattro*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
358 PyObject_GenericSetAttr, /*tp_setattro*/ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
359 0, /*tp_as_buffer*/ |
|
40908
d01bd37bf5ce
Variation of patch # 1624059 to speed up checking if an object is a subclass
Neal Norwitz <nnorwitz@gmail.com>
parents:
40209
diff
changeset
|
360 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | |
|
d01bd37bf5ce
Variation of patch # 1624059 to speed up checking if an object is a subclass
Neal Norwitz <nnorwitz@gmail.com>
parents:
40209
diff
changeset
|
361 Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
362 PyDoc_STR("Common base class for all exceptions"), /* tp_doc */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
363 (traverseproc)BaseException_traverse, /* tp_traverse */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
364 (inquiry)BaseException_clear, /* tp_clear */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
365 0, /* tp_richcompare */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
366 0, /* tp_weaklistoffset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
367 0, /* tp_iter */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
368 0, /* tp_iternext */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
369 BaseException_methods, /* tp_methods */ |
|
41617
615795d52b9f
Deprecate BaseException.message as per PEP 352.
Brett Cannon <bcannon@gmail.com>
parents:
41435
diff
changeset
|
370 0, /* tp_members */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
371 BaseException_getset, /* tp_getset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
372 0, /* tp_base */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
373 0, /* tp_dict */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
374 0, /* tp_descr_get */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
375 0, /* tp_descr_set */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
376 offsetof(PyBaseExceptionObject, dict), /* tp_dictoffset */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
377 (initproc)BaseException_init, /* tp_init */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
378 0, /* tp_alloc */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
379 BaseException_new, /* tp_new */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
380 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
381 /* the CPython API expects exceptions to be (PyObject *) - both a hold-over |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
382 from the previous implmentation and also allowing Python objects to be used |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
383 in the API */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
384 PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
385 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
386 /* note these macros omit the last semicolon so the macro invocation may |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
387 * include it and not look strange. |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
388 */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
389 #define SimpleExtendsException(EXCBASE, EXCNAME, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
390 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
391 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
392 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
393 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
394 sizeof(PyBaseExceptionObject), \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
395 0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
396 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
397 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
398 PyDoc_STR(EXCDOC), (traverseproc)BaseException_traverse, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
399 (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
400 0, 0, 0, offsetof(PyBaseExceptionObject, dict), \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
401 (initproc)BaseException_init, 0, BaseException_new,\ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
402 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
403 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
404 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
405 #define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
406 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
407 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
408 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
409 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
410 sizeof(Py ## EXCSTORE ## Object), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
411 0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
412 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
413 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
414 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
415 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
416 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
417 (initproc)EXCSTORE ## _init, 0, BaseException_new,\ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
418 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
419 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
420 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
421 #define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDEALLOC, EXCMETHODS, EXCMEMBERS, EXCSTR, EXCDOC) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
422 static PyTypeObject _PyExc_ ## EXCNAME = { \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
423 PyObject_HEAD_INIT(NULL) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
424 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
425 EXC_MODULE_NAME # EXCNAME, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
426 sizeof(Py ## EXCSTORE ## Object), 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
427 (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
428 (reprfunc)EXCSTR, 0, 0, 0, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
429 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
430 PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
431 (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
432 EXCMEMBERS, 0, &_ ## EXCBASE, \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
433 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
434 (initproc)EXCSTORE ## _init, 0, BaseException_new,\ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
435 }; \ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
436 PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
437 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
438 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
439 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
440 * Exception extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
441 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
442 SimpleExtendsException(PyExc_BaseException, Exception, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
443 "Common base class for all non-exit exceptions."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
444 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
445 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
446 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
447 * StandardError extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
448 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
449 SimpleExtendsException(PyExc_Exception, StandardError, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
450 "Base class for all standard Python exceptions that do not represent\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
451 "interpreter exiting."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
452 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
453 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
454 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
455 * TypeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
456 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
457 SimpleExtendsException(PyExc_StandardError, TypeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
458 "Inappropriate argument type."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
459 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
460 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
461 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
462 * StopIteration extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
463 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
464 SimpleExtendsException(PyExc_Exception, StopIteration, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
465 "Signal the end from iterator.next()."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
466 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
467 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
468 /* |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
469 * GeneratorExit extends BaseException |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
470 */ |
|
44127
aa6017a2e8f9
Patch #1537 from Chad Austin
Christian Heimes <christian@cheimes.de>
parents:
43276
diff
changeset
|
471 SimpleExtendsException(PyExc_BaseException, GeneratorExit, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
472 "Request that a generator exit."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
473 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
474 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
475 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
476 * SystemExit extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
477 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
478 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
479 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
480 SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
481 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
482 Py_ssize_t size = PyTuple_GET_SIZE(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
483 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
484 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
485 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
486 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
487 if (size == 0) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
488 return 0; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
489 Py_CLEAR(self->code); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
490 if (size == 1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
491 self->code = PyTuple_GET_ITEM(args, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
492 else if (size > 1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
493 self->code = args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
494 Py_INCREF(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
495 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
496 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
497 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
498 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
499 SystemExit_clear(PySystemExitObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
500 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
501 Py_CLEAR(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
502 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
503 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
504 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
505 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
506 SystemExit_dealloc(PySystemExitObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
507 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
508 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
509 SystemExit_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
510 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
511 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
512 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
513 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
514 SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
515 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
516 Py_VISIT(self->code); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
517 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
518 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
519 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
520 static PyMemberDef SystemExit_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
521 {"code", T_OBJECT, offsetof(PySystemExitObject, code), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
522 PyDoc_STR("exception code")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
523 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
524 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
525 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
526 ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
527 SystemExit_dealloc, 0, SystemExit_members, 0, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
528 "Request to exit from the interpreter."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
529 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
530 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
531 * KeyboardInterrupt extends BaseException |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
532 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
533 SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
534 "Program interrupted by user."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
535 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
536 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
537 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
538 * ImportError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
539 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
540 SimpleExtendsException(PyExc_StandardError, ImportError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
541 "Import can't find module, or can't find name in module."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
542 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
543 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
544 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
545 * EnvironmentError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
546 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
547 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
548 /* Where a function has a single filename, such as open() or some |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
549 * of the os module functions, PyErr_SetFromErrnoWithFilename() is |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
550 * called, giving a third argument which is the filename. But, so |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
551 * that old code using in-place unpacking doesn't break, e.g.: |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
552 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
553 * except IOError, (errno, strerror): |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
554 * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
555 * we hack args so that it only contains two items. This also |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
556 * means we need our own __str__() which prints out the filename |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
557 * when it was supplied. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
558 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
559 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
560 EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
561 PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
562 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
563 PyObject *myerrno = NULL, *strerror = NULL, *filename = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
564 PyObject *subslice = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
565 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
566 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
567 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
568 |
|
39924
e1ab4653ebc0
Bug #1566800: make sure that EnvironmentError can be called with any
Georg Brandl <georg@python.org>
parents:
39863
diff
changeset
|
569 if (PyTuple_GET_SIZE(args) <= 1 || PyTuple_GET_SIZE(args) > 3) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
570 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
571 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
572 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
573 if (!PyArg_UnpackTuple(args, "EnvironmentError", 2, 3, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
574 &myerrno, &strerror, &filename)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
575 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
576 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
577 Py_CLEAR(self->myerrno); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
578 self->myerrno = myerrno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
579 Py_INCREF(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
580 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
581 Py_CLEAR(self->strerror); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
582 self->strerror = strerror; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
583 Py_INCREF(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
584 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
585 /* self->filename will remain Py_None otherwise */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
586 if (filename != NULL) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
587 Py_CLEAR(self->filename); /* replacing */ |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
588 self->filename = filename; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
589 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
590 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
591 subslice = PyTuple_GetSlice(args, 0, 2); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
592 if (!subslice) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
593 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
594 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
595 Py_DECREF(self->args); /* replacing args */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
596 self->args = subslice; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
597 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
598 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
599 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
600 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
601 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
602 EnvironmentError_clear(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
603 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
604 Py_CLEAR(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
605 Py_CLEAR(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
606 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
607 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
608 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
609 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
610 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
611 EnvironmentError_dealloc(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
612 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
613 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
614 EnvironmentError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
615 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
616 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
617 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
618 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
619 EnvironmentError_traverse(PyEnvironmentErrorObject *self, visitproc visit, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
620 void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
621 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
622 Py_VISIT(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
623 Py_VISIT(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
624 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
625 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
626 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
627 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
628 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
629 EnvironmentError_str(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
630 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
631 PyObject *rtnval = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
632 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
633 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
634 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
635 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
636 PyObject *tuple; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
637 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
638 fmt = PyString_FromString("[Errno %s] %s: %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
639 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
640 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
641 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
642 repr = PyObject_Repr(self->filename); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
643 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
644 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
645 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
646 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
647 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
648 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
649 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
650 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
651 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
652 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
653 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
654 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
655 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
656 PyTuple_SET_ITEM(tuple, 0, self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
657 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
658 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
659 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
660 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
661 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
662 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
663 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
664 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
665 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
666 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
667 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
668 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
669 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
670 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
671 PyTuple_SET_ITEM(tuple, 2, repr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
672 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
673 rtnval = PyString_Format(fmt, tuple); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
674 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
675 Py_DECREF(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
676 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
677 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
678 else if (self->myerrno && self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
679 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
680 PyObject *tuple; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
681 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
682 fmt = PyString_FromString("[Errno %s] %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
683 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
684 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
685 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
686 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
687 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
688 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
689 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
690 } |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
691 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
692 if (self->myerrno) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
693 Py_INCREF(self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
694 PyTuple_SET_ITEM(tuple, 0, self->myerrno); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
695 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
696 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
697 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
698 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
699 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
700 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
701 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
702 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
703 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
704 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
705 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
706 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
707 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
708 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
709 rtnval = PyString_Format(fmt, tuple); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
710 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
711 Py_DECREF(fmt); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
712 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
713 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
714 else |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
715 rtnval = BaseException_str((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
716 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
717 return rtnval; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
718 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
719 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
720 static PyMemberDef EnvironmentError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
721 {"errno", T_OBJECT, offsetof(PyEnvironmentErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
722 PyDoc_STR("exception errno")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
723 {"strerror", T_OBJECT, offsetof(PyEnvironmentErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
724 PyDoc_STR("exception strerror")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
725 {"filename", T_OBJECT, offsetof(PyEnvironmentErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
726 PyDoc_STR("exception filename")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
727 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
728 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
729 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
730 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
731 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
732 EnvironmentError_reduce(PyEnvironmentErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
733 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
734 PyObject *args = self->args; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
735 PyObject *res = NULL, *tmp; |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
736 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
737 /* self->args is only the first two real arguments if there was a |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
738 * file name given to EnvironmentError. */ |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
739 if (PyTuple_GET_SIZE(args) == 2 && self->filename) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
740 args = PyTuple_New(3); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
741 if (!args) return NULL; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
742 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
743 tmp = PyTuple_GET_ITEM(self->args, 0); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
744 Py_INCREF(tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
745 PyTuple_SET_ITEM(args, 0, tmp); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
746 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
747 tmp = PyTuple_GET_ITEM(self->args, 1); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
748 Py_INCREF(tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
749 PyTuple_SET_ITEM(args, 1, tmp); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
750 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
751 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
752 PyTuple_SET_ITEM(args, 2, self->filename); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
753 } else |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
754 Py_INCREF(args); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
755 |
|
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
756 if (self->dict) |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
757 res = PyTuple_Pack(3, Py_TYPE(self), args, self->dict); |
|
38506
0aba63ff7f73
Add a test case for exception pickling. args is never NULL.
Georg Brandl <georg@python.org>
parents:
38505
diff
changeset
|
758 else |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
759 res = PyTuple_Pack(2, Py_TYPE(self), args); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
760 Py_DECREF(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
761 return res; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
762 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
763 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
764 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
765 static PyMethodDef EnvironmentError_methods[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
766 {"__reduce__", (PyCFunction)EnvironmentError_reduce, METH_NOARGS}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
767 {NULL} |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
768 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
769 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
770 ComplexExtendsException(PyExc_StandardError, EnvironmentError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
771 EnvironmentError, EnvironmentError_dealloc, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
772 EnvironmentError_methods, EnvironmentError_members, |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
773 EnvironmentError_str, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
774 "Base class for I/O related errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
775 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
776 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
777 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
778 * IOError extends EnvironmentError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
779 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
780 MiddlingExtendsException(PyExc_EnvironmentError, IOError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
781 EnvironmentError, "I/O operation failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
782 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
783 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
784 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
785 * OSError extends EnvironmentError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
786 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
787 MiddlingExtendsException(PyExc_EnvironmentError, OSError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
788 EnvironmentError, "OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
789 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
790 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
791 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
792 * WindowsError extends OSError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
793 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
794 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
795 #include "errmap.h" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
796 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
797 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
798 WindowsError_clear(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
799 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
800 Py_CLEAR(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
801 Py_CLEAR(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
802 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
803 Py_CLEAR(self->winerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
804 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
805 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
806 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
807 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
808 WindowsError_dealloc(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
809 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
810 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
811 WindowsError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
812 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
813 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
814 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
815 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
816 WindowsError_traverse(PyWindowsErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
817 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
818 Py_VISIT(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
819 Py_VISIT(self->strerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
820 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
821 Py_VISIT(self->winerror); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
822 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
823 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
824 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
825 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
826 WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
827 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
828 PyObject *o_errcode = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
829 long errcode; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
830 long posix_errno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
831 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
832 if (EnvironmentError_init((PyEnvironmentErrorObject *)self, args, kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
833 == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
834 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
835 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
836 if (self->myerrno == NULL) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
837 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
838 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
839 /* Set errno to the POSIX errno, and winerror to the Win32 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
840 error code. */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
841 errcode = PyInt_AsLong(self->myerrno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
842 if (errcode == -1 && PyErr_Occurred()) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
843 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
844 posix_errno = winerror_to_errno(errcode); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
845 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
846 Py_CLEAR(self->winerror); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
847 self->winerror = self->myerrno; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
848 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
849 o_errcode = PyInt_FromLong(posix_errno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
850 if (!o_errcode) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
851 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
852 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
853 self->myerrno = o_errcode; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
854 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
855 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
856 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
857 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
858 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
859 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
860 WindowsError_str(PyWindowsErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
861 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
862 PyObject *rtnval = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
863 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
864 if (self->filename) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
865 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
866 PyObject *repr; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
867 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
868 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
869 fmt = PyString_FromString("[Error %s] %s: %s"); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
870 if (!fmt) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
871 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
872 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
873 repr = PyObject_Repr(self->filename); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
874 if (!repr) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
875 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
876 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
877 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
878 tuple = PyTuple_New(3); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
879 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
880 Py_DECREF(repr); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
881 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
882 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
883 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
884 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
885 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
886 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
887 PyTuple_SET_ITEM(tuple, 0, self->winerror); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
888 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
889 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
890 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
891 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
892 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
893 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
894 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
895 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
896 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
897 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
898 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
899 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
900 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
901 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
902 PyTuple_SET_ITEM(tuple, 2, repr); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
903 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
904 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
905 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
906 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
907 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
908 } |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
909 else if (self->winerror && self->strerror) { |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
910 PyObject *fmt; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
911 PyObject *tuple; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
912 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
913 fmt = PyString_FromString("[Error %s] %s"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
914 if (!fmt) |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
915 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
916 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
917 tuple = PyTuple_New(2); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
918 if (!tuple) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
919 Py_DECREF(fmt); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
920 return NULL; |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
921 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
922 |
|
40209
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
923 if (self->winerror) { |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
924 Py_INCREF(self->winerror); |
|
988d95ff1fdb
WindowsError.str should display the windows error code,
Thomas Heller <theller@ctypes.org>
parents:
39924
diff
changeset
|
925 PyTuple_SET_ITEM(tuple, 0, self->winerror); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
926 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
927 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
928 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
929 PyTuple_SET_ITEM(tuple, 0, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
930 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
931 if (self->strerror) { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
932 Py_INCREF(self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
933 PyTuple_SET_ITEM(tuple, 1, self->strerror); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
934 } |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
935 else { |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
936 Py_INCREF(Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
937 PyTuple_SET_ITEM(tuple, 1, Py_None); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
938 } |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
939 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
940 rtnval = PyString_Format(fmt, tuple); |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
941 |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
942 Py_DECREF(fmt); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
943 Py_DECREF(tuple); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
944 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
945 else |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
946 rtnval = EnvironmentError_str((PyEnvironmentErrorObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
947 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
948 return rtnval; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
949 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
950 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
951 static PyMemberDef WindowsError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
952 {"errno", T_OBJECT, offsetof(PyWindowsErrorObject, myerrno), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
953 PyDoc_STR("POSIX exception code")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
954 {"strerror", T_OBJECT, offsetof(PyWindowsErrorObject, strerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
955 PyDoc_STR("exception strerror")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
956 {"filename", T_OBJECT, offsetof(PyWindowsErrorObject, filename), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
957 PyDoc_STR("exception filename")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
958 {"winerror", T_OBJECT, offsetof(PyWindowsErrorObject, winerror), 0, |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
959 PyDoc_STR("Win32 exception code")}, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
960 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
961 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
962 |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
963 ComplexExtendsException(PyExc_OSError, WindowsError, WindowsError, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
964 WindowsError_dealloc, 0, WindowsError_members, |
|
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
965 WindowsError_str, "MS-Windows OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
966 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
967 #endif /* MS_WINDOWS */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
968 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
969 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
970 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
971 * VMSError extends OSError (I think) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
972 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
973 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
974 MiddlingExtendsException(PyExc_OSError, VMSError, EnvironmentError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
975 "OpenVMS OS system call failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
976 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
977 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
978 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
979 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
980 * EOFError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
981 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
982 SimpleExtendsException(PyExc_StandardError, EOFError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
983 "Read beyond end of file."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
984 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
985 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
986 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
987 * RuntimeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
988 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
989 SimpleExtendsException(PyExc_StandardError, RuntimeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
990 "Unspecified run-time error."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
991 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
992 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
993 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
994 * NotImplementedError extends RuntimeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
995 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
996 SimpleExtendsException(PyExc_RuntimeError, NotImplementedError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
997 "Method or function hasn't been implemented yet."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
998 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
999 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1000 * NameError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1001 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1002 SimpleExtendsException(PyExc_StandardError, NameError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1003 "Name not found globally."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1004 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1005 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1006 * UnboundLocalError extends NameError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1007 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1008 SimpleExtendsException(PyExc_NameError, UnboundLocalError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1009 "Local name referenced but not bound to a value."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1010 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1011 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1012 * AttributeError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1013 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1014 SimpleExtendsException(PyExc_StandardError, AttributeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1015 "Attribute not found."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1016 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1017 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1018 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1019 * SyntaxError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1020 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1021 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1022 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1023 SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1024 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1025 PyObject *info = NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1026 Py_ssize_t lenargs = PyTuple_GET_SIZE(args); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1027 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1028 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1029 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1030 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1031 if (lenargs >= 1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1032 Py_CLEAR(self->msg); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1033 self->msg = PyTuple_GET_ITEM(args, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1034 Py_INCREF(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1035 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1036 if (lenargs == 2) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1037 info = PyTuple_GET_ITEM(args, 1); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1038 info = PySequence_Tuple(info); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1039 if (!info) return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1040 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1041 if (PyTuple_GET_SIZE(info) != 4) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1042 /* not a very good error message, but it's what Python 2.4 gives */ |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1043 PyErr_SetString(PyExc_IndexError, "tuple index out of range"); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1044 Py_DECREF(info); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1045 return -1; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1046 } |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1047 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1048 Py_CLEAR(self->filename); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1049 self->filename = PyTuple_GET_ITEM(info, 0); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1050 Py_INCREF(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1051 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1052 Py_CLEAR(self->lineno); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1053 self->lineno = PyTuple_GET_ITEM(info, 1); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1054 Py_INCREF(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1055 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1056 Py_CLEAR(self->offset); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1057 self->offset = PyTuple_GET_ITEM(info, 2); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1058 Py_INCREF(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1059 |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1060 Py_CLEAR(self->text); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1061 self->text = PyTuple_GET_ITEM(info, 3); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1062 Py_INCREF(self->text); |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1063 |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1064 Py_DECREF(info); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1065 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1066 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1067 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1068 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1069 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1070 SyntaxError_clear(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1071 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1072 Py_CLEAR(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1073 Py_CLEAR(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1074 Py_CLEAR(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1075 Py_CLEAR(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1076 Py_CLEAR(self->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1077 Py_CLEAR(self->print_file_and_line); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1078 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1079 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1080 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1081 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1082 SyntaxError_dealloc(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1083 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1084 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1085 SyntaxError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
1086 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1087 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1088 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1089 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1090 SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1091 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1092 Py_VISIT(self->msg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1093 Py_VISIT(self->filename); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1094 Py_VISIT(self->lineno); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1095 Py_VISIT(self->offset); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1096 Py_VISIT(self->text); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1097 Py_VISIT(self->print_file_and_line); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1098 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1099 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1100 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1101 /* This is called "my_basename" instead of just "basename" to avoid name |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1102 conflicts with glibc; basename is already prototyped if _GNU_SOURCE is |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1103 defined, and Python does define that. */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1104 static char * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1105 my_basename(char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1106 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1107 char *cp = name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1108 char *result = name; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1109 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1110 if (name == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1111 return "???"; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1112 while (*cp != '\0') { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1113 if (*cp == SEP) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1114 result = cp + 1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1115 ++cp; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1116 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1117 return result; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1118 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1119 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1120 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1121 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1122 SyntaxError_str(PySyntaxErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1123 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1124 PyObject *str; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1125 PyObject *result; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1126 int have_filename = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1127 int have_lineno = 0; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1128 char *buffer = NULL; |
|
38469
95fb2cd1d3ba
Make last patch valid C89 so Windows compilers can deal with it.
Thomas Wouters <thomas@python.org>
parents:
38468
diff
changeset
|
1129 Py_ssize_t bufsize; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1130 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1131 if (self->msg) |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1132 str = PyObject_Str(self->msg); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1133 else |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1134 str = PyObject_Str(Py_None); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1135 if (!str) return NULL; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1136 /* Don't fiddle with non-string return (shouldn't happen anyway) */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1137 if (!PyString_Check(str)) return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1138 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1139 /* XXX -- do all the additional formatting with filename and |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1140 lineno here */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1141 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1142 have_filename = (self->filename != NULL) && |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1143 PyString_Check(self->filename); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1144 have_lineno = (self->lineno != NULL) && PyInt_Check(self->lineno); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1145 |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1146 if (!have_filename && !have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1147 return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1148 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1149 bufsize = PyString_GET_SIZE(str) + 64; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1150 if (have_filename) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1151 bufsize += PyString_GET_SIZE(self->filename); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1152 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1153 buffer = PyMem_MALLOC(bufsize); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1154 if (buffer == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1155 return str; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1156 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1157 if (have_filename && have_lineno) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1158 PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1159 PyString_AS_STRING(str), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1160 my_basename(PyString_AS_STRING(self->filename)), |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1161 PyInt_AsLong(self->lineno)); |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1162 else if (have_filename) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1163 PyOS_snprintf(buffer, bufsize, "%s (%s)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1164 PyString_AS_STRING(str), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1165 my_basename(PyString_AS_STRING(self->filename))); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1166 else /* only have_lineno */ |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1167 PyOS_snprintf(buffer, bufsize, "%s (line %ld)", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1168 PyString_AS_STRING(str), |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1169 PyInt_AsLong(self->lineno)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1170 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1171 result = PyString_FromString(buffer); |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1172 PyMem_FREE(buffer); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1173 |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1174 if (result == NULL) |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1175 result = str; |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1176 else |
|
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1177 Py_DECREF(str); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1178 return result; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1179 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1180 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1181 static PyMemberDef SyntaxError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1182 {"msg", T_OBJECT, offsetof(PySyntaxErrorObject, msg), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1183 PyDoc_STR("exception msg")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1184 {"filename", T_OBJECT, offsetof(PySyntaxErrorObject, filename), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1185 PyDoc_STR("exception filename")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1186 {"lineno", T_OBJECT, offsetof(PySyntaxErrorObject, lineno), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1187 PyDoc_STR("exception lineno")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1188 {"offset", T_OBJECT, offsetof(PySyntaxErrorObject, offset), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1189 PyDoc_STR("exception offset")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1190 {"text", T_OBJECT, offsetof(PySyntaxErrorObject, text), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1191 PyDoc_STR("exception text")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1192 {"print_file_and_line", T_OBJECT, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1193 offsetof(PySyntaxErrorObject, print_file_and_line), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1194 PyDoc_STR("exception print_file_and_line")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1195 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1196 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1197 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1198 ComplexExtendsException(PyExc_StandardError, SyntaxError, SyntaxError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1199 SyntaxError_dealloc, 0, SyntaxError_members, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1200 SyntaxError_str, "Invalid syntax."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1201 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1202 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1203 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1204 * IndentationError extends SyntaxError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1205 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1206 MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1207 "Improper indentation."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1208 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1209 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1210 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1211 * TabError extends IndentationError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1212 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1213 MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1214 "Improper mixture of spaces and tabs."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1215 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1216 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1217 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1218 * LookupError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1219 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1220 SimpleExtendsException(PyExc_StandardError, LookupError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1221 "Base class for lookup errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1222 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1223 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1224 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1225 * IndexError extends LookupError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1226 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1227 SimpleExtendsException(PyExc_LookupError, IndexError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1228 "Sequence index out of range."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1229 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1230 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1231 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1232 * KeyError extends LookupError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1233 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1234 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1235 KeyError_str(PyBaseExceptionObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1236 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1237 /* If args is a tuple of exactly one item, apply repr to args[0]. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1238 This is done so that e.g. the exception raised by {}[''] prints |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1239 KeyError: '' |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1240 rather than the confusing |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1241 KeyError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1242 alone. The downside is that if KeyError is raised with an explanatory |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1243 string, that string will be displayed in quotes. Too bad. |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1244 If args is anything else, use the default BaseException__str__(). |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1245 */ |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1246 if (PyTuple_GET_SIZE(self->args) == 1) { |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1247 return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0)); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1248 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1249 return BaseException_str(self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1250 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1251 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1252 ComplexExtendsException(PyExc_LookupError, KeyError, BaseException, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1253 0, 0, 0, KeyError_str, "Mapping key not found."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1254 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1255 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1256 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1257 * ValueError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1258 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1259 SimpleExtendsException(PyExc_StandardError, ValueError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1260 "Inappropriate argument value (of correct type)."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1261 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1262 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1263 * UnicodeError extends ValueError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1264 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1265 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1266 SimpleExtendsException(PyExc_ValueError, UnicodeError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1267 "Unicode related error."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1268 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1269 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1270 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1271 get_string(PyObject *attr, const char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1272 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1273 if (!attr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1274 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1275 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1276 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1277 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1278 if (!PyString_Check(attr)) { |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1279 PyErr_Format(PyExc_TypeError, "%.200s attribute must be str", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1280 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1281 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1282 Py_INCREF(attr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1283 return attr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1284 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1285 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1286 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1287 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1288 set_string(PyObject **attr, const char *value) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1289 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1290 PyObject *obj = PyString_FromString(value); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1291 if (!obj) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1292 return -1; |
|
38467
593accdde00e
Fix refleaks in UnicodeError get and set methods.
Georg Brandl <georg@python.org>
parents:
38461
diff
changeset
|
1293 Py_CLEAR(*attr); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1294 *attr = obj; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1295 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1296 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1297 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1298 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1299 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1300 get_unicode(PyObject *attr, const char *name) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1301 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1302 if (!attr) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1303 PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1304 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1305 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1306 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1307 if (!PyUnicode_Check(attr)) { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1308 PyErr_Format(PyExc_TypeError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1309 "%.200s attribute must be unicode", name); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1310 return NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1311 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1312 Py_INCREF(attr); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1313 return attr; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1314 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1315 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1316 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1317 PyUnicodeEncodeError_GetEncoding(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1318 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1319 return get_string(((PyUnicodeErrorObject *)exc)->encoding, "encoding"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1320 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1321 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1322 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1323 PyUnicodeDecodeError_GetEncoding(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1324 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1325 return get_string(((PyUnicodeErrorObject *)exc)->encoding, "encoding"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1326 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1327 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1328 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1329 PyUnicodeEncodeError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1330 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1331 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1332 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1333 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1334 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1335 PyUnicodeDecodeError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1336 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1337 return get_string(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1338 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1339 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1340 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1341 PyUnicodeTranslateError_GetObject(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1342 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1343 return get_unicode(((PyUnicodeErrorObject *)exc)->object, "object"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1344 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1345 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1346 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1347 PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1348 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1349 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1350 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1351 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1352 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1353 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1354 *start = ((PyUnicodeErrorObject *)exc)->start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1355 size = PyUnicode_GET_SIZE(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1356 if (*start<0) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1357 *start = 0; /*XXX check for values <0*/ |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1358 if (*start>=size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1359 *start = size-1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1360 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1361 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1362 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1363 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1364 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1365 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1366 PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1367 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1368 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1369 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1370 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1371 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1372 return -1; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1373 size = PyString_GET_SIZE(obj); |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1374 *start = ((PyUnicodeErrorObject *)exc)->start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1375 if (*start<0) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1376 *start = 0; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1377 if (*start>=size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1378 *start = size-1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1379 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1380 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1381 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1382 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1383 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1384 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1385 PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1386 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1387 return PyUnicodeEncodeError_GetStart(exc, start); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1388 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1389 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1390 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1391 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1392 PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1393 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1394 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1395 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1396 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1397 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1398 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1399 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1400 PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1401 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1402 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1403 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1404 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1405 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1406 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1407 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1408 PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1409 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1410 ((PyUnicodeErrorObject *)exc)->start = start; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1411 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1412 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1413 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1414 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1415 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1416 PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1417 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1418 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1419 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1420 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1421 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1422 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1423 *end = ((PyUnicodeErrorObject *)exc)->end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1424 size = PyUnicode_GET_SIZE(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1425 if (*end<1) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1426 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1427 if (*end>size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1428 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1429 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1430 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1431 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1432 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1433 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1434 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1435 PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1436 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1437 Py_ssize_t size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1438 PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1439 "object"); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1440 if (!obj) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1441 return -1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1442 *end = ((PyUnicodeErrorObject *)exc)->end; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1443 size = PyString_GET_SIZE(obj); |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1444 if (*end<1) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1445 *end = 1; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1446 if (*end>size) |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1447 *end = size; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1448 Py_DECREF(obj); |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1449 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1450 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1451 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1452 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1453 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1454 PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1455 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1456 return PyUnicodeEncodeError_GetEnd(exc, start); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1457 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1458 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1459 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1460 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1461 PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1462 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1463 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1464 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1465 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1466 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1467 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1468 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1469 PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1470 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1471 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1472 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1473 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1474 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1475 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1476 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1477 PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1478 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1479 ((PyUnicodeErrorObject *)exc)->end = end; |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1480 return 0; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1481 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1482 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1483 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1484 PyUnicodeEncodeError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1485 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1486 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1487 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1488 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1489 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1490 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1491 PyUnicodeDecodeError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1492 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1493 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1494 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1495 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1496 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1497 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1498 PyUnicodeTranslateError_GetReason(PyObject *exc) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1499 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1500 return get_string(((PyUnicodeErrorObject *)exc)->reason, "reason"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1501 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1502 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1503 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1504 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1505 PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1506 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1507 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1508 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1509 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1510 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1511 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1512 PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1513 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1514 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1515 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1516 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1517 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1518 int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1519 PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1520 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1521 return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1522 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1523 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1524 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1525 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1526 UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1527 PyTypeObject *objecttype) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1528 { |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1529 Py_CLEAR(self->encoding); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1530 Py_CLEAR(self->object); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1531 Py_CLEAR(self->reason); |
|
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1532 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1533 if (!PyArg_ParseTuple(args, "O!O!nnO!", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1534 &PyString_Type, &self->encoding, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1535 objecttype, &self->object, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1536 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1537 &self->end, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1538 &PyString_Type, &self->reason)) { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1539 self->encoding = self->object = self->reason = NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1540 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1541 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1542 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1543 Py_INCREF(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1544 Py_INCREF(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1545 Py_INCREF(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1546 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1547 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1548 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1549 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1550 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1551 UnicodeError_clear(PyUnicodeErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1552 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1553 Py_CLEAR(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1554 Py_CLEAR(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1555 Py_CLEAR(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1556 return BaseException_clear((PyBaseExceptionObject *)self); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1557 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1558 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1559 static void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1560 UnicodeError_dealloc(PyUnicodeErrorObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1561 { |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1562 _PyObject_GC_UNTRACK(self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1563 UnicodeError_clear(self); |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
44127
diff
changeset
|
1564 Py_TYPE(self)->tp_free((PyObject *)self); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1565 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1566 |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1567 static int |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1568 UnicodeError_traverse(PyUnicodeErrorObject *self, visitproc visit, void *arg) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1569 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1570 Py_VISIT(self->encoding); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1571 Py_VISIT(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1572 Py_VISIT(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1573 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1574 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1575 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1576 static PyMemberDef UnicodeError_members[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1577 {"encoding", T_OBJECT, offsetof(PyUnicodeErrorObject, encoding), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1578 PyDoc_STR("exception encoding")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1579 {"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1580 PyDoc_STR("exception object")}, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1581 {"start", T_PYSSIZET, offsetof(PyUnicodeErrorObject, start), 0, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1582 PyDoc_STR("exception start")}, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1583 {"end", T_PYSSIZET, offsetof(PyUnicodeErrorObject, end), 0, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1584 PyDoc_STR("exception end")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1585 {"reason", T_OBJECT, offsetof(PyUnicodeErrorObject, reason), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1586 PyDoc_STR("exception reason")}, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1587 {NULL} /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1588 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1589 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1590 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1591 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1592 * UnicodeEncodeError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1593 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1594 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1595 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1596 UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1597 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1598 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1599 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1600 return UnicodeError_init((PyUnicodeErrorObject *)self, args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1601 kwds, &PyUnicode_Type); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1602 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1603 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1604 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1605 UnicodeEncodeError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1606 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1607 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1608 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1609 if (uself->end==uself->start+1) { |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1610 int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start]; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1611 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1612 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1613 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1614 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1615 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1616 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1617 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1618 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1619 "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1620 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1621 badchar_str, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1622 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1623 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1624 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1625 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1626 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1627 "'%.400s' codec can't encode characters in position %zd-%zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1628 PyString_AS_STRING(uself->encoding), |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1629 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1630 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1631 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1632 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1633 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1634 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1635 static PyTypeObject _PyExc_UnicodeEncodeError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1636 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1637 0, |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1638 EXC_MODULE_NAME "UnicodeEncodeError", |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1639 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1640 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1641 (reprfunc)UnicodeEncodeError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1642 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
38468
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1643 PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse, |
|
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1644 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1645 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1646 (initproc)UnicodeEncodeError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1647 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1648 PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1649 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1650 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1651 PyUnicodeEncodeError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1652 const char *encoding, const Py_UNICODE *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1653 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1654 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1655 return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1656 encoding, object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1657 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1658 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1659 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1660 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1661 * UnicodeDecodeError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1662 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1663 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1664 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1665 UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1666 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1667 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1668 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1669 return UnicodeError_init((PyUnicodeErrorObject *)self, args, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1670 kwds, &PyString_Type); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1671 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1672 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1673 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1674 UnicodeDecodeError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1675 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1676 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1677 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1678 if (uself->end==uself->start+1) { |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1679 /* FromFormat does not support %02x, so format that separately */ |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1680 char byte[4]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1681 PyOS_snprintf(byte, sizeof(byte), "%02x", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1682 ((int)PyString_AS_STRING(uself->object)[uself->start])&0xff); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1683 return PyString_FromFormat( |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1684 "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1685 PyString_AS_STRING(uself->encoding), |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1686 byte, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1687 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1688 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1689 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1690 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1691 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1692 "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s", |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1693 PyString_AS_STRING(uself->encoding), |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1694 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1695 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1696 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1697 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1698 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1699 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1700 static PyTypeObject _PyExc_UnicodeDecodeError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1701 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1702 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1703 EXC_MODULE_NAME "UnicodeDecodeError", |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1704 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1705 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1706 (reprfunc)UnicodeDecodeError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1707 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
38468
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1708 PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse, |
|
f17d37920f6a
use the UnicodeError traversal and clearing functions in UnicodeError
Michael W. Hudson <mwh@python.net>
parents:
38467
diff
changeset
|
1709 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1710 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1711 (initproc)UnicodeDecodeError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1712 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1713 PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1714 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1715 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1716 PyUnicodeDecodeError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1717 const char *encoding, const char *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1718 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1719 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1720 assert(length < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1721 assert(start < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1722 assert(end < INT_MAX); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1723 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1724 encoding, object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1725 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1726 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1727 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1728 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1729 * UnicodeTranslateError extends UnicodeError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1730 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1731 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1732 static int |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1733 UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1734 PyObject *kwds) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1735 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1736 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1737 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1738 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1739 Py_CLEAR(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1740 Py_CLEAR(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1741 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1742 if (!PyArg_ParseTuple(args, "O!nnO!", |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1743 &PyUnicode_Type, &self->object, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1744 &self->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1745 &self->end, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1746 &PyString_Type, &self->reason)) { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1747 self->object = self->reason = NULL; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1748 return -1; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1749 } |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1750 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1751 Py_INCREF(self->object); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1752 Py_INCREF(self->reason); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1753 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1754 return 0; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1755 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1756 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1757 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1758 static PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1759 UnicodeTranslateError_str(PyObject *self) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1760 { |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1761 PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self; |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1762 |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1763 if (uself->end==uself->start+1) { |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1764 int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start]; |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1765 char badchar_str[20]; |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1766 if (badchar <= 0xff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1767 PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1768 else if (badchar <= 0xffff) |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1769 PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1770 else |
|
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1771 PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1772 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1773 "can't translate character u'\\%s' in position %zd: %.400s", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1774 badchar_str, |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1775 uself->start, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1776 PyString_AS_STRING(uself->reason) |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1777 ); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1778 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1779 return PyString_FromFormat( |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1780 "can't translate characters in position %zd-%zd: %.400s", |
|
42083
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1781 uself->start, |
|
37189e375ec7
Add T_PYSSIZET in structmember.h: This can be used for
Walter Dörwald <walter@livinglogic.de>
parents:
41745
diff
changeset
|
1782 uself->end-1, |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1783 PyString_AS_STRING(uself->reason) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1784 ); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1785 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1786 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1787 static PyTypeObject _PyExc_UnicodeTranslateError = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1788 PyObject_HEAD_INIT(NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1789 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1790 EXC_MODULE_NAME "UnicodeTranslateError", |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1791 sizeof(PyUnicodeErrorObject), 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1792 (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1793 (reprfunc)UnicodeTranslateError_str, 0, 0, 0, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1794 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
39781
cb883e7e0b7e
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Georg Brandl <georg@python.org>
parents:
39487
diff
changeset
|
1795 PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1796 (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1797 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), |
|
38461
6ba5678be7f2
Quality control, meet exceptions.c, round two.
Michael W. Hudson <mwh@python.net>
parents:
38458
diff
changeset
|
1798 (initproc)UnicodeTranslateError_init, 0, BaseException_new, |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1799 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1800 PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1801 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1802 PyObject * |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1803 PyUnicodeTranslateError_Create( |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1804 const Py_UNICODE *object, Py_ssize_t length, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1805 Py_ssize_t start, Py_ssize_t end, const char *reason) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1806 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1807 return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns", |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1808 object, length, start, end, reason); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1809 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1810 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1811 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1812 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1813 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1814 * AssertionError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1815 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1816 SimpleExtendsException(PyExc_StandardError, AssertionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1817 "Assertion failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1818 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1819 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1820 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1821 * ArithmeticError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1822 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1823 SimpleExtendsException(PyExc_StandardError, ArithmeticError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1824 "Base class for arithmetic errors."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1825 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1826 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1827 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1828 * FloatingPointError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1829 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1830 SimpleExtendsException(PyExc_ArithmeticError, FloatingPointError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1831 "Floating point operation failed."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1832 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1833 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1834 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1835 * OverflowError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1836 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1837 SimpleExtendsException(PyExc_ArithmeticError, OverflowError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1838 "Result too large to be represented."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1839 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1840 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1841 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1842 * ZeroDivisionError extends ArithmeticError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1843 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1844 SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1845 "Second argument to a division or modulo operation was zero."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1846 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1847 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1848 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1849 * SystemError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1850 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1851 SimpleExtendsException(PyExc_StandardError, SystemError, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1852 "Internal error in the Python interpreter.\n" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1853 "\n" |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1854 "Please report this to the Python maintainer, along with the traceback,\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1855 "the Python version, and the hardware/OS platform and version."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1856 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1857 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1858 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1859 * ReferenceError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1860 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1861 SimpleExtendsException(PyExc_StandardError, ReferenceError, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1862 "Weak ref proxy used after referent went away."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1863 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1864 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1865 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1866 * MemoryError extends StandardError |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1867 */ |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1868 SimpleExtendsException(PyExc_StandardError, MemoryError, "Out of memory."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1869 |
|
45832
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1870 /* |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1871 * BufferError extends StandardError |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1872 */ |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1873 SimpleExtendsException(PyExc_StandardError, BufferError, "Buffer error."); |
|
5c0b5cabeec9
Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will.
Travis E. Oliphant <oliphant@enthought.com>
parents:
45830
diff
changeset
|
1874 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1875 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1876 /* Warning category docstrings */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1877 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1878 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1879 * Warning extends Exception |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1880 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1881 SimpleExtendsException(PyExc_Exception, Warning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1882 "Base class for warning categories."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1883 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1884 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1885 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1886 * UserWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1887 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1888 SimpleExtendsException(PyExc_Warning, UserWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1889 "Base class for warnings generated by user code."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1890 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1891 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1892 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1893 * DeprecationWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1894 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1895 SimpleExtendsException(PyExc_Warning, DeprecationWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1896 "Base class for warnings about deprecated features."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1897 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1898 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1899 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1900 * PendingDeprecationWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1901 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1902 SimpleExtendsException(PyExc_Warning, PendingDeprecationWarning, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1903 "Base class for warnings about features which will be deprecated\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1904 "in the future."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1905 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1906 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1907 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1908 * SyntaxWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1909 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1910 SimpleExtendsException(PyExc_Warning, SyntaxWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1911 "Base class for warnings about dubious syntax."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1912 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1913 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1914 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1915 * RuntimeWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1916 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1917 SimpleExtendsException(PyExc_Warning, RuntimeWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1918 "Base class for warnings about dubious runtime behavior."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1919 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1920 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1921 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1922 * FutureWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1923 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1924 SimpleExtendsException(PyExc_Warning, FutureWarning, |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1925 "Base class for warnings about constructs that will change semantically\n" |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1926 "in the future."); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1927 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1928 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1929 /* |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1930 * ImportWarning extends Warning |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1931 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1932 SimpleExtendsException(PyExc_Warning, ImportWarning, |
|
38447
807540cf7714
move semicolons
Richard Jones <richard@commonground.com.au>
parents:
38446
diff
changeset
|
1933 "Base class for warnings about probable mistakes in module imports"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1934 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1935 |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1936 /* |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1937 * UnicodeWarning extends Warning |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1938 */ |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1939 SimpleExtendsException(PyExc_Warning, UnicodeWarning, |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1940 "Base class for warnings about Unicode related problems, mostly\n" |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1941 "related to conversion problems."); |
|
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1942 |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1943 /* |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1944 * BytesWarning extends Warning |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1945 */ |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1946 SimpleExtendsException(PyExc_Warning, BytesWarning, |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1947 "Base class for warnings about bytes and buffer related problems, mostly\n" |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
1948 "related to conversion from str or comparing to str."); |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
1949 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1950 /* Pre-computed MemoryError instance. Best to create this as early as |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1951 * possible and not wait until a MemoryError is actually raised! |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1952 */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1953 PyObject *PyExc_MemoryErrorInst=NULL; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1954 |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1955 /* Pre-computed RuntimeError instance for when recursion depth is reached. |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1956 Meant to be used when normalizing the exception for exceeding the recursion |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1957 depth will cause its own infinite recursion. |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1958 */ |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1959 PyObject *PyExc_RecursionErrorInst = NULL; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
1960 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1961 /* module global functions */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1962 static PyMethodDef functions[] = { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1963 /* Sentinel */ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1964 {NULL, NULL} |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1965 }; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1966 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1967 #define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1968 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1969 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1970 #define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1971 PyModule_AddObject(m, # TYPE, PyExc_ ## TYPE); \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1972 if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1973 Py_FatalError("Module dictionary insertion problem."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1974 |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
1975 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
38779
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1976 /* crt variable checking in VisualStudio .NET 2005 */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1977 #include <crtdbg.h> |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1978 |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1979 static int prevCrtReportMode; |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1980 static _invalid_parameter_handler prevCrtHandler; |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1981 |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1982 /* Invalid parameter handler. Sets a ValueError exception */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1983 static void |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1984 InvalidParameterHandler( |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1985 const wchar_t * expression, |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1986 const wchar_t * function, |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1987 const wchar_t * file, |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1988 unsigned int line, |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1989 uintptr_t pReserved) |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1990 { |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1991 /* Do nothing, allow execution to continue. Usually this |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1992 * means that the CRT will set errno to EINVAL |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1993 */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1994 } |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1995 #endif |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1996 |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
1997 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
1998 PyMODINIT_FUNC |
|
38458
236725f64a34
Quality control, meet exceptions.c.
Michael W. Hudson <mwh@python.net>
parents:
38447
diff
changeset
|
1999 _PyExc_Init(void) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2000 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2001 PyObject *m, *bltinmod, *bdict; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2002 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2003 PRE_INIT(BaseException) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2004 PRE_INIT(Exception) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2005 PRE_INIT(StandardError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2006 PRE_INIT(TypeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2007 PRE_INIT(StopIteration) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2008 PRE_INIT(GeneratorExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2009 PRE_INIT(SystemExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2010 PRE_INIT(KeyboardInterrupt) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2011 PRE_INIT(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2012 PRE_INIT(EnvironmentError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2013 PRE_INIT(IOError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2014 PRE_INIT(OSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2015 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2016 PRE_INIT(WindowsError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2017 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2018 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2019 PRE_INIT(VMSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2020 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2021 PRE_INIT(EOFError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2022 PRE_INIT(RuntimeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2023 PRE_INIT(NotImplementedError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2024 PRE_INIT(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2025 PRE_INIT(UnboundLocalError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2026 PRE_INIT(AttributeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2027 PRE_INIT(SyntaxError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2028 PRE_INIT(IndentationError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2029 PRE_INIT(TabError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2030 PRE_INIT(LookupError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2031 PRE_INIT(IndexError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2032 PRE_INIT(KeyError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2033 PRE_INIT(ValueError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2034 PRE_INIT(UnicodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2035 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2036 PRE_INIT(UnicodeEncodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2037 PRE_INIT(UnicodeDecodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2038 PRE_INIT(UnicodeTranslateError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2039 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2040 PRE_INIT(AssertionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2041 PRE_INIT(ArithmeticError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2042 PRE_INIT(FloatingPointError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2043 PRE_INIT(OverflowError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2044 PRE_INIT(ZeroDivisionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2045 PRE_INIT(SystemError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2046 PRE_INIT(ReferenceError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2047 PRE_INIT(MemoryError) |
| 48103 | 2048 PRE_INIT(BufferError) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2049 PRE_INIT(Warning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2050 PRE_INIT(UserWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2051 PRE_INIT(DeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2052 PRE_INIT(PendingDeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2053 PRE_INIT(SyntaxWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2054 PRE_INIT(RuntimeWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2055 PRE_INIT(FutureWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2056 PRE_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2057 PRE_INIT(UnicodeWarning) |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
2058 PRE_INIT(BytesWarning) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2059 |
|
38446
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2060 m = Py_InitModule4("exceptions", functions, exceptions_doc, |
|
9a65fd4255a3
doc string additions and tweaks
Richard Jones <richard@commonground.com.au>
parents:
38439
diff
changeset
|
2061 (PyObject *)NULL, PYTHON_API_VERSION); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2062 if (m == NULL) return; |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2063 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2064 bltinmod = PyImport_ImportModule("__builtin__"); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2065 if (bltinmod == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2066 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2067 bdict = PyModule_GetDict(bltinmod); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2068 if (bdict == NULL) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2069 Py_FatalError("exceptions bootstrapping error."); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2070 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2071 POST_INIT(BaseException) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2072 POST_INIT(Exception) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2073 POST_INIT(StandardError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2074 POST_INIT(TypeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2075 POST_INIT(StopIteration) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2076 POST_INIT(GeneratorExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2077 POST_INIT(SystemExit) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2078 POST_INIT(KeyboardInterrupt) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2079 POST_INIT(ImportError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2080 POST_INIT(EnvironmentError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2081 POST_INIT(IOError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2082 POST_INIT(OSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2083 #ifdef MS_WINDOWS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2084 POST_INIT(WindowsError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2085 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2086 #ifdef __VMS |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2087 POST_INIT(VMSError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2088 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2089 POST_INIT(EOFError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2090 POST_INIT(RuntimeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2091 POST_INIT(NotImplementedError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2092 POST_INIT(NameError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2093 POST_INIT(UnboundLocalError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2094 POST_INIT(AttributeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2095 POST_INIT(SyntaxError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2096 POST_INIT(IndentationError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2097 POST_INIT(TabError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2098 POST_INIT(LookupError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2099 POST_INIT(IndexError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2100 POST_INIT(KeyError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2101 POST_INIT(ValueError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2102 POST_INIT(UnicodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2103 #ifdef Py_USING_UNICODE |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2104 POST_INIT(UnicodeEncodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2105 POST_INIT(UnicodeDecodeError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2106 POST_INIT(UnicodeTranslateError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2107 #endif |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2108 POST_INIT(AssertionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2109 POST_INIT(ArithmeticError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2110 POST_INIT(FloatingPointError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2111 POST_INIT(OverflowError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2112 POST_INIT(ZeroDivisionError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2113 POST_INIT(SystemError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2114 POST_INIT(ReferenceError) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2115 POST_INIT(MemoryError) |
| 48103 | 2116 POST_INIT(BufferError) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2117 POST_INIT(Warning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2118 POST_INIT(UserWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2119 POST_INIT(DeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2120 POST_INIT(PendingDeprecationWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2121 POST_INIT(SyntaxWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2122 POST_INIT(RuntimeWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2123 POST_INIT(FutureWarning) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2124 POST_INIT(ImportWarning) |
|
39487
635b09b1f542
Slightly revised version of patch #1538956:
Marc-André Lemburg <mal@egenix.com>
parents:
38999
diff
changeset
|
2125 POST_INIT(UnicodeWarning) |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46075
diff
changeset
|
2126 POST_INIT(BytesWarning) |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2127 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2128 PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2129 if (!PyExc_MemoryErrorInst) |
|
50830
e158c70511fe
#4077: No need to append \n when calling Py_FatalError
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48103
diff
changeset
|
2130 Py_FatalError("Cannot pre-allocate MemoryError instance"); |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2131 |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2132 PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2133 if (!PyExc_RecursionErrorInst) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2134 Py_FatalError("Cannot pre-allocate RuntimeError instance for " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2135 "recursion errors"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2136 else { |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2137 PyBaseExceptionObject *err_inst = |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2138 (PyBaseExceptionObject *)PyExc_RecursionErrorInst; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2139 PyObject *args_tuple; |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2140 PyObject *exc_message; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2141 exc_message = PyString_FromString("maximum recursion depth exceeded"); |
|
43276
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2142 if (!exc_message) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2143 Py_FatalError("cannot allocate argument for RuntimeError " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2144 "pre-allocation"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2145 args_tuple = PyTuple_Pack(1, exc_message); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2146 if (!args_tuple) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2147 Py_FatalError("cannot allocate tuple for RuntimeError " |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2148 "pre-allocation"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2149 Py_DECREF(exc_message); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2150 if (BaseException_init(err_inst, args_tuple, NULL)) |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2151 Py_FatalError("init of pre-allocated RuntimeError failed"); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2152 Py_DECREF(args_tuple); |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2153 } |
|
3bc3f12cae28
Fix a crasher where Python code managed to infinitely recurse in C code without
Brett Cannon <bcannon@gmail.com>
parents:
42688
diff
changeset
|
2154 |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2155 Py_DECREF(bltinmod); |
|
38779
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2156 |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
2157 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
38779
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2158 /* Set CRT argument error handler */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2159 prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler); |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2160 /* turn off assertions in debug mode */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2161 prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0); |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2162 #endif |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2163 } |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2164 |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2165 void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2166 _PyExc_Fini(void) |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2167 { |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2168 Py_XDECREF(PyExc_MemoryErrorInst); |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2169 PyExc_MemoryErrorInst = NULL; |
|
38999
75bdb1eb0766
Fix build problems with the platform SDK on windows. It is not sufficient to test for the C compiler version when determining if we have the secure CRT from microsoft. Must test with an undocumented macro, __STDC_SECURE_LIB__ too.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38779
diff
changeset
|
2170 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
|
38779
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2171 /* reset CRT error handling */ |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2172 _set_invalid_parameter_handler(prevCrtHandler); |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2173 _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); |
|
4c74ec831a6c
Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38577
diff
changeset
|
2174 #endif |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
diff
changeset
|
2175 } |
