* supply a more useful error message when append() is called on the

wrong type of database in dbshelve.
* fix a typo in the exception name when checking args
This commit is contained in:
Gregory P. Smith 2004-03-16 18:50:26 +00:00
parent bce64ec086
commit 1281f76606
1 changed files with 8 additions and 2 deletions

View 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):