diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py index fd33b6e8fdd..369db43abe9 100644 --- a/Lib/bsddb/dbtables.py +++ b/Lib/bsddb/dbtables.py @@ -131,7 +131,8 @@ def contains_metastrings(s) : class bsdTableDB : def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600, recover=0, dbflags=0): - """bsdTableDB.open(filename, dbhome, create=0, truncate=0, mode=0600) + """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600) + Open database name in the dbhome BerkeleyDB directory. Use keyword arguments when calling this constructor. """ @@ -218,7 +219,8 @@ class bsdTableDB : def CreateTable(self, table, columns): - """CreateTable(table, columns) - Create a new table in the database + """CreateTable(table, columns) - Create a new table in the database. + raises TableDBError if it already exists or for other DB errors. """ assert isinstance(columns, ListType) @@ -286,7 +288,8 @@ class bsdTableDB : def CreateOrExtendTable(self, table, columns): """CreateOrExtendTable(table, columns) - - Create a new table in the database. + Create a new table in the database. + If a table of this name already exists, extend it to have any additional columns present in the given list as well as all of its current columns. @@ -411,14 +414,15 @@ class bsdTableDB : def Modify(self, table, conditions={}, mappings={}): - """Modify(table, conditions) - Modify in rows matching 'conditions' - using mapping functions in 'mappings' - * conditions is a dictionary keyed on column names - containing condition functions expecting the data string as an - argument and returning a boolean. - * mappings is a dictionary keyed on column names containint condition - functions expecting the data string as an argument and returning the - new string for that column. + """Modify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings' + + * table - the table name + * conditions - a dictionary keyed on column names containing + a condition callable expecting the data string as an + argument and returning a boolean. + * mappings - a dictionary keyed on column names containing a + condition callable expecting the data string as an argument and + returning the new string for that column. """ try: matching_rowids = self.__Select(table, [], conditions) @@ -450,7 +454,8 @@ class bsdTableDB : txn.commit() txn = None - except DBError, dberror: + # catch all exceptions here since we call unknown callables + except: if txn: txn.abort() raise @@ -461,9 +466,10 @@ class bsdTableDB : def Delete(self, table, conditions={}): """Delete(table, conditions) - Delete items matching the given conditions from the table. - * conditions is a dictionary keyed on column names - containing condition functions expecting the data string as an - argument and returning a boolean. + + * conditions - a dictionary keyed on column names containing + condition functions expecting the data string as an + argument and returning a boolean. """ try: matching_rowids = self.__Select(table, [], conditions) @@ -499,11 +505,12 @@ class bsdTableDB : def Select(self, table, columns, conditions={}): - """Select(table, conditions) - retrieve specific row data + """Select(table, columns, conditions) - retrieve specific row data Returns a list of row column->value mapping dictionaries. - * columns is a list of which column data to return. If + + * columns - a list of which column data to return. If columns is None, all columns will be returned. - * conditions is a dictionary keyed on column names + * conditions - a dictionary keyed on column names containing callable conditions expecting the data string as an argument and returning a boolean. """ diff --git a/Misc/NEWS b/Misc/NEWS index ec7570eb4fb..370a18e4b71 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -119,6 +119,10 @@ Extension Modules results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). +- bsddb: the bsddb.dbtables Modify method now raises the proper error and + aborts the db transaction safely when a modifier callback fails. + Fixes SF python patch/bug #1408584. + Library -------