[Python-checkins] r54049 - in python/branches/p3yk_no_args_on_exc: BROKEN Lib/bsddb/dbtables.py Lib/bsddb/test/test_basics.py Lib/bsddb/test/test_recno.py Python/errors.c

brett.cannon python-checkins at python.org
Thu Mar 1 01:28:28 CET 2007


Author: brett.cannon
Date: Thu Mar  1 01:28:20 2007
New Revision: 54049

Modified:
   python/branches/p3yk_no_args_on_exc/BROKEN
   python/branches/p3yk_no_args_on_exc/Lib/bsddb/dbtables.py
   python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_basics.py
   python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_recno.py
   python/branches/p3yk_no_args_on_exc/Python/errors.c
Log:
Fix test_bsddb and test_bsddb3 (still one failure, but it doesn't look like it
is from this work).  Had to revert part of r54046 where PyErr_SetFromErrno()
was being wrapped in another tuple since it messed up IOError.

This means that socket.error needs to be rewritten so that it takes up to two
arguments and does the right thing when calling Exception.__init__.  See _bsddb
for possible inspiration on how to do this in Python code within a C extension
module.


Modified: python/branches/p3yk_no_args_on_exc/BROKEN
==============================================================================
--- python/branches/p3yk_no_args_on_exc/BROKEN	(original)
+++ python/branches/p3yk_no_args_on_exc/BROKEN	Thu Mar  1 01:28:20 2007
@@ -2,4 +2,8 @@
   thus constructor gets passed two arguments (thanks to
   PyErr_NormalizeException() passing any tuple given to it as a value as the
   args tuple, but not when it is any other type of value).
-    + test_bsddb3 (?)
+    + test_socket
+    + test_socket_ssl
+    + test_timeout
+    + test_urllib2net 
+    + test_urllibnet

Modified: python/branches/p3yk_no_args_on_exc/Lib/bsddb/dbtables.py
==============================================================================
--- python/branches/p3yk_no_args_on_exc/Lib/bsddb/dbtables.py	(original)
+++ python/branches/p3yk_no_args_on_exc/Lib/bsddb/dbtables.py	Thu Mar  1 01:28:20 2007
@@ -244,7 +244,7 @@
 
             columnlist_key = _columns_key(table)
             if self.db.has_key(columnlist_key):
-                raise TableAlreadyExists, "table already exists"
+                raise TableAlreadyExists("table already exists")
 
             txn = self.env.txn_begin()
             # store the table's column info
@@ -263,7 +263,7 @@
         except DBError as dberror:
             if txn:
                 txn.abort()
-            raise TableDBError, dberror[1]
+            raise TableDBError(dberror.message[1])
 
 
     def ListTableColumns(self, table):
@@ -272,7 +272,7 @@
         """
         assert isinstance(table, StringType)
         if contains_metastrings(table):
-            raise ValueError, "bad table name: contains reserved metastrings"
+            raise ValueError("bad table name: contains reserved metastrings")
 
         columnlist_key = _columns_key(table)
         if not self.db.has_key(columnlist_key):
@@ -341,7 +341,7 @@
             except DBError as dberror:
                 if txn:
                     txn.abort()
-                raise TableDBError, dberror[1]
+                raise TableDBError(dberror.message[1])
 
 
     def __load_column_info(self, table) :
@@ -350,9 +350,9 @@
         try:
             tcolpickles = self.db.get(_columns_key(table))
         except DBNotFoundError:
-            raise TableDBError, "unknown table: %r" % (table,)
+            raise TableDBError("unknown table: %r" % (table,))
         if not tcolpickles:
-            raise TableDBError, "unknown table: %r" % (table,)
+            raise TableDBError("unknown table: %r" % (table,))
         self.__tablecolumns[table] = pickle.loads(tcolpickles)
 
     def __new_rowid(self, table, txn) :
@@ -416,7 +416,7 @@
             if txn:
                 txn.abort()
                 self.db.delete(_rowid_key(table, rowid))
-            raise TableDBError, dberror[1], info[2]
+            raise TableDBError((dberror.message[1], info[2]))
 
 
     def Modify(self, table, conditions={}, mappings={}):
@@ -467,7 +467,7 @@
                     raise
 
         except DBError as dberror:
-            raise TableDBError, dberror[1]
+            raise TableDBError(dberror.message[1])
 
     def Delete(self, table, conditions={}):
         """Delete(table, conditions) - Delete items matching the given
@@ -507,7 +507,7 @@
                         txn.abort()
                     raise
         except DBError as dberror:
-            raise TableDBError, dberror[1]
+            raise TableDBError(dberror.message[1])
 
 
     def Select(self, table, columns, conditions={}):
@@ -527,7 +527,7 @@
                 columns = self.__tablecolumns[table]
             matching_rowids = self.__Select(table, columns, conditions)
         except DBError as dberror:
-            raise TableDBError, dberror[1]
+            raise TableDBError(dberror.message[1])
         # return the matches as a list of dictionaries
         return matching_rowids.values()
 
@@ -617,7 +617,7 @@
                     key, data = cur.next()
 
             except DBError as dberror:
-                if dberror[0] != DB_NOTFOUND:
+                if dberror.message != DB_NOTFOUND:
                     raise
                 continue
 
@@ -703,4 +703,4 @@
         except DBError as dberror:
             if txn:
                 txn.abort()
-            raise TableDBError, dberror[1]
+            raise TableDBError(dberror.message[1])

Modified: python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_basics.py
==============================================================================
--- python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_basics.py	(original)
+++ python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_basics.py	Thu Mar  1 01:28:20 2007
@@ -163,7 +163,7 @@
         try:
             d.delete('abcd')
         except db.DBNotFoundError as val:
-            assert val[0] == db.DB_NOTFOUND
+            assert val.message[0] == db.DB_NOTFOUND
             if verbose: print(val)
         else:
             self.fail("expected exception")
@@ -182,7 +182,7 @@
         try:
             d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
         except db.DBKeyExistError as val:
-            assert val[0] == db.DB_KEYEXIST
+            assert val.message[0] == db.DB_KEYEXIST
             if verbose: print(val)
         else:
             self.fail("expected exception")
@@ -315,7 +315,7 @@
                 rec = c.next()
             except db.DBNotFoundError as val:
                 if get_raises_error:
-                    assert val[0] == db.DB_NOTFOUND
+                    assert val.message[0] == db.DB_NOTFOUND
                     if verbose: print(val)
                     rec = None
                 else:
@@ -335,7 +335,7 @@
                 rec = c.prev()
             except db.DBNotFoundError as val:
                 if get_raises_error:
-                    assert val[0] == db.DB_NOTFOUND
+                    assert val.message[0] == db.DB_NOTFOUND
                     if verbose: print(val)
                     rec = None
                 else:
@@ -358,7 +358,7 @@
         try:
             n = c.set('bad key')
         except db.DBNotFoundError as val:
-            assert val[0] == db.DB_NOTFOUND
+            assert val.message[0] == db.DB_NOTFOUND
             if verbose: print(val)
         else:
             if set_raises_error:
@@ -372,7 +372,7 @@
         try:
             n = c.get_both('0404', 'bad data')
         except db.DBNotFoundError as val:
-            assert val[0] == db.DB_NOTFOUND
+            assert val.message[0] == db.DB_NOTFOUND
             if verbose: print(val)
         else:
             if get_raises_error:
@@ -401,7 +401,7 @@
             rec = c.current()
         except db.DBKeyEmptyError as val:
             if get_raises_error:
-                assert val[0] == db.DB_KEYEMPTY
+                assert val.message[0] == db.DB_KEYEMPTY
                 if verbose: print(val)
             else:
                 self.fail("unexpected DBKeyEmptyError")
@@ -446,7 +446,7 @@
                 # a bug may cause a NULL pointer dereference...
                 getattr(c, method)(*args)
             except db.DBError as val:
-                assert val[0] == 0
+                assert val.message[0] == 0
                 if verbose: print(val)
             else:
                 self.fail("no exception raised when using a buggy cursor's"

Modified: python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_recno.py
==============================================================================
--- python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_recno.py	(original)
+++ python/branches/p3yk_no_args_on_exc/Lib/bsddb/test/test_recno.py	Thu Mar  1 01:28:20 2007
@@ -64,7 +64,7 @@
         try:
             data = d[0]  # This should raise a KeyError!?!?!
         except db.DBInvalidArgError as val:
-            assert val[0] == db.EINVAL
+            assert val.message[0] == db.EINVAL
             if verbose: print(val)
         else:
             self.fail("expected exception")
@@ -268,7 +268,7 @@
         try:                    # this one will fail
             d.append('bad' * 20)
         except db.DBInvalidArgError as val:
-            assert val[0] == db.EINVAL
+            assert val.message[0] == db.EINVAL
             if verbose: print(val)
         else:
             self.fail("expected exception")

Modified: python/branches/p3yk_no_args_on_exc/Python/errors.c
==============================================================================
--- python/branches/p3yk_no_args_on_exc/Python/errors.c	(original)
+++ python/branches/p3yk_no_args_on_exc/Python/errors.c	Thu Mar  1 01:28:20 2007
@@ -335,9 +335,9 @@
 #endif /* Unix/Windows */
 #endif /* PLAN 9*/
 	if (filenameObject != NULL)
-		v = Py_BuildValue("((isO))", i, s, filenameObject);
+		v = Py_BuildValue("(isO)", i, s, filenameObject);
 	else
-		v = Py_BuildValue("((is))", i, s);
+		v = Py_BuildValue("(is)", i, s);
 	if (v != NULL) {
 		PyErr_SetObject(exc, v);
 		Py_DECREF(v);
@@ -415,9 +415,9 @@
 			s[--len] = '\0';
 	}
 	if (filenameObject != NULL)
-		v = Py_BuildValue("((isO))", err, s, filenameObject);
+		v = Py_BuildValue("(isO)", err, s, filenameObject);
 	else
-		v = Py_BuildValue("((is))", err, s);
+		v = Py_BuildValue("(is)", err, s);
 	if (v != NULL) {
 		PyErr_SetObject(exc, v);
 		Py_DECREF(v);


More information about the Python-checkins mailing list