]> granicus.if.org Git - python/commitdiff
* supply a more useful error message when append() is called on the
authorGregory P. Smith <greg@mad-scientist.com>
Tue, 16 Mar 2004 18:50:26 +0000 (18:50 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Tue, 16 Mar 2004 18:50:26 +0000 (18:50 +0000)
  wrong type of database in dbshelve.
* fix a typo in the exception name when checking args

Lib/bsddb/dbshelve.py

index 003038ba56e6ead349936f83bf8fde1328b96652..d341ab791092cb3c50c0efc11e7da8419f5a2ef5 100644 (file)
@@ -67,7 +67,7 @@ def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH,
         elif sflag == 'n':
             flags = db.DB_TRUNCATE | db.DB_CREATE
         else:
-            raise error, "flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags"
+            raise db.DBError, "flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags"
 
     d = DBShelf(dbenv)
     d.open(filename, dbname, filetype, flags, mode)
@@ -145,10 +145,16 @@ class DBShelf(DictMixin):
     #-----------------------------------
     # Other methods
 
-    def append(self, value, txn=None):
+    def __append(self, value, txn=None):
         data = cPickle.dumps(value, self.binary)
         return self.db.append(data, txn)
 
+    def append(self, value, txn=None):
+        if self.get_type() != db.DB_RECNO:
+            self.append = self.__append
+            return self.append(value, txn=txn)
+        raise db.DBError, "append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO"
+
 
     def associate(self, secondaryDB, callback, flags=0):
         def _shelf_callback(priKey, priData, realCallback=callback):