annotate Python/exceptions.c @ 30037:0504ba8efbb6 legacy-trunk

As discussed on python-dev, changed builtin.zip() to handle zero arguments by returning an empty list instead of raising a TypeError.
author Raymond Hettinger <python@rcn.com>
date Sat, 02 Aug 2003 07:42:57 +0000
parents b38cebc76d82
children aa5cb8e3b9ea df654861ccf6
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\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
60 +-- StandardError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
61 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
62 | +-- KeyboardInterrupt\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
63 | +-- ImportError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
64 | +-- EnvironmentError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
65 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
66 | | +-- IOError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
67 | | +-- OSError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
68 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
69 | | +-- WindowsError\n\
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
70 | | +-- VMSError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
71 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
72 | +-- EOFError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
73 | +-- RuntimeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
74 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
75 | | +-- NotImplementedError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
76 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
77 | +-- NameError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
78 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
79 | | +-- UnboundLocalError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
80 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
81 | +-- AttributeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
82 | +-- SyntaxError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
83 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
84 | | +-- IndentationError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
85 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
86 | | +-- TabError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
87 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
88 | +-- TypeError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
89 | +-- AssertionError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
90 | +-- LookupError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
91 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
92 | | +-- IndexError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
93 | | +-- KeyError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
94 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
95 | +-- ArithmeticError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
96 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
97 | | +-- OverflowError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
98 | | +-- ZeroDivisionError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
99 | | +-- FloatingPointError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
100 | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
101 | +-- ValueError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
102 | | |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
103 | | +-- 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
104 | | |\n\
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
105 | | +-- 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
106 | | +-- 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
107 | | +-- UnicodeTranslateError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
108 | |\n\
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
109 | +-- ReferenceError\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
110 | +-- SystemError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
111 | +-- MemoryError\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
112 |\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
113 +---Warning\n\
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
114 |\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
115 +-- UserWarning\n\
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
116 +-- DeprecationWarning\n\
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
117 +-- PendingDeprecationWarning\n\
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
118 +-- SyntaxWarning\n\
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
119 +-- OverflowWarning\n\
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
120 +-- RuntimeWarning\n\
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
121 +-- FutureWarning"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
122 );
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
123
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 /* 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
126 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
127 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
128 {
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
129 PyObject *module;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
130 int status = -1;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
131
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
132 if (!methods)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
133 return 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
134
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
135 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
136 if (!module)
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
137 return 0;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
138 while (methods->ml_name) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
139 /* 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
140 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
141 PyObject *meth;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
142
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
143 if (!func)
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
144 goto status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
145
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
146 /* 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
147 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
148 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
149 goto status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
150 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
151
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
152 /* add method to dictionary */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
153 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
154 Py_DECREF(meth);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
155 Py_DECREF(func);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
156
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
157 /* 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
158 if (status)
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
159 goto status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
160
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
161 methods++;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
162 }
27559
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
163 status = 0;
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
164 status:
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
165 Py_DECREF(module);
faabd9867fb8 Provide __module__ attributes for functions defined in C and Python.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26550
diff changeset
166 return status;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
167 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
168
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
169
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
170
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
171 /* 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
172 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
173 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
174 char *name, PyMethodDef *methods,
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
175 char *docstr)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
176 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
177 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
178 PyObject *str = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
179 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
180
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
181 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
182 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
183
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
184 /* 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
185 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
186 */
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 if (docstr) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
189 if (!(str = PyString_FromString(docstr)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
190 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
191 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
192 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
193 }
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 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
196 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
197
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
198 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
199 Py_DECREF(*klass);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
200 *klass = NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
201 goto finally;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
202 }
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 status = 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
205
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
206 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
207 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
208 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
209 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
210 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
211
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 /* 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
214 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
215 get_self(PyObject *args)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
216 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
217 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
218 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
219 /* 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
220 if (PyExc_TypeError) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
221 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14068
diff changeset
222 "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
223 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
224 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
225 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
226 return self;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
227 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
228
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 /* 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
232 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
233 * 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
234 * 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
235 * 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
236 * 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
237 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
238 * 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
239 * 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
240 * 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
241 * 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
242 * explicit bootstrap order.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
243 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
244 * 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
245 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
246
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
247 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
248
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
249
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
250 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
251 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
252 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
253 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
254
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
255 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
256 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
257
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
258 /* set args attribute */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
259 /* 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
260 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
261 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
262 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
263 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
264 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
265 if (status < 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
266 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
267
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
268 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
269 return Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
270 }
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
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
273 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
274 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
275 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
276 PyObject *out;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
277
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
278 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
279 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
280
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
281 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
282 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
283 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
284
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
285 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
286 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
287 out = PyString_FromString("");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
288 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
289 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
290 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
291 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
292 if (tmp) {
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
293 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
294 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
295 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
296 else
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
297 out = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
298 break;
13484
67fd19d74528 Exception__str__(): In case 1, be sure to decref the tmp local
Barry Warsaw <barry@python.org>
parents: 13453
diff changeset
299 }
25320
14ad560f4a97 Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
Guido van Rossum <guido@python.org>
parents: 25110
diff changeset
300 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
301 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
302 /* Fall through */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
303 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
304 out = PyObject_Str(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
305 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
306 }
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 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
309 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
310 }
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
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
313 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
314 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
315 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
316 PyObject *out;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
317 PyObject *index;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
318
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
319 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
320 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
321
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
322 args = PyObject_GetAttrString(self, "args");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
323 if (!args)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
324 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
325
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
326 out = PyObject_GetItem(args, index);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
327 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
328 return out;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
329 }
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 static PyMethodDef
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
333 Exception_methods[] = {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
334 /* 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
335 { "__getitem__", Exception__getitem__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
336 { "__str__", Exception__str__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
337 { "__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
338 { NULL, NULL }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
339 };
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 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
343 make_Exception(char *modulename)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
344 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
345 PyObject *dict = PyDict_New();
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
346 PyObject *str = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
347 PyObject *name = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
348 int status = -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
349
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
350 if (!dict)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
351 return -1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
352
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
353 /* 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
354 * returning NULL.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
355 */
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 if (!(str = PyString_FromString(modulename)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
358 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
359 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
360 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
361 Py_DECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
362 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
363 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
364 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
365 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
366
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
367 if (!(name = PyString_FromString("Exception")))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
368 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
369
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
370 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
371 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
372
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
373 /* 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
374 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
375 /* 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
376 * happen during interpreter shutdown.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
377 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
378 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
379
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
380 status = 0;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
381
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
382 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
383 Py_XDECREF(dict);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
384 Py_XDECREF(str);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
385 Py_XDECREF(name);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
386 return status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
387 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
388
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
389
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
390
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
391 PyDoc_STRVAR(StandardError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
392 "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
393
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
394 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
395
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
396 PyDoc_STRVAR(StopIteration__doc__, "Signal the end from iterator.next().");
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
397
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
398
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
399
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
400 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
401
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
402
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
403 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
404 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
405 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
406 PyObject *code;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
407 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
408
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
409 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
410 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
411
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
412 /* Set args attribute. */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
413 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
414 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
415
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
416 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
417 if (status < 0) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
418 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
419 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
420 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
421
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
422 /* set code attribute */
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
423 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
424 case 0:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
425 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
426 code = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
427 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
428 case 1:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
429 code = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
430 break;
25325
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
431 case -1:
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
432 PyErr_Clear();
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
433 /* Fall through */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
434 default:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
435 Py_INCREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
436 code = args;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
437 break;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
438 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
439
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
440 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
441 Py_DECREF(code);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
442 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
443 if (status < 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
444 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
445
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
446 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
447 return Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
448 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
449
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
450
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
451 static PyMethodDef SystemExit_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
452 { "__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
453 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
454 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
455
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
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
458 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
459
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
460 PyDoc_STRVAR(ImportError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
461 "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
462
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
463
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
464
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
465 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
466
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
467
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
468 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
469 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
470 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
471 PyObject *item0 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
472 PyObject *item1 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
473 PyObject *item2 = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
474 PyObject *subslice = NULL;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
475 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
476
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
477 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
478 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
479
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
480 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
481 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
482
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
483 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
484 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
485 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
486 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
487 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
488 goto finally;
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
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
491 switch (PySequence_Size(args)) {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
492 case 3:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
493 /* 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
494 * 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
495 * 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
496 * 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
497 *
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
498 * except IOError, (errno, strerror):
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 * 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
501 * 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
502 * when it was supplied.
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
503 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
504 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
505 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
506 item2 = PySequence_GetItem(args, 2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
507 if (!item0 || !item1 || !item2)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
508 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
509
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
510 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
511 PyObject_SetAttrString(self, "strerror", item1) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
512 PyObject_SetAttrString(self, "filename", item2))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
513 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
514 goto finally;
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
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
517 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
518 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
519 goto finally;
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
520 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
521
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
522 case 2:
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
523 /* 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
524 * argument is given.
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
525 */
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
526 item0 = PySequence_GetItem(args, 0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
527 item1 = PySequence_GetItem(args, 1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
528 if (!item0 || !item1)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
529 goto finally;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
530
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
531 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
532 PyObject_SetAttrString(self, "strerror", item1))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
533 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
534 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
535 }
13453
d6198e703602 EnvironmentError__init__(): The two case clauses were missing
Barry Warsaw <barry@python.org>
parents: 13283
diff changeset
536 break;
25325
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
537
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
538 case -1:
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
539 PyErr_Clear();
6b62ab8485eb Two more cases of switch(PySequence_Size()) without checking for case -1.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25320
diff changeset
540 break;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
541 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
542
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
543 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
544 rtnval = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
545
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
546 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
547 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
548 Py_XDECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
549 Py_XDECREF(item1);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
550 Py_XDECREF(item2);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
551 Py_XDECREF(subslice);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
552 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
553 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
554
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
555
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
556 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
557 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
558 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
559 PyObject *originalself = self;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
560 PyObject *filename;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
561 PyObject *serrno;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
562 PyObject *strerror;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
563 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
564
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
565 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
566 return NULL;
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
567
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
568 filename = PyObject_GetAttrString(self, "filename");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
569 serrno = PyObject_GetAttrString(self, "errno");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
570 strerror = PyObject_GetAttrString(self, "strerror");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
571 if (!filename || !serrno || !strerror)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
572 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
573
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
574 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
575 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
576 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
577 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
578
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
579 if (!fmt || !repr || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
580 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
581 Py_XDECREF(repr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
582 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
583 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
584 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
585
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
586 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
587 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
588 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
589
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
590 rtnval = PyString_Format(fmt, tuple);
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 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
593 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
594 /* 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
595 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
596 strerror = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
597 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
598 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
599 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
600 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
601
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
602 if (!fmt || !tuple) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
603 Py_XDECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
604 Py_XDECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
605 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
606 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
607
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
608 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
609 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
610
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
611 rtnval = PyString_Format(fmt, tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
612
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
613 Py_DECREF(fmt);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
614 Py_DECREF(tuple);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
615 /* 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
616 serrno = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
617 strerror = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
618 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
619 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
620 /* The original Python code said:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
621 *
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
622 * return StandardError.__str__(self)
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 * 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
625 * 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
626 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
627 rtnval = Exception__str__(originalself, args);
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 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
630 Py_XDECREF(filename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
631 Py_XDECREF(serrno);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
632 Py_XDECREF(strerror);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
633 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
634 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
635
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
636
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
637 static
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
638 PyMethodDef EnvironmentError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
639 {"__init__", EnvironmentError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
640 {"__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
641 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
642 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
643
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
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
647 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
648
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
649 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
650
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
651 #ifdef MS_WINDOWS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
652 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
653 #endif /* MS_WINDOWS */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
654
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
655 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
656 static char
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
657 VMSError__doc__[] = "OpenVMS OS system call failed.";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
658 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
659
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
660 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
661
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
662 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
663
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
664 PyDoc_STRVAR(NotImplementedError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
665 "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
666
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
667 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
668
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
669 PyDoc_STRVAR(UnboundLocalError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
670 "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
671
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
672 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
673
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
674
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
675
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
676 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
677
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
678
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
679 static int
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
680 SyntaxError__classinit__(PyObject *klass)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
681 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
682 int retval = 0;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
683 PyObject *emptystring = PyString_FromString("");
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
684
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
685 /* Additional class-creation time initializations */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
686 if (!emptystring ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
687 PyObject_SetAttrString(klass, "msg", emptystring) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
688 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
689 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
690 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
691 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
692 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
693 {
14054
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
694 retval = -1;
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 Py_XDECREF(emptystring);
e8301612e7d8 SyntaxError__classinit__(): Slight reorg for simplicity.
Barry Warsaw <barry@python.org>
parents: 14013
diff changeset
697 return retval;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
698 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
699
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
700
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
701 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
702 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
703 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
704 PyObject *rtnval = NULL;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
705 int lenargs;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
706
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
707 if (!(self = get_self(args)))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
708 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
709
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
710 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
711 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
712
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
713 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
714 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
715
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13565
diff changeset
716 lenargs = PySequence_Size(args);
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
717 if (lenargs >= 1) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
718 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
719 int status;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
720
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
721 if (!item0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
722 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
723 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
724 Py_DECREF(item0);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
725 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
726 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
727 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
728 if (lenargs == 2) {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
729 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
730 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
731 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
732 int status = 1;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
733
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
734 if (!info)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
735 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
736
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
737 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
738 if (filename != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
739 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
740 if (lineno != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
741 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
742 if (offset != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
743 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
744 if (text != NULL) {
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
745 status =
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
746 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
747 || 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
748 || 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
749 || 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
750 Py_DECREF(text);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
751 }
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
752 Py_DECREF(offset);
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(lineno);
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(filename);
847844248c6f SyntaxError__init__(): Be a little more robust when picking apart the
Fred Drake <fdrake@acm.org>
parents: 16837
diff changeset
757 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
758 Py_DECREF(info);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
759
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
760 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
761 goto finally;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
762 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
763 Py_INCREF(Py_None);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
764 rtnval = Py_None;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
765
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
766 finally:
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
767 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
768 return rtnval;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
769 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
770
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
771
13996
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
772 /* 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
773 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
774 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
775 static char *
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
776 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
777 {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
778 char *cp = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
779 char *result = name;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
780
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
781 if (name == NULL)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
782 return "???";
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
783 while (*cp != '\0') {
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
784 if (*cp == SEP)
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
785 result = cp + 1;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
786 ++cp;
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
787 }
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
788 return result;
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
d8069efcd76e my_basename(): Removes the leading path components from a path name,
Fred Drake <fdrake@acm.org>
parents: 13991
diff changeset
791
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
792 static PyObject *
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
793 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
794 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
795 PyObject *msg;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
796 PyObject *str;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
797 PyObject *filename, *lineno, *result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
798
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
799 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
800 return NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
801
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
802 if (!(msg = PyObject_GetAttrString(self, "msg")))
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
803 return NULL;
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
804
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
805 str = PyObject_Str(msg);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
806 Py_DECREF(msg);
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
807 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
808
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
809 /* 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
810 lineno here */
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
811
25110
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
812 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
813 int have_filename = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
814 int have_lineno = 0;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
815 char *buffer = NULL;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
816
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
817 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
818 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
819 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
820 PyErr_Clear();
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
821
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
822 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
823 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
824 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
825 PyErr_Clear();
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
826
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
827 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
828 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
829 if (have_filename)
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
830 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
831
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
832 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
833 if (buffer != NULL) {
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
834 if (have_filename && have_lineno)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
835 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
836 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
837 my_basename(PyString_AS_STRING(filename)),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
838 PyInt_AsLong(lineno));
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
839 else if (have_filename)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
840 PyOS_snprintf(buffer, bufsize, "%s (%s)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
841 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
842 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
843 else if (have_lineno)
21072
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
844 PyOS_snprintf(buffer, bufsize, "%s (line %ld)",
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
845 PyString_AS_STRING(str),
639c0a3ae8dc Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20279
diff changeset
846 PyInt_AsLong(lineno));
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
847
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
848 result = PyString_FromString(buffer);
14013
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
849 PyMem_FREE(buffer);
6c7fa523726f SyntaxError__str__(): Fix two memory problems discovered by Insure.
Barry Warsaw <barry@python.org>
parents: 13996
diff changeset
850
13991
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
851 if (result == NULL)
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
852 result = str;
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
853 else
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
854 Py_DECREF(str);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
855 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
856 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
857 Py_XDECREF(filename);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
858 Py_XDECREF(lineno);
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
859 }
7834a113ce24 SyntaxError__str__(): Do more formatting of the exception here, rather
Fred Drake <fdrake@acm.org>
parents: 13973
diff changeset
860 return result;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
861 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
862
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
863
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 16852
diff changeset
864 static PyMethodDef SyntaxError_methods[] = {
13182
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
865 {"__init__", SyntaxError__init__, METH_VARARGS},
1e302d996d58 replace constant 1 with symbolic constant METH_VARARGS
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12968
diff changeset
866 {"__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
867 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
868 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
869
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
870
25110
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
871 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
872 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
873 {
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
874 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
875 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
876
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
877 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
878 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
879
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
880 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
881 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
882
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
883 /* 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
884 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
885 KeyError: ''
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
886 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
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 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
889 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
890 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
891 */
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 (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
893 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
894 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
895 }
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
896 else
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
897 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
898
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
899 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
900 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
901 }
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
902
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
903 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
904 {"__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
905 {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
906 };
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
907
0401a0ead1eb Add a custom __str__ method to KeyError that applies repr() to the
Guido van Rossum <guido@python.org>
parents: 25094
diff changeset
908
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
909 #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
910 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
911 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
912 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
913 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
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 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
916 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
917 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
918 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
919 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
920 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
921 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
922 *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
923 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
924 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
925 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
926
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
929 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
930 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
931 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
932 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
933
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
934 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
935 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
936 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
937 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
938 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
939 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
940
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
943 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
944 {
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 *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
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 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
948 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
949 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
950 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
951 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
952 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
953 }
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 attr;
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
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
959 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
960 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
961 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
962 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
963
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
964 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
965 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
966 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
967 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
968 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
969 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
970
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 static
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
973 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
974 {
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 *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
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 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
978 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
979 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
980 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
981 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
982 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
983 }
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 attr;
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
987 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
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 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
992 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
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 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
997 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
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 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1002 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
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 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1007 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
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 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1012 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
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 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 *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
1022 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
1023 *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
1024 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
1025 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
1026 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1027 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
1028 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1029
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1030
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1031 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
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 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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 *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
1041 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
1042 *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
1043 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
1044 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
1045 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1046 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
1069 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1070 return 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
1071 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1072
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1073
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1074 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
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 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
1077 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
1078 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
1079 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
1080 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
1081 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
1082 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
1083 *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
1084 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
1085 *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
1086 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
1087 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
1088 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1089 return -1;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1090 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1092
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1093 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
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 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 *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
1103 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
1104 *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
1105 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
1106 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
1107 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1108 return -1;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1109 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1110
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 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
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 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
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
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 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
1119 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1120 return 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
1121 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1122
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1123
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1124 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
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 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
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
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 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
1173 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
1174 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1175 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
1176 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
1177 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
1178 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
1179 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
1180 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
1181
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1182 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
1183 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
1184
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1185 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
1186 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
1187
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1188 if (!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
1189 &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
1190 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
1191 &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
1192 &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
1193 &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
1194 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
1195
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1196 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
1197 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
1198
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1199 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
1200 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
1201 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
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, "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
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, "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
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, "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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1210 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
1211 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
1212
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1213 finally:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1214 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
1215 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
1216 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1217
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1218
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1219 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
1220 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
1221 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1222 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
1223 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1224
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1225 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
1226 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
1227 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1228 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
1229 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
1230 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
1231 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
1232 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
1233 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
1234 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
1235
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1236 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
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 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
1239 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
1240
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1241 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
1242 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
1243
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1244 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
1245 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
1246
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1247 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
1248 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
1249
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1250 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
1251 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
1252
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1253 if (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
1254 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
1255 "'%.400s' codec can't encode character '\\u%x' in position %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
1256 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
1257 (int)PyUnicode_AS_UNICODE(objectObj)[start],
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1258 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1259 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
1260 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1261 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1262 else {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1263 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
1264 "'%.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
1265 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
1266 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1267 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
1268 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
1269 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1270 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1271 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
1272
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1273 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1274 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
1275 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
1276 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
1277 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
1278 }
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 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
1281 {"__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
1282 {"__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
1283 {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
1284 };
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1285
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1286
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1287 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
1288 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
1289 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
1290 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1291 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
1292 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
1293 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1294
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 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
1297 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
1298 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1299 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
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
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1302 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
1303 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
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 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
1306 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
1307 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
1308 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
1309 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
1310 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
1311 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
1312
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1313 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
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 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
1316 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
1317
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1318 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
1319 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
1320
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1321 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
1322 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
1323
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1324 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
1325 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
1326
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1327 if (!(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
1328 goto error;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1329
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1330 if (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
1331 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
1332 "'%.400s' codec can't decode byte 0x%x in position %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
1333 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
1334 ((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
1335 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1336 PyString_AS_STRING(reasonObj)
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1337 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1338 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1339 else {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1340 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
1341 "'%.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
1342 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
1343 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1344 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
1345 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
1346 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1347 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1348 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
1349
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1350 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1351 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
1352 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
1353 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
1354 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
1355 }
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 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
1358 {"__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
1359 {"__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
1360 {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
1361 };
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1362
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1363
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1364 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
1365 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
1366 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
1367 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1368 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
1369 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
1370 }
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 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
1374 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
1375 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1376 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
1377 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
1378 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
1379 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
1380 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
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 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
1383 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
1384
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1385 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
1386 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
1387
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1388 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
1389 &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
1390 &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
1391 &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
1392 &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
1393 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
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 (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
1396 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
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 (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
1399 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
1400 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
1401 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
1402 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
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 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
1405 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
1406
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1407 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
1408 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
1409
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1410 finally:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1411 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
1412 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
1413 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1414
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1415
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1416 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
1417 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
1418 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1419 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
1420 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
1421 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
1422 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
1423 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
1424 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
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 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
1427
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1428 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
1429 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
1430
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1431 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
1432 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
1433
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1434 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
1435 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
1436
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1437 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
1438 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
1439
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1440 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
1441 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
1442 "can't translate character '\\u%x' in position %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
1443 (int)PyUnicode_AS_UNICODE(objectObj)[start],
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1444 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1445 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
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 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1448 else {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1449 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
1450 "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
1451 start,
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1452 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
1453 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
1454 );
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1455 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1456 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
1457
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1458 error:
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1459 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
1460 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
1461 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
1462 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1463
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1464 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
1465 {"__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
1466 {"__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
1467 {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
1468 };
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1469
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1470
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1471 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
1472 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
1473 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
1474 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1475 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
1476 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
1477 }
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
1478 #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
1479
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1480
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1481
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1482 /* Exception doc strings */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1483
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1484 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
1485
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1486 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
1487
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1488 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
1489
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1490 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
1491
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1492 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
1493
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1494 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
1495
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1496 PyDoc_STRVAR(ZeroDivisionError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1497 "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
1498
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1499 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
1500
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1501 PyDoc_STRVAR(ValueError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1502 "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
1503
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1504 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
1505
26318
910fa739f4a4 Fix PEP 293 related problems with --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 25325
diff changeset
1506 #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
1507 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
1508
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1509 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
1510
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24818
diff changeset
1511 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
1512 #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
1513
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1514 PyDoc_STRVAR(SystemError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1515 "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
1516 \n\
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1517 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
1518 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
1519
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1520 PyDoc_STRVAR(ReferenceError__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1521 "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
1522
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1523 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
1524
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1525 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
1526
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1527 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
1528
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1529 /* Warning category docstrings */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1530
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1531 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
1532
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1533 PyDoc_STRVAR(UserWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1534 "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
1535
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1536 PyDoc_STRVAR(DeprecationWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1537 "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
1538
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1539 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
1540 "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
1541 "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
1542
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1543 PyDoc_STRVAR(SyntaxWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1544 "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
1545
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1546 PyDoc_STRVAR(OverflowWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1547 "Base class for warnings about numeric overflow.");
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
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(RuntimeWarning__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23564
diff changeset
1550 "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
1551
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1552 PyDoc_STRVAR(FutureWarning__doc__,
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1553 "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
1554 "in the future.");
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1555
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1556
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1557
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1558 /* module global functions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1559 static PyMethodDef functions[] = {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1560 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1561 {NULL, NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1562 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1563
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1564
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1565
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1566 /* Global C API defined exceptions */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1567
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1568 PyObject *PyExc_Exception;
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1569 PyObject *PyExc_StopIteration;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1570 PyObject *PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1571 PyObject *PyExc_ArithmeticError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1572 PyObject *PyExc_LookupError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1573
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1574 PyObject *PyExc_AssertionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1575 PyObject *PyExc_AttributeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1576 PyObject *PyExc_EOFError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1577 PyObject *PyExc_FloatingPointError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1578 PyObject *PyExc_EnvironmentError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1579 PyObject *PyExc_IOError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1580 PyObject *PyExc_OSError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1581 PyObject *PyExc_ImportError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1582 PyObject *PyExc_IndexError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1583 PyObject *PyExc_KeyError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1584 PyObject *PyExc_KeyboardInterrupt;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1585 PyObject *PyExc_MemoryError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1586 PyObject *PyExc_NameError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1587 PyObject *PyExc_OverflowError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1588 PyObject *PyExc_RuntimeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1589 PyObject *PyExc_NotImplementedError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1590 PyObject *PyExc_SyntaxError;
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1591 PyObject *PyExc_IndentationError;
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1592 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
1593 PyObject *PyExc_ReferenceError;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1594 PyObject *PyExc_SystemError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1595 PyObject *PyExc_SystemExit;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1596 PyObject *PyExc_UnboundLocalError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1597 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
1598 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
1599 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
1600 PyObject *PyExc_UnicodeTranslateError;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1601 PyObject *PyExc_TypeError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1602 PyObject *PyExc_ValueError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1603 PyObject *PyExc_ZeroDivisionError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1604 #ifdef MS_WINDOWS
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1605 PyObject *PyExc_WindowsError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1606 #endif
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1607 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1608 PyObject *PyExc_VMSError;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1609 #endif
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1610
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1611 /* 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
1612 * 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
1613 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1614 PyObject *PyExc_MemoryErrorInst;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1615
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1616 /* Predefined warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1617 PyObject *PyExc_Warning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1618 PyObject *PyExc_UserWarning;
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1619 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
1620 PyObject *PyExc_PendingDeprecationWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1621 PyObject *PyExc_SyntaxWarning;
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1622 PyObject *PyExc_OverflowWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1623 PyObject *PyExc_RuntimeWarning;
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1624 PyObject *PyExc_FutureWarning;
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1625
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1626
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1627
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1628 /* 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
1629 static struct {
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1630 char *name;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1631 PyObject **exc;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1632 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
1633 char *docstr;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1634 PyMethodDef *methods;
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1635 int (*classinit)(PyObject *);
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1636 } exctable[] = {
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1637 /*
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1638 * 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
1639 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1640 {"Exception", &PyExc_Exception},
17597
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1641 {"StopIteration", &PyExc_StopIteration, &PyExc_Exception,
32e7d0898eab Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
1642 StopIteration__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1643 {"StandardError", &PyExc_StandardError, &PyExc_Exception,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1644 StandardError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1645 {"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
1646 /*
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1647 * 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
1648 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1649 {"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
1650 SystemExit_methods},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1651 {"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
1652 {"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
1653 {"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
1654 EnvironmentError_methods},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1655 {"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
1656 {"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
1657 #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
1658 {"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
1659 WindowsError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1660 #endif /* MS_WINDOWS */
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1661 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1662 {"VMSError", &PyExc_VMSError, &PyExc_OSError,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1663 VMSError__doc__},
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26318
diff changeset
1664 #endif
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1665 {"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
1666 {"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
1667 {"NotImplementedError", &PyExc_NotImplementedError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1668 &PyExc_RuntimeError, NotImplementedError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1669 {"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
1670 {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1671 UnboundLocalError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1672 {"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
1673 {"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
1674 SyntaxError_methods, SyntaxError__classinit__},
13539
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1675 {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1676 IndentationError__doc__},
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1677 {"TabError", &PyExc_TabError, &PyExc_IndentationError,
feab677269e0 Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents: 13484
diff changeset
1678 TabError__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1679 {"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
1680 {"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
1681 {"IndexError", &PyExc_IndexError, &PyExc_LookupError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1682 IndexError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1683 {"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
1684 KeyError__doc__, KeyError_methods},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1685 {"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
1686 {"OverflowError", &PyExc_OverflowError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1687 OverflowError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1688 {"ZeroDivisionError", &PyExc_ZeroDivisionError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1689 ZeroDivisionError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1690 {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1691 FloatingPointError__doc__},
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1692 {"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
1693 {"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
1694 #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
1695 {"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
1696 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
1697 {"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
1698 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
1699 {"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
1700 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
1701 #endif
20279
8b3ea7335c1b weakref.ReferenceError becomes a built-in exception now that weak ref objects
Fred Drake <fdrake@acm.org>
parents: 19433
diff changeset
1702 {"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
1703 {"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
1704 {"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
1705 /* Warning categories */
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1706 {"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
1707 {"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
1708 {"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
1709 DeprecationWarning__doc__},
23564
3f242cdd0904 As discussed on python-dev, add a mechanism to indicate features
Neal Norwitz <nnorwitz@gmail.com>
parents: 22629
diff changeset
1710 {"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
1711 PendingDeprecationWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1712 {"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__},
19433
5d81c6bff306 Introduce OverflowWarning -- to be issued when short int operations
Guido van Rossum <guido@python.org>
parents: 18933
diff changeset
1713 {"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
1714 OverflowWarning__doc__},
15590
1e756f93bf5d Add definitions for standard warning category classes (PyExc_Warning
Guido van Rossum <guido@python.org>
parents: 15318
diff changeset
1715 {"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
1716 RuntimeWarning__doc__},
24818
31d2860089e6 Added a FutureWarning for constructs that will change semantically in
Barry Warsaw <barry@python.org>
parents: 24420
diff changeset
1717 {"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
1718 FutureWarning__doc__},
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1719 /* Sentinel */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1720 {NULL}
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1721 };
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1722
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1723
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1724
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1725 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1726 _PyExc_Init(void)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1727 {
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1728 char *modulename = "exceptions";
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1729 int modnamesz = strlen(modulename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1730 int i;
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1731 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
1732
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1733 me = Py_InitModule(modulename, functions);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1734 if (me == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1735 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1736 mydict = PyModule_GetDict(me);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1737 if (mydict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1738 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1739 bltinmod = PyImport_ImportModule("__builtin__");
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1740 if (bltinmod == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1741 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1742 bdict = PyModule_GetDict(bltinmod);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1743 if (bdict == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1744 goto err;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1745 doc = PyString_FromString(module__doc__);
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1746 if (doc == NULL)
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1747 goto err;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1748
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1749 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
1750 Py_DECREF(doc);
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1751 if (i < 0) {
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1752 err:
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1753 Py_FatalError("exceptions bootstrapping error.");
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1754 return;
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1755 }
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1756
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1757 /* 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
1758 if (make_Exception(modulename) ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1759 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
1760 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
1761 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1762 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
1763 }
16164
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1764
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1765 /* 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
1766 * 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
1767 */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1768 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
1769 int status;
13657
6a5314a6c2c2 Fix two instances of empty argument lists, and fix style
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
1770 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
1771 PyObject *base;
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1772
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1773 (void)strcpy(cname, modulename);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1774 (void)strcat(cname, ".");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1775 (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
1776
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1777 if (exctable[i].base == 0)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1778 base = PyExc_StandardError;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1779 else
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1780 base = *exctable[i].base;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1781
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1782 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
1783 exctable[i].methods,
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1784 exctable[i].docstr);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1785
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1786 PyMem_DEL(cname);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1787
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1788 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1789 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
1790
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1791 if (exctable[i].classinit) {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1792 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
1793 if (status)
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1794 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
1795 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1796
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1797 /* 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
1798 * module.
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 (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
1801 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
1802 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1803 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
1804 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1805 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1806
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1807 /* Now we need to pre-allocate a MemoryError instance */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1808 args = Py_BuildValue("()");
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1809 if (!args ||
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1810 !(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
1811 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1812 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
1813 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1814 Py_DECREF(args);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1815
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1816 /* We're done with __builtin__ */
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1817 Py_DECREF(bltinmod);
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
24420
36e2fd3f08f7 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
1821 void
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 17597
diff changeset
1822 _PyExc_Fini(void)
12771
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1823 {
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1824 int i;
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_XDECREF(PyExc_MemoryErrorInst);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1827 PyExc_MemoryErrorInst = NULL;
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 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
1830 /* 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
1831 * between the class and its methods.
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1832 */
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1833 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
1834 PyDict_Clear(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1835 Py_DECREF(cdict);
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1836
2208a03d05a3 Leak pluggin', bug fixin' and better documentin'. Specifically,
Barry Warsaw <barry@python.org>
parents: 15590
diff changeset
1837 /* 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
1838 Py_XDECREF(*exctable[i].exc);
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1839 *exctable[i].exc = NULL;
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1840 }
52c6ac2d16a8 The standard exception classes. Moved here from ../Modules/_exceptions.c
Barry Warsaw <barry@python.org>
parents:
diff changeset
1841 }