annotate Python/exceptions.c @ 35772:f64fb284ed15 legacy-trunk

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