| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | /* This module provides the suite of standard class-based exceptions for
 | 
					
						
							|  |  |  |  |  * Python's builtin module.  This is a complete C implementation of what, | 
					
						
							|  |  |  |  |  * in Python 1.5.2, was contained in the exceptions.py module.  The problem | 
					
						
							|  |  |  |  |  * there was that if exceptions.py could not be imported for some reason, | 
					
						
							|  |  |  |  |  * the entire interpreter would abort. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * By moving the exceptions into C and statically linking, we can guarantee | 
					
						
							|  |  |  |  |  * that the standard exceptions will always be available. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * history: | 
					
						
							|  |  |  |  |  * 98-08-19    fl   created (for pyexe) | 
					
						
							|  |  |  |  |  * 00-02-08    fl   updated for 1.5.2 | 
					
						
							|  |  |  |  |  * 26-May-2000 baw  vetted for Python 1.6 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  * XXX | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * written by Fredrik Lundh | 
					
						
							|  |  |  |  |  * modifications, additions, cleanups, and proofreading by Barry Warsaw | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Copyright (c) 1998-2000 by Secret Labs AB.  All rights reserved. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
										
											2000-08-15 16:20:36 +00:00
										 |  |  |  | #include "osdefs.h"
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 04:02:10 +00:00
										 |  |  |  | /* Caution:  MS Visual C++ 6 errors if a single string literal exceeds
 | 
					
						
							|  |  |  |  |  * 2Kb.  So the module docstring has been broken roughly in half, using | 
					
						
							|  |  |  |  |  * compile-time literal concatenation. | 
					
						
							|  |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2002-03-28 20:57:51 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /* NOTE: If the exception class hierarchy changes, don't forget to update
 | 
					
						
							|  |  |  |  |  * Doc/lib/libexcs.tex! | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(module__doc__, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | "Python's standard exception class hierarchy.\n\
 | 
					
						
							|  |  |  |  | \n\ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | Exceptions found here are defined both in the exceptions module and the \n\ | 
					
						
							|  |  |  |  | built-in namespace.  It is recommended that user-defined exceptions inherit \n\ | 
					
						
							|  |  |  |  | from Exception.\n\ | 
					
						
							|  |  |  |  | " | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 04:02:10 +00:00
										 |  |  |  | 	/* keep string pieces "small" */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | /* XXX exception hierarchy from Lib/test/exception_hierarchy.txt */ | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | ); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | /* Helper function for populating a dictionary with method wrappers. */ | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | populate_methods(PyObject *klass, PyMethodDef *methods) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  |     PyObject *module; | 
					
						
							|  |  |  |  |     int status = -1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (!methods) | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  |     module = PyString_FromString("exceptions"); | 
					
						
							|  |  |  |  |     if (!module) | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     while (methods->ml_name) { | 
					
						
							|  |  |  |  | 	/* get a wrapper for the built-in function */ | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  | 	PyObject *func = PyCFunction_NewEx(methods, NULL, module); | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *meth; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!func) | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  | 	    goto status; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	/* turn the function into an unbound method */ | 
					
						
							|  |  |  |  | 	if (!(meth = PyMethod_New(func, NULL, klass))) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(func); | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  | 	    goto status; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	/* add method to dictionary */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 	status = PyObject_SetAttrString(klass, methods->ml_name, meth); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	Py_DECREF(meth); | 
					
						
							|  |  |  |  | 	Py_DECREF(func); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	/* stop now if an error occurred, otherwise do the next method */ | 
					
						
							|  |  |  |  | 	if (status) | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  | 	    goto status; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	methods++; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-01-31 18:33:18 +00:00
										 |  |  |  |     status = 0; | 
					
						
							|  |  |  |  |  status: | 
					
						
							|  |  |  |  |     Py_DECREF(module); | 
					
						
							|  |  |  |  |     return status; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | /* This function is used to create all subsequent exception classes. */ | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | make_class(PyObject **klass, PyObject *base, | 
					
						
							|  |  |  |  | 	   char *name, PyMethodDef *methods, | 
					
						
							|  |  |  |  | 	   char *docstr) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *dict = PyDict_New(); | 
					
						
							|  |  |  |  |     PyObject *str = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     int status = -1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!dict) | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* If an error occurs from here on, goto finally instead of explicitly
 | 
					
						
							|  |  |  |  |      * returning NULL. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (docstr) { | 
					
						
							|  |  |  |  | 	if (!(str = PyString_FromString(docstr))) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	if (PyDict_SetItemString(dict, "__doc__", str)) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(*klass = PyErr_NewException(name, base, dict))) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (populate_methods(*klass, methods)) { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	Py_DECREF(*klass); | 
					
						
							|  |  |  |  | 	*klass = NULL; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 	goto finally; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     status = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_XDECREF(dict); | 
					
						
							|  |  |  |  |     Py_XDECREF(str); | 
					
						
							|  |  |  |  |     return status; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /* Use this for *args signatures, otherwise just use PyArg_ParseTuple() */ | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | get_self(PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *self = PyTuple_GetItem(args, 0); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (!self) { | 
					
						
							| 
									
										
										
										
											2000-07-16 12:04:32 +00:00
										 |  |  |  | 	/* Watch out for being called to early in the bootstrapping process */ | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	if (PyExc_TypeError) { | 
					
						
							|  |  |  |  | 	    PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2000-10-24 19:57:45 +00:00
										 |  |  |  | 	     "unbound method must be called with instance as first argument"); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  |         return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return self; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | /* Notes on bootstrapping the exception classes.
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * First thing we create is the base class for all exceptions, called | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  * appropriately BaseException.  Creation of this class makes no | 
					
						
							| 
									
										
										
										
											2000-06-30 04:59:59 +00:00
										 |  |  |  |  * assumptions about the existence of any other exception class -- except | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  * for TypeError, which can conditionally exist. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  * Next, Exception is created since it is the common subclass for the rest of | 
					
						
							|  |  |  |  |  * the needed exceptions for this bootstrapping to work.  StandardError is | 
					
						
							|  |  |  |  |  * created (which is quite simple) followed by | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  * TypeError, because the instantiation of other exceptions can potentially | 
					
						
							|  |  |  |  |  * throw a TypeError.  Once these exceptions are created, all the others | 
					
						
							|  |  |  |  |  * can be created in any order.  See the static exctable below for the | 
					
						
							|  |  |  |  |  * explicit bootstrap order. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  * All classes after BaseException can be created using PyErr_NewException(). | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | PyDoc_STRVAR(BaseException__doc__, "Common base class for all exceptions"); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |    Set args and message attributes. | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |    Assumes self and args have already been set properly with set_self, etc. | 
					
						
							|  |  |  |  | */ | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | set_args_and_message(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     PyObject *message_val; | 
					
						
							|  |  |  |  |     Py_ssize_t args_len = PySequence_Length(args); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (args_len < 0) | 
					
						
							|  |  |  |  | 	    return 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* set args */ | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "args", args) < 0) | 
					
						
							|  |  |  |  | 	    return 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* set message */ | 
					
						
							|  |  |  |  |     if (args_len == 1) | 
					
						
							|  |  |  |  | 	    message_val = PySequence_GetItem(args, 0); | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  | 	    message_val = PyString_FromString(""); | 
					
						
							|  |  |  |  |     if (!message_val) | 
					
						
							|  |  |  |  | 	    return 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "message", message_val) < 0) { | 
					
						
							|  |  |  |  |             Py_DECREF(message_val); | 
					
						
							|  |  |  |  |             return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_DECREF(message_val); | 
					
						
							|  |  |  |  |     return 1; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | BaseException__init__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     /* set args and message attribute */ | 
					
						
							|  |  |  |  |     args = PySequence_GetSlice(args, 1, PySequence_Length(args)); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (!args) | 
					
						
							|  |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | BaseException__str__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *out; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "O:__str__", &self)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     args = PyObject_GetAttrString(self, "args"); | 
					
						
							|  |  |  |  |     if (!args) | 
					
						
							|  |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     switch (PySequence_Size(args)) { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     case 0: | 
					
						
							|  |  |  |  |         out = PyString_FromString(""); | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2000-07-09 22:27:10 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *tmp = PySequence_GetItem(args, 0); | 
					
						
							| 
									
										
										
										
											2000-07-09 22:27:10 +00:00
										 |  |  |  | 	if (tmp) { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	    out = PyObject_Str(tmp); | 
					
						
							| 
									
										
										
										
											2000-07-09 22:27:10 +00:00
										 |  |  |  | 	    Py_DECREF(tmp); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	    out = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2000-07-09 22:27:10 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-09-18 04:06:32 +00:00
										 |  |  |  |     case -1: | 
					
						
							|  |  |  |  |         PyErr_Clear(); | 
					
						
							|  |  |  |  |         /* Fall through */ | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     default: | 
					
						
							|  |  |  |  |         out = PyObject_Str(args); | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     return out; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | #ifdef Py_USING_UNICODE
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | BaseException__unicode__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Py_ssize_t args_len; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!PyArg_ParseTuple(args, "O:__unicode__", &self)) | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	args = PyObject_GetAttrString(self, "args"); | 
					
						
							|  |  |  |  | 	if (!args) | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	args_len = PySequence_Size(args); | 
					
						
							|  |  |  |  | 	if (args_len < 0) { | 
					
						
							|  |  |  |  | 		Py_DECREF(args); | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (args_len == 0) { | 
					
						
							|  |  |  |  | 		Py_DECREF(args); | 
					
						
							|  |  |  |  | 		return PyUnicode_FromUnicode(NULL, 0); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else if (args_len == 1) { | 
					
						
							|  |  |  |  | 		PyObject *temp = PySequence_GetItem(args, 0); | 
					
						
							|  |  |  |  | 		if (!temp) { | 
					
						
							|  |  |  |  | 			Py_DECREF(args); | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		Py_DECREF(args); | 
					
						
							|  |  |  |  | 		return PyObject_Unicode(temp); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else { | 
					
						
							|  |  |  |  | 		Py_DECREF(args); | 
					
						
							|  |  |  |  | 		return PyObject_Unicode(args); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | #endif /* Py_USING_UNICODE */
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | BaseException__repr__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	PyObject *args_attr; | 
					
						
							|  |  |  |  | 	Py_ssize_t args_len; | 
					
						
							|  |  |  |  | 	PyObject *repr_suffix; | 
					
						
							|  |  |  |  | 	PyObject *repr; | 
					
						
							|  |  |  |  | 	 | 
					
						
							|  |  |  |  | 	if (!PyArg_ParseTuple(args, "O:__repr__", &self)) | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	args_attr = PyObject_GetAttrString(self, "args"); | 
					
						
							|  |  |  |  | 	if (!args_attr) | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	args_len = PySequence_Length(args_attr); | 
					
						
							|  |  |  |  | 	if (args_len < 0) { | 
					
						
							|  |  |  |  | 		Py_DECREF(args_attr); | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (args_len == 0) { | 
					
						
							|  |  |  |  | 		Py_DECREF(args_attr); | 
					
						
							|  |  |  |  | 		repr_suffix = PyString_FromString("()"); | 
					
						
							|  |  |  |  | 		if (!repr_suffix) | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else { | 
					
						
							|  |  |  |  | 		PyObject *args_repr; | 
					
						
							|  |  |  |  | 		/*PyObject *right_paren;
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		repr_suffix = PyString_FromString("(*"); | 
					
						
							|  |  |  |  | 		if (!repr_suffix) { | 
					
						
							|  |  |  |  | 			Py_DECREF(args_attr); | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 		}*/ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		args_repr = PyObject_Repr(args_attr); | 
					
						
							|  |  |  |  | 		Py_DECREF(args_attr); | 
					
						
							|  |  |  |  | 		if (!args_repr) | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		repr_suffix = args_repr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		/*PyString_ConcatAndDel(&repr_suffix, args_repr);
 | 
					
						
							|  |  |  |  | 		if (!repr_suffix) | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		right_paren = PyString_FromString(")"); | 
					
						
							|  |  |  |  | 		if (!right_paren) { | 
					
						
							|  |  |  |  | 			Py_DECREF(repr_suffix); | 
					
						
							|  |  |  |  | 			return NULL; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		PyString_ConcatAndDel(&repr_suffix, right_paren); | 
					
						
							|  |  |  |  | 		if (!repr_suffix) | 
					
						
							|  |  |  |  | 			return NULL;*/ | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	repr = PyString_FromString(self->ob_type->tp_name); | 
					
						
							|  |  |  |  | 	if (!repr) { | 
					
						
							|  |  |  |  | 		Py_DECREF(repr_suffix); | 
					
						
							|  |  |  |  | 		return NULL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	PyString_ConcatAndDel(&repr, repr_suffix); | 
					
						
							|  |  |  |  | 	return repr; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | BaseException__getitem__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *out; | 
					
						
							|  |  |  |  |     PyObject *index; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "OO:__getitem__", &self, &index)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     args = PyObject_GetAttrString(self, "args"); | 
					
						
							|  |  |  |  |     if (!args) | 
					
						
							|  |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     out = PyObject_GetItem(args, index); | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     return out; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyMethodDef | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | BaseException_methods[] = { | 
					
						
							|  |  |  |  |     /* methods for the BaseException class */ | 
					
						
							|  |  |  |  |     {"__getitem__", BaseException__getitem__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__repr__", BaseException__repr__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",     BaseException__str__, METH_VARARGS}, | 
					
						
							|  |  |  |  | #ifdef Py_USING_UNICODE
 | 
					
						
							|  |  |  |  |     {"__unicode__",  BaseException__unicode__, METH_VARARGS}, | 
					
						
							|  |  |  |  | #endif /* Py_USING_UNICODE */
 | 
					
						
							|  |  |  |  |     {"__init__",    BaseException__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {NULL, NULL } | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | make_BaseException(char *modulename) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *dict = PyDict_New(); | 
					
						
							|  |  |  |  |     PyObject *str = NULL; | 
					
						
							|  |  |  |  |     PyObject *name = NULL; | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     PyObject *emptytuple = NULL; | 
					
						
							|  |  |  |  |     PyObject *argstuple = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     int status = -1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!dict) | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* If an error occurs from here on, goto finally instead of explicitly
 | 
					
						
							|  |  |  |  |      * returning NULL. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(str = PyString_FromString(modulename))) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyDict_SetItemString(dict, "__module__", str)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     Py_DECREF(str); | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(str = PyString_FromString(BaseException__doc__))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyDict_SetItemString(dict, "__doc__", str)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!(name = PyString_FromString("BaseException"))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	goto finally; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!(emptytuple = PyTuple_New(0))) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |     if (!(argstuple = PyTuple_Pack(3, name, emptytuple, dict))) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |         | 
					
						
							|  |  |  |  |     if (!(PyExc_BaseException = PyType_Type.tp_new(&PyType_Type, argstuple, | 
					
						
							|  |  |  |  | 						       	NULL))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* Now populate the dictionary with the method suite */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (populate_methods(PyExc_BaseException, BaseException_methods)) | 
					
						
							|  |  |  |  | 	/* Don't need to reclaim PyExc_BaseException here because that'll
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	 * happen during interpreter shutdown. | 
					
						
							|  |  |  |  | 	 */ | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     status = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_XDECREF(dict); | 
					
						
							|  |  |  |  |     Py_XDECREF(str); | 
					
						
							|  |  |  |  |     Py_XDECREF(name); | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     Py_XDECREF(emptytuple); | 
					
						
							|  |  |  |  |     Py_XDECREF(argstuple); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     return status; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | PyDoc_STRVAR(Exception__doc__, "Common base class for all non-exit exceptions."); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(StandardError__doc__, | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | "Base class for all standard Python exceptions that do not represent" | 
					
						
							|  |  |  |  | "interpreter exiting."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(TypeError__doc__, "Inappropriate argument type."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(StopIteration__doc__, "Signal the end from iterator.next()."); | 
					
						
							| 
									
										
										
										
											2005-08-02 00:46:46 +00:00
										 |  |  |  | PyDoc_STRVAR(GeneratorExit__doc__, "Request that a generator exit."); | 
					
						
							| 
									
										
										
										
											2001-04-20 19:13:02 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(SystemExit__doc__, "Request to exit from the interpreter."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | SystemExit__init__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *code; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     int status; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* set code attribute */ | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     switch (PySequence_Size(args)) { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     case 0: | 
					
						
							|  |  |  |  |         Py_INCREF(Py_None); | 
					
						
							|  |  |  |  |         code = Py_None; | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  |     case 1: | 
					
						
							|  |  |  |  |         code = PySequence_GetItem(args, 0); | 
					
						
							|  |  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2002-09-18 22:37:17 +00:00
										 |  |  |  |     case -1: | 
					
						
							|  |  |  |  |         PyErr_Clear(); | 
					
						
							|  |  |  |  |         /* Fall through */ | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     default: | 
					
						
							|  |  |  |  |         Py_INCREF(args); | 
					
						
							|  |  |  |  |         code = args; | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     status = PyObject_SetAttrString(self, "code", code); | 
					
						
							|  |  |  |  |     Py_DECREF(code); | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     if (status < 0) | 
					
						
							|  |  |  |  |         return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-14 17:55:09 +00:00
										 |  |  |  | static PyMethodDef SystemExit_methods[] = { | 
					
						
							| 
									
										
										
										
											2000-06-30 04:59:59 +00:00
										 |  |  |  |     { "__init__", SystemExit__init__, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(KeyboardInterrupt__doc__, "Program interrupted by user."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(ImportError__doc__, | 
					
						
							|  |  |  |  | "Import can't find module, or can't find name in module."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(EnvironmentError__doc__, "Base class for I/O related errors."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | EnvironmentError__init__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *item0 = NULL; | 
					
						
							|  |  |  |  |     PyObject *item1 = NULL; | 
					
						
							|  |  |  |  |     PyObject *item2 = NULL; | 
					
						
							|  |  |  |  |     PyObject *subslice = NULL; | 
					
						
							|  |  |  |  |     PyObject *rtnval = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "errno", Py_None) || | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	PyObject_SetAttrString(self, "strerror", Py_None) || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(self, "filename", Py_None)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     switch (PySequence_Size(args)) { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     case 3: | 
					
						
							| 
									
										
										
										
											2000-07-09 04:56:25 +00:00
										 |  |  |  | 	/* Where a function has a single filename, such as open() or some
 | 
					
						
							|  |  |  |  | 	 * of the os module functions, PyErr_SetFromErrnoWithFilename() is | 
					
						
							|  |  |  |  | 	 * called, giving a third argument which is the filename.  But, so | 
					
						
							|  |  |  |  | 	 * that old code using in-place unpacking doesn't break, e.g.: | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	 * except IOError, (errno, strerror): | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	 * we hack args so that it only contains two items.  This also | 
					
						
							|  |  |  |  | 	 * means we need our own __str__() which prints out the filename | 
					
						
							|  |  |  |  | 	 * when it was supplied. | 
					
						
							|  |  |  |  | 	 */ | 
					
						
							|  |  |  |  | 	item0 = PySequence_GetItem(args, 0); | 
					
						
							|  |  |  |  | 	item1 = PySequence_GetItem(args, 1); | 
					
						
							|  |  |  |  | 	item2 = PySequence_GetItem(args, 2); | 
					
						
							|  |  |  |  | 	if (!item0 || !item1 || !item2) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	if (PyObject_SetAttrString(self, "errno", item0) || | 
					
						
							|  |  |  |  | 	    PyObject_SetAttrString(self, "strerror", item1) || | 
					
						
							|  |  |  |  | 	    PyObject_SetAttrString(self, "filename", item2)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	subslice = PySequence_GetSlice(args, 0, 2); | 
					
						
							|  |  |  |  | 	if (!subslice || PyObject_SetAttrString(self, "args", subslice)) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							| 
									
										
										
										
											2000-07-09 04:56:25 +00:00
										 |  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2000-07-09 04:56:25 +00:00
										 |  |  |  | 	/* Used when PyErr_SetFromErrno() is called and no filename
 | 
					
						
							|  |  |  |  | 	 * argument is given. | 
					
						
							|  |  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	item0 = PySequence_GetItem(args, 0); | 
					
						
							|  |  |  |  | 	item1 = PySequence_GetItem(args, 1); | 
					
						
							|  |  |  |  | 	if (!item0 || !item1) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	if (PyObject_SetAttrString(self, "errno", item0) || | 
					
						
							|  |  |  |  | 	    PyObject_SetAttrString(self, "strerror", item1)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-09 04:56:25 +00:00
										 |  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2002-09-18 22:37:17 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     case -1: | 
					
						
							|  |  |  |  | 	PyErr_Clear(); | 
					
						
							|  |  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_INCREF(Py_None); | 
					
						
							|  |  |  |  |     rtnval = Py_None; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     Py_XDECREF(item0); | 
					
						
							|  |  |  |  |     Py_XDECREF(item1); | 
					
						
							|  |  |  |  |     Py_XDECREF(item2); | 
					
						
							|  |  |  |  |     Py_XDECREF(subslice); | 
					
						
							|  |  |  |  |     return rtnval; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | EnvironmentError__str__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *originalself = self; | 
					
						
							|  |  |  |  |     PyObject *filename; | 
					
						
							|  |  |  |  |     PyObject *serrno; | 
					
						
							|  |  |  |  |     PyObject *strerror; | 
					
						
							|  |  |  |  |     PyObject *rtnval = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "O:__str__", &self)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     filename = PyObject_GetAttrString(self, "filename"); | 
					
						
							|  |  |  |  |     serrno = PyObject_GetAttrString(self, "errno"); | 
					
						
							|  |  |  |  |     strerror = PyObject_GetAttrString(self, "strerror"); | 
					
						
							|  |  |  |  |     if (!filename || !serrno || !strerror) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (filename != Py_None) { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *fmt = PyString_FromString("[Errno %s] %s: %s"); | 
					
						
							|  |  |  |  | 	PyObject *repr = PyObject_Repr(filename); | 
					
						
							|  |  |  |  | 	PyObject *tuple = PyTuple_New(3); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!fmt || !repr || !tuple) { | 
					
						
							|  |  |  |  | 	    Py_XDECREF(fmt); | 
					
						
							|  |  |  |  | 	    Py_XDECREF(repr); | 
					
						
							|  |  |  |  | 	    Py_XDECREF(tuple); | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	PyTuple_SET_ITEM(tuple, 0, serrno); | 
					
						
							|  |  |  |  | 	PyTuple_SET_ITEM(tuple, 1, strerror); | 
					
						
							|  |  |  |  | 	PyTuple_SET_ITEM(tuple, 2, repr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	rtnval = PyString_Format(fmt, tuple); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	Py_DECREF(fmt); | 
					
						
							|  |  |  |  | 	Py_DECREF(tuple); | 
					
						
							|  |  |  |  | 	/* already freed because tuple owned only reference */ | 
					
						
							|  |  |  |  | 	serrno = NULL; | 
					
						
							|  |  |  |  | 	strerror = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else if (PyObject_IsTrue(serrno) && PyObject_IsTrue(strerror)) { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *fmt = PyString_FromString("[Errno %s] %s"); | 
					
						
							|  |  |  |  | 	PyObject *tuple = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!fmt || !tuple) { | 
					
						
							|  |  |  |  | 	    Py_XDECREF(fmt); | 
					
						
							|  |  |  |  | 	    Py_XDECREF(tuple); | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	PyTuple_SET_ITEM(tuple, 0, serrno); | 
					
						
							|  |  |  |  | 	PyTuple_SET_ITEM(tuple, 1, strerror); | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	rtnval = PyString_Format(fmt, tuple); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	Py_DECREF(fmt); | 
					
						
							|  |  |  |  | 	Py_DECREF(tuple); | 
					
						
							|  |  |  |  | 	/* already freed because tuple owned only reference */ | 
					
						
							|  |  |  |  | 	serrno = NULL; | 
					
						
							|  |  |  |  | 	strerror = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  | 	/* The original Python code said:
 | 
					
						
							|  |  |  |  | 	 * | 
					
						
							|  |  |  |  | 	 *   return StandardError.__str__(self) | 
					
						
							|  |  |  |  | 	 * | 
					
						
							|  |  |  |  | 	 * but there is no StandardError__str__() function; we happen to | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 	 * know that's just a pass through to BaseException__str__(). | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 	rtnval = BaseException__str__(originalself, args); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_XDECREF(filename); | 
					
						
							|  |  |  |  |     Py_XDECREF(serrno); | 
					
						
							|  |  |  |  |     Py_XDECREF(strerror); | 
					
						
							|  |  |  |  |     return rtnval; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static | 
					
						
							|  |  |  |  | PyMethodDef EnvironmentError_methods[] = { | 
					
						
							| 
									
										
										
										
											2000-06-30 04:59:59 +00:00
										 |  |  |  |     {"__init__", EnvironmentError__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",  EnvironmentError__str__, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(IOError__doc__, "I/O operation failed."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(OSError__doc__, "OS system call failed."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | #ifdef MS_WINDOWS
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(WindowsError__doc__, "MS-Windows OS system call failed."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | #endif /* MS_WINDOWS */
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-06 12:48:53 +00:00
										 |  |  |  | #ifdef __VMS
 | 
					
						
							|  |  |  |  | static char | 
					
						
							|  |  |  |  | VMSError__doc__[] = "OpenVMS OS system call failed."; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(EOFError__doc__, "Read beyond end of file."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(RuntimeError__doc__, "Unspecified run-time error."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(NotImplementedError__doc__, | 
					
						
							|  |  |  |  | "Method or function hasn't been implemented yet."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(NameError__doc__, "Name not found globally."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(UnboundLocalError__doc__, | 
					
						
							|  |  |  |  | "Local name referenced but not bound to a value."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(AttributeError__doc__, "Attribute not found."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(SyntaxError__doc__, "Invalid syntax."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | SyntaxError__classinit__(PyObject *klass) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-08-18 05:05:37 +00:00
										 |  |  |  |     int retval = 0; | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *emptystring = PyString_FromString(""); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* Additional class-creation time initializations */ | 
					
						
							|  |  |  |  |     if (!emptystring || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(klass, "msg", emptystring) || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(klass, "filename", Py_None) || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(klass, "lineno", Py_None) || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(klass, "offset", Py_None) || | 
					
						
							| 
									
										
										
										
											2002-03-03 21:30:27 +00:00
										 |  |  |  | 	PyObject_SetAttrString(klass, "text", Py_None) || | 
					
						
							|  |  |  |  | 	PyObject_SetAttrString(klass, "print_file_and_line", Py_None)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-08-18 05:05:37 +00:00
										 |  |  |  | 	retval = -1; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-08-18 05:05:37 +00:00
										 |  |  |  |     Py_XDECREF(emptystring); | 
					
						
							|  |  |  |  |     return retval; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | SyntaxError__init__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *rtnval = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     int lenargs; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-12 13:05:33 +00:00
										 |  |  |  |     lenargs = PySequence_Size(args); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (lenargs >= 1) { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *item0 = PySequence_GetItem(args, 0); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	int status; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!item0) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 	status = PyObject_SetAttrString(self, "msg", item0); | 
					
						
							|  |  |  |  | 	Py_DECREF(item0); | 
					
						
							|  |  |  |  | 	if (status) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     if (lenargs == 2) { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	PyObject *info = PySequence_GetItem(args, 1); | 
					
						
							| 
									
										
										
										
											2001-02-28 21:52:10 +00:00
										 |  |  |  | 	PyObject *filename = NULL, *lineno = NULL; | 
					
						
							|  |  |  |  | 	PyObject *offset = NULL, *text = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	int status = 1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (!info) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	filename = PySequence_GetItem(info, 0); | 
					
						
							| 
									
										
										
										
											2001-02-28 21:52:10 +00:00
										 |  |  |  | 	if (filename != NULL) { | 
					
						
							|  |  |  |  | 	    lineno = PySequence_GetItem(info, 1); | 
					
						
							|  |  |  |  | 	    if (lineno != NULL) { | 
					
						
							|  |  |  |  | 		offset = PySequence_GetItem(info, 2); | 
					
						
							|  |  |  |  | 		if (offset != NULL) { | 
					
						
							|  |  |  |  | 		    text = PySequence_GetItem(info, 3); | 
					
						
							|  |  |  |  | 		    if (text != NULL) { | 
					
						
							|  |  |  |  | 			status = | 
					
						
							|  |  |  |  | 			    PyObject_SetAttrString(self, "filename", filename) | 
					
						
							|  |  |  |  | 			    || PyObject_SetAttrString(self, "lineno", lineno) | 
					
						
							|  |  |  |  | 			    || PyObject_SetAttrString(self, "offset", offset) | 
					
						
							|  |  |  |  | 			    || PyObject_SetAttrString(self, "text", text); | 
					
						
							|  |  |  |  | 			Py_DECREF(text); | 
					
						
							|  |  |  |  | 		    } | 
					
						
							|  |  |  |  | 		    Py_DECREF(offset); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		Py_DECREF(lineno); | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	    Py_DECREF(filename); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-02-28 21:52:10 +00:00
										 |  |  |  | 	Py_DECREF(info); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (status) | 
					
						
							|  |  |  |  | 	    goto finally; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     Py_INCREF(Py_None); | 
					
						
							|  |  |  |  |     rtnval = Py_None; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     return rtnval; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 16:20:36 +00:00
										 |  |  |  | /* This is called "my_basename" instead of just "basename" to avoid name
 | 
					
						
							|  |  |  |  |    conflicts with glibc; basename is already prototyped if _GNU_SOURCE is | 
					
						
							|  |  |  |  |    defined, and Python does define that. */ | 
					
						
							|  |  |  |  | static char * | 
					
						
							|  |  |  |  | my_basename(char *name) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	char *cp = name; | 
					
						
							|  |  |  |  | 	char *result = name; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (name == NULL) | 
					
						
							|  |  |  |  | 		return "???"; | 
					
						
							|  |  |  |  | 	while (*cp != '\0') { | 
					
						
							|  |  |  |  | 		if (*cp == SEP) | 
					
						
							|  |  |  |  | 			result = cp + 1; | 
					
						
							|  |  |  |  | 		++cp; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | SyntaxError__str__(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     PyObject *msg; | 
					
						
							|  |  |  |  |     PyObject *str; | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     PyObject *filename, *lineno, *result; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "O:__str__", &self)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(msg = PyObject_GetAttrString(self, "msg"))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     str = PyObject_Str(msg); | 
					
						
							|  |  |  |  |     Py_DECREF(msg); | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  |     result = str; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* XXX -- do all the additional formatting with filename and
 | 
					
						
							|  |  |  |  |        lineno here */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  |     if (str != NULL && PyString_Check(str)) { | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 	int have_filename = 0; | 
					
						
							|  |  |  |  | 	int have_lineno = 0; | 
					
						
							|  |  |  |  | 	char *buffer = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-16 19:43:17 +00:00
										 |  |  |  | 	if ((filename = PyObject_GetAttrString(self, "filename")) != NULL) | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 	    have_filename = PyString_Check(filename); | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	    PyErr_Clear(); | 
					
						
							| 
									
										
										
										
											2000-08-16 19:43:17 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if ((lineno = PyObject_GetAttrString(self, "lineno")) != NULL) | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 	    have_lineno = PyInt_Check(lineno); | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	    PyErr_Clear(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (have_filename || have_lineno) { | 
					
						
							| 
									
										
										
										
											2000-08-16 19:43:17 +00:00
										 |  |  |  | 	    int bufsize = PyString_GET_SIZE(str) + 64; | 
					
						
							|  |  |  |  | 	    if (have_filename) | 
					
						
							|  |  |  |  | 		bufsize += PyString_GET_SIZE(filename); | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-28 20:24:33 +00:00
										 |  |  |  | 	    buffer = PyMem_MALLOC(bufsize); | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 	    if (buffer != NULL) { | 
					
						
							|  |  |  |  | 		if (have_filename && have_lineno) | 
					
						
							| 
									
										
										
										
											2001-11-28 20:24:33 +00:00
										 |  |  |  | 		    PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", | 
					
						
							|  |  |  |  | 				  PyString_AS_STRING(str), | 
					
						
							|  |  |  |  | 				  my_basename(PyString_AS_STRING(filename)), | 
					
						
							|  |  |  |  | 				  PyInt_AsLong(lineno)); | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 		else if (have_filename) | 
					
						
							| 
									
										
										
										
											2001-11-28 20:24:33 +00:00
										 |  |  |  | 		    PyOS_snprintf(buffer, bufsize, "%s (%s)", | 
					
						
							|  |  |  |  | 				  PyString_AS_STRING(str), | 
					
						
							|  |  |  |  | 				  my_basename(PyString_AS_STRING(filename))); | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 		else if (have_lineno) | 
					
						
							| 
									
										
										
										
											2001-11-28 20:24:33 +00:00
										 |  |  |  | 		    PyOS_snprintf(buffer, bufsize, "%s (line %ld)", | 
					
						
							|  |  |  |  | 				  PyString_AS_STRING(str), | 
					
						
							|  |  |  |  | 				  PyInt_AsLong(lineno)); | 
					
						
							| 
									
										
										
										
											2000-08-16 19:43:17 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 		result = PyString_FromString(buffer); | 
					
						
							| 
									
										
										
										
											2000-08-16 19:43:17 +00:00
										 |  |  |  | 		PyMem_FREE(buffer); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-15 15:46:16 +00:00
										 |  |  |  | 		if (result == NULL) | 
					
						
							|  |  |  |  | 		    result = str; | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		    Py_DECREF(str); | 
					
						
							|  |  |  |  | 	    } | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	Py_XDECREF(filename); | 
					
						
							|  |  |  |  | 	Py_XDECREF(lineno); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return result; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-14 17:55:09 +00:00
										 |  |  |  | static PyMethodDef SyntaxError_methods[] = { | 
					
						
							| 
									
										
										
										
											2000-06-30 04:59:59 +00:00
										 |  |  |  |     {"__init__", SyntaxError__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",  SyntaxError__str__, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | KeyError__str__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *argsattr; | 
					
						
							|  |  |  |  |     PyObject *result; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!PyArg_ParseTuple(args, "O:__str__", &self)) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     argsattr = PyObject_GetAttrString(self, "args"); | 
					
						
							|  |  |  |  |     if (!argsattr) | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* If args is a tuple of exactly one item, apply repr to args[0].
 | 
					
						
							|  |  |  |  |        This is done so that e.g. the exception raised by {}[''] prints | 
					
						
							|  |  |  |  |          KeyError: '' | 
					
						
							|  |  |  |  |        rather than the confusing | 
					
						
							|  |  |  |  |          KeyError | 
					
						
							|  |  |  |  |        alone.  The downside is that if KeyError is raised with an explanatory | 
					
						
							|  |  |  |  |        string, that string will be displayed in quotes.  Too bad. | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |        If args is anything else, use the default BaseException__str__(). | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  |     */ | 
					
						
							|  |  |  |  |     if (PyTuple_Check(argsattr) && PyTuple_GET_SIZE(argsattr) == 1) { | 
					
						
							|  |  |  |  | 	PyObject *key = PyTuple_GET_ITEM(argsattr, 0); | 
					
						
							|  |  |  |  | 	result = PyObject_Repr(key); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 	result = BaseException__str__(self, args); | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_DECREF(argsattr); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyMethodDef KeyError_methods[] = { | 
					
						
							|  |  |  |  |     {"__str__",  KeyError__str__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #ifdef Py_USING_UNICODE
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | static | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int get_int(PyObject *exc, const char *name, Py_ssize_t *value) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *attr = PyObject_GetAttrString(exc, (char *)name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!attr) | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     if (PyInt_Check(attr)) { | 
					
						
							|  |  |  |  |         *value = PyInt_AS_LONG(attr); | 
					
						
							|  |  |  |  |     } else if (PyLong_Check(attr)) { | 
					
						
							|  |  |  |  | 	*value = (size_t)PyLong_AsLongLong(attr); | 
					
						
							|  |  |  |  | 	if (*value == -1) { | 
					
						
							|  |  |  |  | 		Py_DECREF(attr); | 
					
						
							|  |  |  |  | 		return -1; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2002-09-02 16:10:06 +00:00
										 |  |  |  | 	PyErr_Format(PyExc_TypeError, "%.200s attribute must be int", name); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	Py_DECREF(attr); | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     Py_DECREF(attr); | 
					
						
							|  |  |  |  |     return 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int set_ssize_t(PyObject *exc, const char *name, Py_ssize_t value) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     PyObject *obj = PyInt_FromSsize_t(value); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     int result; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!obj) | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							|  |  |  |  |     result = PyObject_SetAttrString(exc, (char *)name, obj); | 
					
						
							|  |  |  |  |     Py_DECREF(obj); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static | 
					
						
							|  |  |  |  | PyObject *get_string(PyObject *exc, const char *name) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *attr = PyObject_GetAttrString(exc, (char *)name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!attr) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  |     if (!PyString_Check(attr)) { | 
					
						
							| 
									
										
										
										
											2002-09-02 16:10:06 +00:00
										 |  |  |  | 	PyErr_Format(PyExc_TypeError, "%.200s attribute must be str", name); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	Py_DECREF(attr); | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return attr; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static | 
					
						
							|  |  |  |  | int set_string(PyObject *exc, const char *name, const char *value) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *obj = PyString_FromString(value); | 
					
						
							|  |  |  |  |     int result; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!obj) | 
					
						
							|  |  |  |  | 	return -1; | 
					
						
							|  |  |  |  |     result = PyObject_SetAttrString(exc, (char *)name, obj); | 
					
						
							|  |  |  |  |     Py_DECREF(obj); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static | 
					
						
							|  |  |  |  | PyObject *get_unicode(PyObject *exc, const char *name) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *attr = PyObject_GetAttrString(exc, (char *)name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!attr) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  |     if (!PyUnicode_Check(attr)) { | 
					
						
							| 
									
										
										
										
											2002-09-02 16:10:06 +00:00
										 |  |  |  | 	PyErr_Format(PyExc_TypeError, "%.200s attribute must be unicode", name); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	Py_DECREF(attr); | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return attr; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject * PyUnicodeEncodeError_GetEncoding(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "encoding"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject * PyUnicodeDecodeError_GetEncoding(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "encoding"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeEncodeError_GetObject(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_unicode(exc, "object"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeDecodeError_GetObject(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "object"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeTranslateError_GetObject(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_unicode(exc, "object"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     if (!get_int(exc, "start", start)) { | 
					
						
							|  |  |  |  | 	PyObject *object = PyUnicodeEncodeError_GetObject(exc); | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	Py_ssize_t size; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	if (!object) | 
					
						
							|  |  |  |  | 	    return -1; | 
					
						
							|  |  |  |  | 	size = PyUnicode_GET_SIZE(object); | 
					
						
							|  |  |  |  | 	if (*start<0) | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	    *start = 0; /*XXX check for values <0*/ | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	if (*start>=size) | 
					
						
							|  |  |  |  | 	    *start = size-1; | 
					
						
							|  |  |  |  | 	Py_DECREF(object); | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return -1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     if (!get_int(exc, "start", start)) { | 
					
						
							|  |  |  |  | 	PyObject *object = PyUnicodeDecodeError_GetObject(exc); | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	Py_ssize_t size; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	if (!object) | 
					
						
							|  |  |  |  | 	    return -1; | 
					
						
							|  |  |  |  | 	size = PyString_GET_SIZE(object); | 
					
						
							|  |  |  |  | 	if (*start<0) | 
					
						
							|  |  |  |  | 	    *start = 0; | 
					
						
							|  |  |  |  | 	if (*start>=size) | 
					
						
							|  |  |  |  | 	    *start = size-1; | 
					
						
							|  |  |  |  | 	Py_DECREF(object); | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return -1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     return PyUnicodeEncodeError_GetStart(exc, start); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "start", start); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "start", start); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "start", start); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     if (!get_int(exc, "end", end)) { | 
					
						
							|  |  |  |  | 	PyObject *object = PyUnicodeEncodeError_GetObject(exc); | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	Py_ssize_t size; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	if (!object) | 
					
						
							|  |  |  |  | 	    return -1; | 
					
						
							|  |  |  |  | 	size = PyUnicode_GET_SIZE(object); | 
					
						
							|  |  |  |  | 	if (*end<1) | 
					
						
							|  |  |  |  | 	    *end = 1; | 
					
						
							|  |  |  |  | 	if (*end>size) | 
					
						
							|  |  |  |  | 	    *end = size; | 
					
						
							|  |  |  |  | 	Py_DECREF(object); | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return -1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     if (!get_int(exc, "end", end)) { | 
					
						
							|  |  |  |  | 	PyObject *object = PyUnicodeDecodeError_GetObject(exc); | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	Py_ssize_t size; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	if (!object) | 
					
						
							|  |  |  |  | 	    return -1; | 
					
						
							|  |  |  |  | 	size = PyString_GET_SIZE(object); | 
					
						
							|  |  |  |  | 	if (*end<1) | 
					
						
							|  |  |  |  | 	    *end = 1; | 
					
						
							|  |  |  |  | 	if (*end>size) | 
					
						
							|  |  |  |  | 	    *end = size; | 
					
						
							|  |  |  |  | 	Py_DECREF(object); | 
					
						
							|  |  |  |  | 	return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return -1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     return PyUnicodeEncodeError_GetEnd(exc, start); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "end", end); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "end", end); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return set_ssize_t(exc, "end", end); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeEncodeError_GetReason(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "reason"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeDecodeError_GetReason(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "reason"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyUnicodeTranslateError_GetReason(PyObject *exc) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return get_string(exc, "reason"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | int PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return set_string(exc, "reason", reason); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | int PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return set_string(exc, "reason", reason); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | int PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return set_string(exc, "reason", reason); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeError__init__(PyObject *self, PyObject *args, PyTypeObject *objecttype) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *rtnval = NULL; | 
					
						
							|  |  |  |  |     PyObject *encoding; | 
					
						
							|  |  |  |  |     PyObject *object; | 
					
						
							|  |  |  |  |     PyObject *start; | 
					
						
							|  |  |  |  |     PyObject *end; | 
					
						
							|  |  |  |  |     PyObject *reason; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "O!O!O!O!O!", | 
					
						
							|  |  |  |  | 	&PyString_Type, &encoding, | 
					
						
							|  |  |  |  | 	objecttype, &object, | 
					
						
							|  |  |  |  | 	&PyInt_Type, &start, | 
					
						
							|  |  |  |  | 	&PyInt_Type, &end, | 
					
						
							|  |  |  |  | 	&PyString_Type, &reason)) | 
					
						
							| 
									
										
										
										
											2003-08-14 20:59:07 +00:00
										 |  |  |  | 	goto finally; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "encoding", encoding)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "object", object)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "start", start)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "end", end)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "reason", reason)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_INCREF(Py_None); | 
					
						
							|  |  |  |  |     rtnval = Py_None; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     return rtnval; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeEncodeError__init__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return UnicodeError__init__(self, args, &PyUnicode_Type); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeEncodeError__str__(PyObject *self, PyObject *arg) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *encodingObj = NULL; | 
					
						
							|  |  |  |  |     PyObject *objectObj = NULL; | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     Py_ssize_t start; | 
					
						
							|  |  |  |  |     Py_ssize_t end; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     PyObject *reasonObj = NULL; | 
					
						
							|  |  |  |  |     PyObject *result = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     self = arg; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(encodingObj = PyUnicodeEncodeError_GetEncoding(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(objectObj = PyUnicodeEncodeError_GetObject(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeEncodeError_GetStart(self, &start)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeEncodeError_GetEnd(self, &end)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(reasonObj = PyUnicodeEncodeError_GetReason(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (end==start+1) { | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start]; | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	char badchar_str[20]; | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	if (badchar <= 0xff) | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	else if (badchar <= 0xffff) | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); | 
					
						
							|  |  |  |  | 	result = PyString_FromFormat( | 
					
						
							|  |  |  |  | 	    "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(encodingObj), | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    badchar_str, | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    start, | 
					
						
							|  |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	result = PyString_FromFormat( | 
					
						
							|  |  |  |  | 	    "'%.400s' codec can't encode characters in position %zd-%zd: %.400s", | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(encodingObj), | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    start, | 
					
						
							|  |  |  |  | 	    (end-1), | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | error: | 
					
						
							|  |  |  |  |     Py_XDECREF(reasonObj); | 
					
						
							|  |  |  |  |     Py_XDECREF(objectObj); | 
					
						
							|  |  |  |  |     Py_XDECREF(encodingObj); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyMethodDef UnicodeEncodeError_methods[] = { | 
					
						
							|  |  |  |  |     {"__init__", UnicodeEncodeError__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",  UnicodeEncodeError__str__, METH_O}, | 
					
						
							|  |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject * PyUnicodeEncodeError_Create( | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	const char *encoding, const Py_UNICODE *object, Py_ssize_t length, | 
					
						
							|  |  |  |  | 	Py_ssize_t start, Py_ssize_t end, const char *reason) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	encoding, object, length, start, end, reason); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeDecodeError__init__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     return UnicodeError__init__(self, args, &PyString_Type); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeDecodeError__str__(PyObject *self, PyObject *arg) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *encodingObj = NULL; | 
					
						
							|  |  |  |  |     PyObject *objectObj = NULL; | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     Py_ssize_t start; | 
					
						
							|  |  |  |  |     Py_ssize_t end; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     PyObject *reasonObj = NULL; | 
					
						
							|  |  |  |  |     PyObject *result = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     self = arg; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(encodingObj = PyUnicodeDecodeError_GetEncoding(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(objectObj = PyUnicodeDecodeError_GetObject(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeDecodeError_GetStart(self, &start)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeDecodeError_GetEnd(self, &end)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(reasonObj = PyUnicodeDecodeError_GetReason(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (end==start+1) { | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	/* FromFormat does not support %02x, so format that separately */ | 
					
						
							|  |  |  |  | 	char byte[4]; | 
					
						
							|  |  |  |  | 	PyOS_snprintf(byte, sizeof(byte), "%02x",  | 
					
						
							|  |  |  |  | 		      ((int)PyString_AS_STRING(objectObj)[start])&0xff); | 
					
						
							|  |  |  |  | 	result = PyString_FromFormat(				      | 
					
						
							|  |  |  |  | 	    "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(encodingObj), | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    byte, | 
					
						
							|  |  |  |  | 	    start, | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	result = PyString_FromFormat( | 
					
						
							|  |  |  |  | 	    "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s", | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(encodingObj), | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    start, | 
					
						
							|  |  |  |  | 	    (end-1), | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | error: | 
					
						
							|  |  |  |  |     Py_XDECREF(reasonObj); | 
					
						
							|  |  |  |  |     Py_XDECREF(objectObj); | 
					
						
							|  |  |  |  |     Py_XDECREF(encodingObj); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyMethodDef UnicodeDecodeError_methods[] = { | 
					
						
							|  |  |  |  |     {"__init__", UnicodeDecodeError__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",  UnicodeDecodeError__str__, METH_O}, | 
					
						
							|  |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject * PyUnicodeDecodeError_Create( | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	const char *encoding, const char *object, Py_ssize_t length, | 
					
						
							|  |  |  |  | 	Py_ssize_t start, Py_ssize_t end, const char *reason) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	assert(length < INT_MAX); | 
					
						
							|  |  |  |  | 	assert(start < INT_MAX); | 
					
						
							|  |  |  |  | 	assert(end < INT_MAX); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#iis", | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	encoding, object, (int)length, (int)start, (int)end, reason); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeTranslateError__init__(PyObject *self, PyObject *args) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *rtnval = NULL; | 
					
						
							|  |  |  |  |     PyObject *object; | 
					
						
							|  |  |  |  |     PyObject *start; | 
					
						
							|  |  |  |  |     PyObject *end; | 
					
						
							|  |  |  |  |     PyObject *reason; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(self = get_self(args))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) | 
					
						
							|  |  |  |  | 	return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (!set_args_and_message(self, args)) { | 
					
						
							|  |  |  |  | 	    Py_DECREF(args); | 
					
						
							|  |  |  |  | 	    return NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     if (!PyArg_ParseTuple(args, "O!O!O!O!", | 
					
						
							|  |  |  |  | 	&PyUnicode_Type, &object, | 
					
						
							|  |  |  |  | 	&PyInt_Type, &start, | 
					
						
							|  |  |  |  | 	&PyInt_Type, &end, | 
					
						
							|  |  |  |  | 	&PyString_Type, &reason)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "object", object)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "start", start)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "end", end)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  |     if (PyObject_SetAttrString(self, "reason", reason)) | 
					
						
							|  |  |  |  | 	goto finally; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     rtnval = Py_None; | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     Py_INCREF(rtnval); | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   finally: | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  |     return rtnval; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyObject * | 
					
						
							|  |  |  |  | UnicodeTranslateError__str__(PyObject *self, PyObject *arg) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     PyObject *objectObj = NULL; | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     Py_ssize_t start; | 
					
						
							|  |  |  |  |     Py_ssize_t end; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |     PyObject *reasonObj = NULL; | 
					
						
							|  |  |  |  |     PyObject *result = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     self = arg; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(objectObj = PyUnicodeTranslateError_GetObject(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeTranslateError_GetStart(self, &start)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (PyUnicodeTranslateError_GetEnd(self, &end)) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (!(reasonObj = PyUnicodeTranslateError_GetReason(self))) | 
					
						
							|  |  |  |  | 	goto error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if (end==start+1) { | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start]; | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	char badchar_str[20]; | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	if (badchar <= 0xff) | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	else if (badchar <= 0xffff) | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); | 
					
						
							| 
									
										
										
										
											2003-08-12 17:32:43 +00:00
										 |  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	    PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); | 
					
						
							|  |  |  |  | 	result = PyString_FromFormat( | 
					
						
							|  |  |  |  |             "can't translate character u'\\%s' in position %zd: %.400s", | 
					
						
							|  |  |  |  | 	    badchar_str, | 
					
						
							|  |  |  |  | 	    start, | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2006-02-16 07:11:33 +00:00
										 |  |  |  | 	result = PyString_FromFormat( | 
					
						
							|  |  |  |  | 	    "can't translate characters in position %zd-%zd: %.400s", | 
					
						
							|  |  |  |  | 	    start, | 
					
						
							|  |  |  |  | 	    (end-1), | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 	    PyString_AS_STRING(reasonObj) | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | error: | 
					
						
							|  |  |  |  |     Py_XDECREF(reasonObj); | 
					
						
							|  |  |  |  |     Py_XDECREF(objectObj); | 
					
						
							|  |  |  |  |     return result; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static PyMethodDef UnicodeTranslateError_methods[] = { | 
					
						
							|  |  |  |  |     {"__init__", UnicodeTranslateError__init__, METH_VARARGS}, | 
					
						
							|  |  |  |  |     {"__str__",  UnicodeTranslateError__str__, METH_O}, | 
					
						
							|  |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject * PyUnicodeTranslateError_Create( | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  | 	const Py_UNICODE *object, Py_ssize_t length, | 
					
						
							|  |  |  |  | 	Py_ssize_t start, Py_ssize_t end, const char *reason) | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#iis", | 
					
						
							|  |  |  |  | 	object, length, start, end, reason); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | /* Exception doc strings */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(AssertionError__doc__, "Assertion failed."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(LookupError__doc__, "Base class for lookup errors."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(IndexError__doc__, "Sequence index out of range."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(KeyError__doc__, "Mapping key not found."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(ArithmeticError__doc__, "Base class for arithmetic errors."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(OverflowError__doc__, "Result too large to be represented."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(ZeroDivisionError__doc__, | 
					
						
							|  |  |  |  | "Second argument to a division or modulo operation was zero."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(FloatingPointError__doc__, "Floating point operation failed."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(ValueError__doc__, | 
					
						
							|  |  |  |  | "Inappropriate argument value (of correct type)."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(UnicodeError__doc__, "Unicode related error."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #ifdef Py_USING_UNICODE
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | PyDoc_STRVAR(UnicodeEncodeError__doc__, "Unicode encoding error."); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyDoc_STRVAR(UnicodeDecodeError__doc__, "Unicode decoding error."); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyDoc_STRVAR(UnicodeTranslateError__doc__, "Unicode translation error."); | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(SystemError__doc__, | 
					
						
							|  |  |  |  | "Internal error in the Python interpreter.\n\
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | \n\ | 
					
						
							|  |  |  |  | Please report this to the Python maintainer, along with the traceback,\n\ | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | the Python version, and the hardware/OS platform and version."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(ReferenceError__doc__, | 
					
						
							|  |  |  |  | "Weak ref proxy used after referent went away."); | 
					
						
							| 
									
										
										
										
											2001-10-05 21:50:08 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(MemoryError__doc__, "Out of memory."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(IndentationError__doc__, "Improper indentation."); | 
					
						
							| 
									
										
										
										
											2000-07-11 17:53:00 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(TabError__doc__, "Improper mixture of spaces and tabs."); | 
					
						
							| 
									
										
										
										
											2000-07-11 17:53:00 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | /* Warning category docstrings */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(Warning__doc__, "Base class for warning categories."); | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(UserWarning__doc__, | 
					
						
							|  |  |  |  | "Base class for warnings generated by user code."); | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(DeprecationWarning__doc__, | 
					
						
							|  |  |  |  | "Base class for warnings about deprecated features."); | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(PendingDeprecationWarning__doc__, | 
					
						
							| 
									
										
										
										
											2002-05-29 15:54:55 +00:00
										 |  |  |  | "Base class for warnings about features which will be deprecated " | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | "in the future."); | 
					
						
							| 
									
										
										
										
											2002-05-29 15:54:55 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(SyntaxWarning__doc__, | 
					
						
							|  |  |  |  | "Base class for warnings about dubious syntax."); | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(OverflowWarning__doc__, | 
					
						
							| 
									
										
										
										
											2004-08-25 02:14:08 +00:00
										 |  |  |  | "Base class for warnings about numeric overflow.  Won't exist in Python 2.5."); | 
					
						
							| 
									
										
										
										
											2001-08-23 02:56:07 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  |  | PyDoc_STRVAR(RuntimeWarning__doc__, | 
					
						
							|  |  |  |  | "Base class for warnings about dubious runtime behavior."); | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-14 15:51:29 +00:00
										 |  |  |  | PyDoc_STRVAR(FutureWarning__doc__, | 
					
						
							|  |  |  |  | "Base class for warnings about constructs that will change semantically " | 
					
						
							|  |  |  |  | "in the future."); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | /* module global functions */ | 
					
						
							|  |  |  |  | static PyMethodDef functions[] = { | 
					
						
							|  |  |  |  |     /* Sentinel */ | 
					
						
							|  |  |  |  |     {NULL, NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | /* Global C API defined exceptions */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | PyObject *PyExc_BaseException; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | PyObject *PyExc_Exception; | 
					
						
							| 
									
										
										
										
											2001-04-20 19:13:02 +00:00
										 |  |  |  | PyObject *PyExc_StopIteration; | 
					
						
							| 
									
										
										
										
											2005-08-02 00:46:46 +00:00
										 |  |  |  | PyObject *PyExc_GeneratorExit; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | PyObject *PyExc_StandardError; | 
					
						
							|  |  |  |  | PyObject *PyExc_ArithmeticError; | 
					
						
							|  |  |  |  | PyObject *PyExc_LookupError; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | PyObject *PyExc_AssertionError; | 
					
						
							|  |  |  |  | PyObject *PyExc_AttributeError; | 
					
						
							|  |  |  |  | PyObject *PyExc_EOFError; | 
					
						
							|  |  |  |  | PyObject *PyExc_FloatingPointError; | 
					
						
							|  |  |  |  | PyObject *PyExc_EnvironmentError; | 
					
						
							|  |  |  |  | PyObject *PyExc_IOError; | 
					
						
							|  |  |  |  | PyObject *PyExc_OSError; | 
					
						
							|  |  |  |  | PyObject *PyExc_ImportError; | 
					
						
							|  |  |  |  | PyObject *PyExc_IndexError; | 
					
						
							|  |  |  |  | PyObject *PyExc_KeyError; | 
					
						
							|  |  |  |  | PyObject *PyExc_KeyboardInterrupt; | 
					
						
							|  |  |  |  | PyObject *PyExc_MemoryError; | 
					
						
							|  |  |  |  | PyObject *PyExc_NameError; | 
					
						
							|  |  |  |  | PyObject *PyExc_OverflowError; | 
					
						
							|  |  |  |  | PyObject *PyExc_RuntimeError; | 
					
						
							|  |  |  |  | PyObject *PyExc_NotImplementedError; | 
					
						
							|  |  |  |  | PyObject *PyExc_SyntaxError; | 
					
						
							| 
									
										
										
										
											2000-07-11 17:53:00 +00:00
										 |  |  |  | PyObject *PyExc_IndentationError; | 
					
						
							|  |  |  |  | PyObject *PyExc_TabError; | 
					
						
							| 
									
										
										
										
											2001-10-05 21:50:08 +00:00
										 |  |  |  | PyObject *PyExc_ReferenceError; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | PyObject *PyExc_SystemError; | 
					
						
							|  |  |  |  | PyObject *PyExc_SystemExit; | 
					
						
							|  |  |  |  | PyObject *PyExc_UnboundLocalError; | 
					
						
							|  |  |  |  | PyObject *PyExc_UnicodeError; | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  | PyObject *PyExc_UnicodeEncodeError; | 
					
						
							|  |  |  |  | PyObject *PyExc_UnicodeDecodeError; | 
					
						
							|  |  |  |  | PyObject *PyExc_UnicodeTranslateError; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | PyObject *PyExc_TypeError; | 
					
						
							|  |  |  |  | PyObject *PyExc_ValueError; | 
					
						
							|  |  |  |  | PyObject *PyExc_ZeroDivisionError; | 
					
						
							|  |  |  |  | #ifdef MS_WINDOWS
 | 
					
						
							|  |  |  |  | PyObject *PyExc_WindowsError; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-12-06 12:48:53 +00:00
										 |  |  |  | #ifdef __VMS
 | 
					
						
							|  |  |  |  | PyObject *PyExc_VMSError; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /* Pre-computed MemoryError instance.  Best to create this as early as
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  * possible and not wait until a MemoryError is actually raised! | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | PyObject *PyExc_MemoryErrorInst; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | /* Predefined warning categories */ | 
					
						
							|  |  |  |  | PyObject *PyExc_Warning; | 
					
						
							|  |  |  |  | PyObject *PyExc_UserWarning; | 
					
						
							|  |  |  |  | PyObject *PyExc_DeprecationWarning; | 
					
						
							| 
									
										
										
										
											2002-05-29 15:54:55 +00:00
										 |  |  |  | PyObject *PyExc_PendingDeprecationWarning; | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | PyObject *PyExc_SyntaxWarning; | 
					
						
							| 
									
										
										
										
											2004-08-25 02:14:08 +00:00
										 |  |  |  | /* PyExc_OverflowWarning should be removed for Python 2.5 */ | 
					
						
							| 
									
										
										
										
											2001-08-23 02:56:07 +00:00
										 |  |  |  | PyObject *PyExc_OverflowWarning; | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | PyObject *PyExc_RuntimeWarning; | 
					
						
							| 
									
										
										
										
											2002-08-14 15:51:29 +00:00
										 |  |  |  | PyObject *PyExc_FutureWarning; | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | /* mapping between exception names and their PyObject ** */ | 
					
						
							|  |  |  |  | static struct { | 
					
						
							|  |  |  |  |     char *name; | 
					
						
							|  |  |  |  |     PyObject **exc; | 
					
						
							|  |  |  |  |     PyObject **base;			     /* NULL == PyExc_StandardError */ | 
					
						
							|  |  |  |  |     char *docstr; | 
					
						
							|  |  |  |  |     PyMethodDef *methods; | 
					
						
							|  |  |  |  |     int (*classinit)(PyObject *); | 
					
						
							|  |  |  |  | } exctable[] = { | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  /*
 | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |   * The first four classes MUST appear in exactly this order | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  {"BaseException", &PyExc_BaseException}, | 
					
						
							|  |  |  |  |  {"Exception", &PyExc_Exception, &PyExc_BaseException, Exception__doc__}, | 
					
						
							| 
									
										
										
										
											2001-04-20 19:13:02 +00:00
										 |  |  |  |  {"StopIteration", &PyExc_StopIteration, &PyExc_Exception, | 
					
						
							|  |  |  |  |   StopIteration__doc__}, | 
					
						
							| 
									
										
										
										
											2005-08-02 00:46:46 +00:00
										 |  |  |  |  {"GeneratorExit", &PyExc_GeneratorExit, &PyExc_Exception, | 
					
						
							|  |  |  |  |   GeneratorExit__doc__}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"StandardError", &PyExc_StandardError, &PyExc_Exception, | 
					
						
							|  |  |  |  |   StandardError__doc__}, | 
					
						
							|  |  |  |  |  {"TypeError", &PyExc_TypeError, 0, TypeError__doc__}, | 
					
						
							|  |  |  |  |  /*
 | 
					
						
							|  |  |  |  |   * The rest appear in depth-first order of the hierarchy | 
					
						
							|  |  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  {"SystemExit", &PyExc_SystemExit, &PyExc_BaseException, SystemExit__doc__, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |   SystemExit_methods}, | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |  {"KeyboardInterrupt",  &PyExc_KeyboardInterrupt, &PyExc_BaseException, | 
					
						
							|  |  |  |  | 	 KeyboardInterrupt__doc__}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"ImportError",        &PyExc_ImportError,       0, ImportError__doc__}, | 
					
						
							|  |  |  |  |  {"EnvironmentError",   &PyExc_EnvironmentError,  0, EnvironmentError__doc__, | 
					
						
							|  |  |  |  |   EnvironmentError_methods}, | 
					
						
							|  |  |  |  |  {"IOError", &PyExc_IOError, &PyExc_EnvironmentError, IOError__doc__}, | 
					
						
							|  |  |  |  |  {"OSError", &PyExc_OSError, &PyExc_EnvironmentError, OSError__doc__}, | 
					
						
							|  |  |  |  | #ifdef MS_WINDOWS
 | 
					
						
							| 
									
										
										
										
											2000-08-15 00:37:32 +00:00
										 |  |  |  |  {"WindowsError", &PyExc_WindowsError, &PyExc_OSError, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |   WindowsError__doc__}, | 
					
						
							|  |  |  |  | #endif /* MS_WINDOWS */
 | 
					
						
							| 
									
										
										
										
											2002-12-06 12:48:53 +00:00
										 |  |  |  | #ifdef __VMS
 | 
					
						
							|  |  |  |  |  {"VMSError", &PyExc_VMSError, &PyExc_OSError, | 
					
						
							|  |  |  |  |   VMSError__doc__}, | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"EOFError",     &PyExc_EOFError,     0, EOFError__doc__}, | 
					
						
							|  |  |  |  |  {"RuntimeError", &PyExc_RuntimeError, 0, RuntimeError__doc__}, | 
					
						
							|  |  |  |  |  {"NotImplementedError", &PyExc_NotImplementedError, | 
					
						
							|  |  |  |  |   &PyExc_RuntimeError, NotImplementedError__doc__}, | 
					
						
							|  |  |  |  |  {"NameError",    &PyExc_NameError,    0, NameError__doc__}, | 
					
						
							|  |  |  |  |  {"UnboundLocalError", &PyExc_UnboundLocalError, &PyExc_NameError, | 
					
						
							|  |  |  |  |   UnboundLocalError__doc__}, | 
					
						
							|  |  |  |  |  {"AttributeError",     &PyExc_AttributeError, 0, AttributeError__doc__}, | 
					
						
							|  |  |  |  |  {"SyntaxError",        &PyExc_SyntaxError,    0, SyntaxError__doc__, | 
					
						
							|  |  |  |  |   SyntaxError_methods, SyntaxError__classinit__}, | 
					
						
							| 
									
										
										
										
											2000-07-11 17:53:00 +00:00
										 |  |  |  |  {"IndentationError",   &PyExc_IndentationError, &PyExc_SyntaxError, | 
					
						
							|  |  |  |  |   IndentationError__doc__}, | 
					
						
							|  |  |  |  |  {"TabError",   &PyExc_TabError, &PyExc_IndentationError, | 
					
						
							|  |  |  |  |   TabError__doc__}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"AssertionError",     &PyExc_AssertionError, 0, AssertionError__doc__}, | 
					
						
							|  |  |  |  |  {"LookupError",        &PyExc_LookupError,    0, LookupError__doc__}, | 
					
						
							|  |  |  |  |  {"IndexError",         &PyExc_IndexError,     &PyExc_LookupError, | 
					
						
							|  |  |  |  |   IndexError__doc__}, | 
					
						
							|  |  |  |  |  {"KeyError",           &PyExc_KeyError,       &PyExc_LookupError, | 
					
						
							| 
									
										
										
										
											2002-09-03 20:24:09 +00:00
										 |  |  |  |   KeyError__doc__, KeyError_methods}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"ArithmeticError",    &PyExc_ArithmeticError, 0, ArithmeticError__doc__}, | 
					
						
							|  |  |  |  |  {"OverflowError",      &PyExc_OverflowError,     &PyExc_ArithmeticError, | 
					
						
							|  |  |  |  |   OverflowError__doc__}, | 
					
						
							|  |  |  |  |  {"ZeroDivisionError",  &PyExc_ZeroDivisionError,  &PyExc_ArithmeticError, | 
					
						
							|  |  |  |  |   ZeroDivisionError__doc__}, | 
					
						
							|  |  |  |  |  {"FloatingPointError", &PyExc_FloatingPointError, &PyExc_ArithmeticError, | 
					
						
							|  |  |  |  |   FloatingPointError__doc__}, | 
					
						
							|  |  |  |  |  {"ValueError",   &PyExc_ValueError,  0, ValueError__doc__}, | 
					
						
							|  |  |  |  |  {"UnicodeError", &PyExc_UnicodeError, &PyExc_ValueError, UnicodeError__doc__}, | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #ifdef Py_USING_UNICODE
 | 
					
						
							| 
									
										
										
										
											2002-09-02 13:14:32 +00:00
										 |  |  |  |  {"UnicodeEncodeError", &PyExc_UnicodeEncodeError, &PyExc_UnicodeError, | 
					
						
							|  |  |  |  |   UnicodeEncodeError__doc__, UnicodeEncodeError_methods}, | 
					
						
							|  |  |  |  |  {"UnicodeDecodeError", &PyExc_UnicodeDecodeError, &PyExc_UnicodeError, | 
					
						
							|  |  |  |  |   UnicodeDecodeError__doc__, UnicodeDecodeError_methods}, | 
					
						
							|  |  |  |  |  {"UnicodeTranslateError", &PyExc_UnicodeTranslateError, &PyExc_UnicodeError, | 
					
						
							|  |  |  |  |   UnicodeTranslateError__doc__, UnicodeTranslateError_methods}, | 
					
						
							| 
									
										
										
										
											2002-11-21 20:08:33 +00:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-10-05 21:50:08 +00:00
										 |  |  |  |  {"ReferenceError",  &PyExc_ReferenceError, 0, ReferenceError__doc__}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  {"SystemError",  &PyExc_SystemError, 0, SystemError__doc__}, | 
					
						
							|  |  |  |  |  {"MemoryError",  &PyExc_MemoryError, 0, MemoryError__doc__}, | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  |  /* Warning categories */ | 
					
						
							|  |  |  |  |  {"Warning", &PyExc_Warning, &PyExc_Exception, Warning__doc__}, | 
					
						
							|  |  |  |  |  {"UserWarning", &PyExc_UserWarning, &PyExc_Warning, UserWarning__doc__}, | 
					
						
							|  |  |  |  |  {"DeprecationWarning", &PyExc_DeprecationWarning, &PyExc_Warning, | 
					
						
							|  |  |  |  |   DeprecationWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2002-05-29 15:54:55 +00:00
										 |  |  |  |  {"PendingDeprecationWarning", &PyExc_PendingDeprecationWarning, &PyExc_Warning, | 
					
						
							|  |  |  |  |   PendingDeprecationWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  |  {"SyntaxWarning", &PyExc_SyntaxWarning, &PyExc_Warning, SyntaxWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2004-08-25 02:14:08 +00:00
										 |  |  |  |  /* OverflowWarning should be removed for Python 2.5 */ | 
					
						
							| 
									
										
										
										
											2001-08-23 02:56:07 +00:00
										 |  |  |  |  {"OverflowWarning", &PyExc_OverflowWarning, &PyExc_Warning, | 
					
						
							|  |  |  |  |   OverflowWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2000-12-15 21:58:29 +00:00
										 |  |  |  |  {"RuntimeWarning", &PyExc_RuntimeWarning, &PyExc_Warning, | 
					
						
							|  |  |  |  |   RuntimeWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2002-08-14 15:51:29 +00:00
										 |  |  |  |  {"FutureWarning", &PyExc_FutureWarning, &PyExc_Warning, | 
					
						
							|  |  |  |  |   FutureWarning__doc__}, | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |  /* Sentinel */ | 
					
						
							|  |  |  |  |  {NULL} | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-29 13:42:14 +00:00
										 |  |  |  | void | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  | _PyExc_Init(void) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  |     char *modulename = "exceptions"; | 
					
						
							| 
									
										
										
										
											2006-02-15 17:27:45 +00:00
										 |  |  |  |     Py_ssize_t modnamesz = strlen(modulename); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  |     PyObject *me, *mydict, *bltinmod, *bdict, *doc, *args; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     me = Py_InitModule(modulename, functions); | 
					
						
							|  |  |  |  |     if (me == NULL) | 
					
						
							|  |  |  |  | 	goto err; | 
					
						
							|  |  |  |  |     mydict = PyModule_GetDict(me); | 
					
						
							|  |  |  |  |     if (mydict == NULL) | 
					
						
							|  |  |  |  | 	goto err; | 
					
						
							|  |  |  |  |     bltinmod = PyImport_ImportModule("__builtin__"); | 
					
						
							|  |  |  |  |     if (bltinmod == NULL) | 
					
						
							|  |  |  |  | 	goto err; | 
					
						
							|  |  |  |  |     bdict = PyModule_GetDict(bltinmod); | 
					
						
							|  |  |  |  |     if (bdict == NULL) | 
					
						
							|  |  |  |  | 	goto err; | 
					
						
							|  |  |  |  |     doc = PyString_FromString(module__doc__); | 
					
						
							|  |  |  |  |     if (doc == NULL) | 
					
						
							|  |  |  |  | 	goto err; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     i = PyDict_SetItemString(mydict, "__doc__", doc); | 
					
						
							| 
									
										
										
										
											2000-07-01 04:45:52 +00:00
										 |  |  |  |     Py_DECREF(doc); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  |     if (i < 0) { | 
					
						
							|  |  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	Py_FatalError("exceptions bootstrapping error."); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  | 	return; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* This is the base class of all exceptions, so make it first. */ | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  |     if (make_BaseException(modulename) || | 
					
						
							|  |  |  |  | 	PyDict_SetItemString(mydict, "BaseException", PyExc_BaseException) || | 
					
						
							|  |  |  |  | 	PyDict_SetItemString(bdict, "BaseException", PyExc_BaseException)) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2006-03-01 04:25:17 +00:00
										 |  |  |  | 	Py_FatalError("Base class `BaseException' could not be created."); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     /* Now we can programmatically create all the remaining exceptions.
 | 
					
						
							|  |  |  |  |      * Remember to start the loop at 1 to skip Exceptions. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     for (i=1; exctable[i].name; i++) { | 
					
						
							|  |  |  |  | 	int status; | 
					
						
							| 
									
										
										
										
											2000-07-22 18:45:06 +00:00
										 |  |  |  | 	char *cname = PyMem_NEW(char, modnamesz+strlen(exctable[i].name)+2); | 
					
						
							|  |  |  |  | 	PyObject *base; | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	(void)strcpy(cname, modulename); | 
					
						
							|  |  |  |  | 	(void)strcat(cname, "."); | 
					
						
							|  |  |  |  | 	(void)strcat(cname, exctable[i].name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (exctable[i].base == 0) | 
					
						
							|  |  |  |  | 	    base = PyExc_StandardError; | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	    base = *exctable[i].base; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	status = make_class(exctable[i].exc, base, cname, | 
					
						
							|  |  |  |  | 			    exctable[i].methods, | 
					
						
							|  |  |  |  | 			    exctable[i].docstr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	PyMem_DEL(cname); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (status) | 
					
						
							|  |  |  |  | 	    Py_FatalError("Standard exception classes could not be created."); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (exctable[i].classinit) { | 
					
						
							|  |  |  |  | 	    status = (*exctable[i].classinit)(*exctable[i].exc); | 
					
						
							|  |  |  |  | 	    if (status) | 
					
						
							|  |  |  |  | 		Py_FatalError("An exception class could not be initialized."); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	/* Now insert the class into both this module and the __builtin__
 | 
					
						
							|  |  |  |  | 	 * module. | 
					
						
							|  |  |  |  | 	 */ | 
					
						
							|  |  |  |  | 	if (PyDict_SetItemString(mydict, exctable[i].name, *exctable[i].exc) || | 
					
						
							|  |  |  |  | 	    PyDict_SetItemString(bdict, exctable[i].name, *exctable[i].exc)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	    Py_FatalError("Module dictionary insertion problem."); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* Now we need to pre-allocate a MemoryError instance */ | 
					
						
							| 
									
										
										
										
											2003-10-12 19:09:37 +00:00
										 |  |  |  |     args = PyTuple_New(0); | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  |     if (!args || | 
					
						
							|  |  |  |  | 	!(PyExc_MemoryErrorInst = PyEval_CallObject(PyExc_MemoryError, args))) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  | 	Py_FatalError("Cannot pre-allocate MemoryError instance\n"); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     Py_DECREF(args); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /* We're done with __builtin__ */ | 
					
						
							|  |  |  |  |     Py_DECREF(bltinmod); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-29 13:42:14 +00:00
										 |  |  |  | void | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  | _PyExc_Fini(void) | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     int i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Py_XDECREF(PyExc_MemoryErrorInst); | 
					
						
							|  |  |  |  |     PyExc_MemoryErrorInst = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     for (i=0; exctable[i].name; i++) { | 
					
						
							| 
									
										
										
										
											2001-01-23 16:08:34 +00:00
										 |  |  |  | 	/* clear the class's dictionary, freeing up circular references
 | 
					
						
							|  |  |  |  | 	 * between the class and its methods. | 
					
						
							|  |  |  |  | 	 */ | 
					
						
							|  |  |  |  | 	PyObject* cdict = PyObject_GetAttrString(*exctable[i].exc, "__dict__"); | 
					
						
							|  |  |  |  | 	PyDict_Clear(cdict); | 
					
						
							|  |  |  |  | 	Py_DECREF(cdict); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	/* Now decref the exception class */ | 
					
						
							| 
									
										
										
										
											2000-05-26 19:05:16 +00:00
										 |  |  |  | 	Py_XDECREF(*exctable[i].exc); | 
					
						
							|  |  |  |  | 	*exctable[i].exc = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |