]> granicus.if.org Git - python/commitdiff
Demand version 2.5.1 since 2.5 has a bug with codecs.open context managers.
authorGeorg Brandl <georg@python.org>
Tue, 21 Aug 2007 06:01:18 +0000 (06:01 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 21 Aug 2007 06:01:18 +0000 (06:01 +0000)
Doc/tools/sphinx-build.py
Lib/test/test_exceptions.py
Objects/exceptions.c
Python/import.c

index e19b10a04a86f3d5b91ac8a8cde7fdc45f363984..8f952be22bc00e7624139034b6011982375e3ad6 100644 (file)
@@ -11,9 +11,9 @@ import sys
 
 if __name__ == '__main__':
 
-    if sys.version_info[:3] < (2, 5, 0):
+    if sys.version_info[:3] < (2, 5, 1):
         print >>sys.stderr, """\
-Error: Sphinx needs to be executed with Python 2.5 or newer
+Error: Sphinx needs to be executed with Python 2.5.1 or newer
 (If you run this from the Makefile, you can set the PYTHON variable
 to the path of an alternative interpreter executable, e.g.,
 ``make html PYTHON=python2.5``).
index 657cbc532704ed53a73df8fbabfd4c1646076b19..2f57f3df5040145a9ea69cb98a8fd3e78cfadff7 100644 (file)
@@ -9,6 +9,16 @@ from test.test_support import (TESTFN, unlink, run_unittest,
                                 catch_warning)
 from test.test_pep352 import ignore_message_warning
 
+class NaiveException(Exception):
+    def __init__(self, x):
+        self.x = x
+
+class SomewhatNaiveException(Exception):
+    def __init__(self, x):
+        self.x = x
+        Exception.__init__(self)
+
+
 # XXX This is not really enough, each *operation* should be tested!
 
 class ExceptionTests(unittest.TestCase):
@@ -263,6 +273,10 @@ class ExceptionTests(unittest.TestCase):
                 {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
                  'object' : u'\u3042', 'reason' : 'ouch',
                  'start' : 0, 'end' : 1}),
+            (NaiveException, ('foo',),
+                {'message': '', 'args': ('foo',), 'x': 'foo'}),
+            (SomewhatNaiveException, ('foo',),
+                {'message': '', 'args': (), 'x': 'foo'}),
         ]
         try:
             exceptionList.append(
@@ -283,7 +297,8 @@ class ExceptionTests(unittest.TestCase):
                     if type(e) is not exc:
                         raise
                     # Verify module name
-                    self.assertEquals(type(e).__module__, 'exceptions')
+                    if not type(e).__name__.endswith('NaiveException'):
+                        self.assertEquals(type(e).__module__, 'exceptions')
                     # Verify no ref leaks in Exc_str()
                     s = str(e)
                     for checkArgName in expected:
index 3d79383d3edae43f2f9a398144ea976e5e714a7e..103a6625ba07e4b9184057e3e7d34b3f6fbe8ce7 100644 (file)
@@ -38,18 +38,31 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
     /* the dict is created on the fly in PyObject_GenericSetAttr */
     self->message = self->dict = NULL;
 
-    self->args = PyTuple_New(0);
-    if (!self->args) {
+    if (!args) {
+        /* MemoryError instantiation */
+        args = PyTuple_New(0);
+        if (!args) {
+            Py_DECREF(self);
+            return NULL;
+        }
+    } else {
+        Py_INCREF(args);
+    }
+    
+    self->args = args;
+
+    /* Since the args can be overwritten in __init__, we have to store
+       the original args somewhere for pickling. */
+    if (PyObject_SetAttrString((PyObject *)self, "__newargs__", args) < 0) {
         Py_DECREF(self);
         return NULL;
     }
-
+   
     self->message = PyString_FromString("");
     if (!self->message) {
         Py_DECREF(self);
         return NULL;
     }
-
     return (PyObject *)self;
 }
 
@@ -147,10 +160,23 @@ BaseException_repr(PyBaseExceptionObject *self)
 static PyObject *
 BaseException_reduce(PyBaseExceptionObject *self)
 {
+    PyObject *result;
+    PyObject *newargs = PyObject_GetAttrString((PyObject *)self, "__newargs__");
+    if (!newargs) {
+        if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+            PyErr_SetString(PyExc_AttributeError,
+                            "To pickle exceptions via BaseException.__reduce__, "
+                            "you need to set the __newargs__ attribute in your "
+                            "custom __new__ method.");
+        }
+        return NULL;
+    }
     if (self->args && self->dict)
-        return PyTuple_Pack(3, Py_Type(self), self->args, self->dict);
+        result = PyTuple_Pack(3, Py_Type(self), newargs, self->dict);
     else
-        return PyTuple_Pack(2, Py_Type(self), self->args);
+        result = PyTuple_Pack(2, Py_Type(self), newargs);
+    Py_DECREF(newargs);
+    return result;
 }
 
 /*
index 678a30b62039d372cd27b78a9e993b9cb8c8aa4a..dc979404de16a479640b56cad0836503746649f1 100644 (file)
@@ -1395,6 +1395,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
                        filemode = fdp->mode;
                        if (filemode[0] == 'U')
                                filemode = "r" PY_STDIOTEXTMODE;
+                       errno = 0;
                        fp = fopen(buf, filemode);
                        if (fp != NULL) {
                                if (case_ok(buf, len, namelen, name))
@@ -1404,6 +1405,15 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
                                        fp = NULL;
                                }
                        }
+                       /* issue a warning if the file is there */
+                       /*if (errno != ENOENT) {
+                               char warnstr[MAXPATHLEN+80];
+                               sprintf(warnstr, "Not importing '%.*s': ");
+                               
+                               if (PyErr_Warn(PyExc_ImportWarning,
+                                              warnstr)) {
+
+                       }*/
 #if defined(PYOS_OS2)
                        /* restore the saved snapshot */
                        strcpy(buf, saved_buf);