From 63b0cb2f39e26be7f6b636ddd40cc8d6a1400d51 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 14 Oct 2009 18:01:33 +0000 Subject: [PATCH] Fix py3k warnings in bsddb --- Lib/bsddb/dbobj.py | 192 +++++++++++++++++++++--------------------- Lib/bsddb/dbshelve.py | 4 +- Lib/bsddb/dbtables.py | 33 +++----- Lib/bsddb/dbutils.py | 2 +- 4 files changed, 112 insertions(+), 119 deletions(-) diff --git a/Lib/bsddb/dbobj.py b/Lib/bsddb/dbobj.py index f6b1d7f15d0..1e423973791 100644 --- a/Lib/bsddb/dbobj.py +++ b/Lib/bsddb/dbobj.py @@ -42,91 +42,91 @@ else : class DBEnv: def __init__(self, *args, **kwargs): - self._cobj = apply(db.DBEnv, args, kwargs) + self._cobj = db.DBEnv(*args, **kwargs) def close(self, *args, **kwargs): - return apply(self._cobj.close, args, kwargs) + return self._cobj.close(*args, **kwargs) def open(self, *args, **kwargs): - return apply(self._cobj.open, args, kwargs) + return self._cobj.open(*args, **kwargs) def remove(self, *args, **kwargs): - return apply(self._cobj.remove, args, kwargs) + return self._cobj.remove(*args, **kwargs) def set_shm_key(self, *args, **kwargs): - return apply(self._cobj.set_shm_key, args, kwargs) + return self._cobj.set_shm_key(*args, **kwargs) def set_cachesize(self, *args, **kwargs): - return apply(self._cobj.set_cachesize, args, kwargs) + return self._cobj.set_cachesize(*args, **kwargs) def set_data_dir(self, *args, **kwargs): - return apply(self._cobj.set_data_dir, args, kwargs) + return self._cobj.set_data_dir(*args, **kwargs) def set_flags(self, *args, **kwargs): - return apply(self._cobj.set_flags, args, kwargs) + return self._cobj.set_flags(*args, **kwargs) def set_lg_bsize(self, *args, **kwargs): - return apply(self._cobj.set_lg_bsize, args, kwargs) + return self._cobj.set_lg_bsize(*args, **kwargs) def set_lg_dir(self, *args, **kwargs): - return apply(self._cobj.set_lg_dir, args, kwargs) + return self._cobj.set_lg_dir(*args, **kwargs) def set_lg_max(self, *args, **kwargs): - return apply(self._cobj.set_lg_max, args, kwargs) + return self._cobj.set_lg_max(*args, **kwargs) def set_lk_detect(self, *args, **kwargs): - return apply(self._cobj.set_lk_detect, args, kwargs) + return self._cobj.set_lk_detect(*args, **kwargs) if db.version() < (4,5): def set_lk_max(self, *args, **kwargs): - return apply(self._cobj.set_lk_max, args, kwargs) + return self._cobj.set_lk_max(*args, **kwargs) def set_lk_max_locks(self, *args, **kwargs): - return apply(self._cobj.set_lk_max_locks, args, kwargs) + return self._cobj.set_lk_max_locks(*args, **kwargs) def set_lk_max_lockers(self, *args, **kwargs): - return apply(self._cobj.set_lk_max_lockers, args, kwargs) + return self._cobj.set_lk_max_lockers(*args, **kwargs) def set_lk_max_objects(self, *args, **kwargs): - return apply(self._cobj.set_lk_max_objects, args, kwargs) + return self._cobj.set_lk_max_objects(*args, **kwargs) def set_mp_mmapsize(self, *args, **kwargs): - return apply(self._cobj.set_mp_mmapsize, args, kwargs) + return self._cobj.set_mp_mmapsize(*args, **kwargs) def set_timeout(self, *args, **kwargs): - return apply(self._cobj.set_timeout, args, kwargs) + return self._cobj.set_timeout(*args, **kwargs) def set_tmp_dir(self, *args, **kwargs): - return apply(self._cobj.set_tmp_dir, args, kwargs) + return self._cobj.set_tmp_dir(*args, **kwargs) def txn_begin(self, *args, **kwargs): - return apply(self._cobj.txn_begin, args, kwargs) + return self._cobj.txn_begin(*args, **kwargs) def txn_checkpoint(self, *args, **kwargs): - return apply(self._cobj.txn_checkpoint, args, kwargs) + return self._cobj.txn_checkpoint(*args, **kwargs) def txn_stat(self, *args, **kwargs): - return apply(self._cobj.txn_stat, args, kwargs) + return self._cobj.txn_stat(*args, **kwargs) def set_tx_max(self, *args, **kwargs): - return apply(self._cobj.set_tx_max, args, kwargs) + return self._cobj.set_tx_max(*args, **kwargs) def set_tx_timestamp(self, *args, **kwargs): - return apply(self._cobj.set_tx_timestamp, args, kwargs) + return self._cobj.set_tx_timestamp(*args, **kwargs) def lock_detect(self, *args, **kwargs): - return apply(self._cobj.lock_detect, args, kwargs) + return self._cobj.lock_detect(*args, **kwargs) def lock_get(self, *args, **kwargs): - return apply(self._cobj.lock_get, args, kwargs) + return self._cobj.lock_get(*args, **kwargs) def lock_id(self, *args, **kwargs): - return apply(self._cobj.lock_id, args, kwargs) + return self._cobj.lock_id(*args, **kwargs) def lock_put(self, *args, **kwargs): - return apply(self._cobj.lock_put, args, kwargs) + return self._cobj.lock_put(*args, **kwargs) def lock_stat(self, *args, **kwargs): - return apply(self._cobj.lock_stat, args, kwargs) + return self._cobj.lock_stat(*args, **kwargs) def log_archive(self, *args, **kwargs): - return apply(self._cobj.log_archive, args, kwargs) + return self._cobj.log_archive(*args, **kwargs) def set_get_returns_none(self, *args, **kwargs): - return apply(self._cobj.set_get_returns_none, args, kwargs) + return self._cobj.set_get_returns_none(*args, **kwargs) def log_stat(self, *args, **kwargs): - return apply(self._cobj.log_stat, args, kwargs) + return self._cobj.log_stat(*args, **kwargs) if db.version() >= (4,1): def dbremove(self, *args, **kwargs): - return apply(self._cobj.dbremove, args, kwargs) + return self._cobj.dbremove(*args, **kwargs) def dbrename(self, *args, **kwargs): - return apply(self._cobj.dbrename, args, kwargs) + return self._cobj.dbrename(*args, **kwargs) def set_encrypt(self, *args, **kwargs): - return apply(self._cobj.set_encrypt, args, kwargs) + return self._cobj.set_encrypt(*args, **kwargs) if db.version() >= (4,4): def lsn_reset(self, *args, **kwargs): - return apply(self._cobj.lsn_reset, args, kwargs) + return self._cobj.lsn_reset(*args, **kwargs) class DB(MutableMapping): def __init__(self, dbenv, *args, **kwargs): # give it the proper DBEnv C object that its expecting - self._cobj = apply(db.DB, (dbenv._cobj,) + args, kwargs) + self._cobj = db.DB(*((dbenv._cobj,) + args), **kwargs) # TODO are there other dict methods that need to be overridden? def __len__(self): @@ -143,126 +143,126 @@ class DB(MutableMapping): return self._cobj.__iter__() def append(self, *args, **kwargs): - return apply(self._cobj.append, args, kwargs) + return self._cobj.append(*args, **kwargs) def associate(self, *args, **kwargs): - return apply(self._cobj.associate, args, kwargs) + return self._cobj.associate(*args, **kwargs) def close(self, *args, **kwargs): - return apply(self._cobj.close, args, kwargs) + return self._cobj.close(*args, **kwargs) def consume(self, *args, **kwargs): - return apply(self._cobj.consume, args, kwargs) + return self._cobj.consume(*args, **kwargs) def consume_wait(self, *args, **kwargs): - return apply(self._cobj.consume_wait, args, kwargs) + return self._cobj.consume_wait(*args, **kwargs) def cursor(self, *args, **kwargs): - return apply(self._cobj.cursor, args, kwargs) + return self._cobj.cursor(*args, **kwargs) def delete(self, *args, **kwargs): - return apply(self._cobj.delete, args, kwargs) + return self._cobj.delete(*args, **kwargs) def fd(self, *args, **kwargs): - return apply(self._cobj.fd, args, kwargs) + return self._cobj.fd(*args, **kwargs) def get(self, *args, **kwargs): - return apply(self._cobj.get, args, kwargs) + return self._cobj.get(*args, **kwargs) def pget(self, *args, **kwargs): - return apply(self._cobj.pget, args, kwargs) + return self._cobj.pget(*args, **kwargs) def get_both(self, *args, **kwargs): - return apply(self._cobj.get_both, args, kwargs) + return self._cobj.get_both(*args, **kwargs) def get_byteswapped(self, *args, **kwargs): - return apply(self._cobj.get_byteswapped, args, kwargs) + return self._cobj.get_byteswapped(*args, **kwargs) def get_size(self, *args, **kwargs): - return apply(self._cobj.get_size, args, kwargs) + return self._cobj.get_size(*args, **kwargs) def get_type(self, *args, **kwargs): - return apply(self._cobj.get_type, args, kwargs) + return self._cobj.get_type(*args, **kwargs) def join(self, *args, **kwargs): - return apply(self._cobj.join, args, kwargs) + return self._cobj.join(*args, **kwargs) def key_range(self, *args, **kwargs): - return apply(self._cobj.key_range, args, kwargs) + return self._cobj.key_range(*args, **kwargs) def has_key(self, *args, **kwargs): - return apply(self._cobj.has_key, args, kwargs) + return self._cobj.has_key(*args, **kwargs) def items(self, *args, **kwargs): - return apply(self._cobj.items, args, kwargs) + return self._cobj.items(*args, **kwargs) def keys(self, *args, **kwargs): - return apply(self._cobj.keys, args, kwargs) + return self._cobj.keys(*args, **kwargs) def open(self, *args, **kwargs): - return apply(self._cobj.open, args, kwargs) + return self._cobj.open(*args, **kwargs) def put(self, *args, **kwargs): - return apply(self._cobj.put, args, kwargs) + return self._cobj.put(*args, **kwargs) def remove(self, *args, **kwargs): - return apply(self._cobj.remove, args, kwargs) + return self._cobj.remove(*args, **kwargs) def rename(self, *args, **kwargs): - return apply(self._cobj.rename, args, kwargs) + return self._cobj.rename(*args, **kwargs) def set_bt_minkey(self, *args, **kwargs): - return apply(self._cobj.set_bt_minkey, args, kwargs) + return self._cobj.set_bt_minkey(*args, **kwargs) def set_bt_compare(self, *args, **kwargs): - return apply(self._cobj.set_bt_compare, args, kwargs) + return self._cobj.set_bt_compare(*args, **kwargs) def set_cachesize(self, *args, **kwargs): - return apply(self._cobj.set_cachesize, args, kwargs) + return self._cobj.set_cachesize(*args, **kwargs) def set_flags(self, *args, **kwargs): - return apply(self._cobj.set_flags, args, kwargs) + return self._cobj.set_flags(*args, **kwargs) def set_h_ffactor(self, *args, **kwargs): - return apply(self._cobj.set_h_ffactor, args, kwargs) + return self._cobj.set_h_ffactor(*args, **kwargs) def set_h_nelem(self, *args, **kwargs): - return apply(self._cobj.set_h_nelem, args, kwargs) + return self._cobj.set_h_nelem(*args, **kwargs) def set_lorder(self, *args, **kwargs): - return apply(self._cobj.set_lorder, args, kwargs) + return self._cobj.set_lorder(*args, **kwargs) def set_pagesize(self, *args, **kwargs): - return apply(self._cobj.set_pagesize, args, kwargs) + return self._cobj.set_pagesize(*args, **kwargs) def set_re_delim(self, *args, **kwargs): - return apply(self._cobj.set_re_delim, args, kwargs) + return self._cobj.set_re_delim(*args, **kwargs) def set_re_len(self, *args, **kwargs): - return apply(self._cobj.set_re_len, args, kwargs) + return self._cobj.set_re_len(*args, **kwargs) def set_re_pad(self, *args, **kwargs): - return apply(self._cobj.set_re_pad, args, kwargs) + return self._cobj.set_re_pad(*args, **kwargs) def set_re_source(self, *args, **kwargs): - return apply(self._cobj.set_re_source, args, kwargs) + return self._cobj.set_re_source(*args, **kwargs) def set_q_extentsize(self, *args, **kwargs): - return apply(self._cobj.set_q_extentsize, args, kwargs) + return self._cobj.set_q_extentsize(*args, **kwargs) def stat(self, *args, **kwargs): - return apply(self._cobj.stat, args, kwargs) + return self._cobj.stat(*args, **kwargs) def sync(self, *args, **kwargs): - return apply(self._cobj.sync, args, kwargs) + return self._cobj.sync(*args, **kwargs) def type(self, *args, **kwargs): - return apply(self._cobj.type, args, kwargs) + return self._cobj.type(*args, **kwargs) def upgrade(self, *args, **kwargs): - return apply(self._cobj.upgrade, args, kwargs) + return self._cobj.upgrade(*args, **kwargs) def values(self, *args, **kwargs): - return apply(self._cobj.values, args, kwargs) + return self._cobj.values(*args, **kwargs) def verify(self, *args, **kwargs): - return apply(self._cobj.verify, args, kwargs) + return self._cobj.verify(*args, **kwargs) def set_get_returns_none(self, *args, **kwargs): - return apply(self._cobj.set_get_returns_none, args, kwargs) + return self._cobj.set_get_returns_none(*args, **kwargs) if db.version() >= (4,1): def set_encrypt(self, *args, **kwargs): - return apply(self._cobj.set_encrypt, args, kwargs) + return self._cobj.set_encrypt(*args, **kwargs) class DBSequence: def __init__(self, *args, **kwargs): - self._cobj = apply(db.DBSequence, args, kwargs) + self._cobj = db.DBSequence(*args, **kwargs) def close(self, *args, **kwargs): - return apply(self._cobj.close, args, kwargs) + return self._cobj.close(*args, **kwargs) def get(self, *args, **kwargs): - return apply(self._cobj.get, args, kwargs) + return self._cobj.get(*args, **kwargs) def get_dbp(self, *args, **kwargs): - return apply(self._cobj.get_dbp, args, kwargs) + return self._cobj.get_dbp(*args, **kwargs) def get_key(self, *args, **kwargs): - return apply(self._cobj.get_key, args, kwargs) + return self._cobj.get_key(*args, **kwargs) def init_value(self, *args, **kwargs): - return apply(self._cobj.init_value, args, kwargs) + return self._cobj.init_value(*args, **kwargs) def open(self, *args, **kwargs): - return apply(self._cobj.open, args, kwargs) + return self._cobj.open(*args, **kwargs) def remove(self, *args, **kwargs): - return apply(self._cobj.remove, args, kwargs) + return self._cobj.remove(*args, **kwargs) def stat(self, *args, **kwargs): - return apply(self._cobj.stat, args, kwargs) + return self._cobj.stat(*args, **kwargs) def set_cachesize(self, *args, **kwargs): - return apply(self._cobj.set_cachesize, args, kwargs) + return self._cobj.set_cachesize(*args, **kwargs) def set_flags(self, *args, **kwargs): - return apply(self._cobj.set_flags, args, kwargs) + return self._cobj.set_flags(*args, **kwargs) def set_range(self, *args, **kwargs): - return apply(self._cobj.set_range, args, kwargs) + return self._cobj.set_range(*args, **kwargs) def get_cachesize(self, *args, **kwargs): - return apply(self._cobj.get_cachesize, args, kwargs) + return self._cobj.get_cachesize(*args, **kwargs) def get_flags(self, *args, **kwargs): - return apply(self._cobj.get_flags, args, kwargs) + return self._cobj.get_flags(*args, **kwargs) def get_range(self, *args, **kwargs): - return apply(self._cobj.get_range, args, kwargs) + return self._cobj.get_range(*args, **kwargs) diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py index e2912597d58..fb0b7624046 100644 --- a/Lib/bsddb/dbshelve.py +++ b/Lib/bsddb/dbshelve.py @@ -234,7 +234,7 @@ class DBShelf(MutableMapping): # given nothing is passed to the extension module. That way # an exception can be raised if set_get_returns_none is turned # off. - data = apply(self.db.get, args, kw) + data = self.db.get(*args, **kw) try: return cPickle.loads(data) except (EOFError, TypeError, cPickle.UnpicklingError): @@ -303,7 +303,7 @@ class DBShelfCursor: def get(self, *args): count = len(args) # a method overloading hack method = getattr(self, 'get_%d' % count) - apply(method, args) + method(*args) def get_1(self, flags): rec = self.dbc.get(flags) diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py index 21cfe58830e..2b0a2bf1f31 100644 --- a/Lib/bsddb/dbtables.py +++ b/Lib/bsddb/dbtables.py @@ -398,7 +398,7 @@ class bsdTableDB : # column names newcolumnlist = copy.copy(oldcolumnlist) for c in columns: - if not oldcolumnhash.has_key(c): + if not c in oldcolumnhash: newcolumnlist.append(c) # store the table's new extended column list @@ -472,7 +472,7 @@ class bsdTableDB : raise TableDBError, "unknown table" # check the validity of each column name - if not self.__tablecolumns.has_key(table): + if not table in self.__tablecolumns: self.__load_column_info(table) for column in rowdict.keys() : if not self.__tablecolumns[table].count(column): @@ -540,7 +540,7 @@ class bsdTableDB : # error dataitem = None dataitem = mappings[column](dataitem) - if dataitem <> None: + if dataitem != None: self.db.put( _data_key(table, column, rowid), dataitem, txn=txn) @@ -615,7 +615,7 @@ class bsdTableDB : argument and returning a boolean. """ try: - if not self.__tablecolumns.has_key(table): + if not table in self.__tablecolumns: self.__load_column_info(table) if columns is None: columns = self.__tablecolumns[table] @@ -639,7 +639,7 @@ class bsdTableDB : argument and returning a boolean. """ # check the validity of each column name - if not self.__tablecolumns.has_key(table): + if not table in self.__tablecolumns: self.__load_column_info(table) if columns is None: columns = self.tablecolumns[table] @@ -709,28 +709,24 @@ class bsdTableDB : # extract the rowid from the key rowid = key[-_rowid_str_len:] - if not rejected_rowids.has_key(rowid): + if not rowid in rejected_rowids: # if no condition was specified or the condition # succeeds, add row to our match list. if not condition or condition(data): - if not matching_rowids.has_key(rowid): + if not rowid in matching_rowids: matching_rowids[rowid] = {} if savethiscolumndata: matching_rowids[rowid][column] = data else: - if matching_rowids.has_key(rowid): + if rowid in matching_rowids: del matching_rowids[rowid] rejected_rowids[rowid] = rowid key, data = cur.next() except db.DBError, dberror: - if sys.version_info[0] < 3 : - if dberror[0] != db.DB_NOTFOUND: - raise - else : - if dberror.args[0] != db.DB_NOTFOUND: - raise + if dberror.args[0] != db.DB_NOTFOUND: + raise continue cur.close() @@ -743,7 +739,7 @@ class bsdTableDB : if len(columns) > 0: for rowid, rowdata in matching_rowids.items(): for column in columns: - if rowdata.has_key(column): + if column in rowdata: continue try: rowdata[column] = self.db.get( @@ -815,13 +811,10 @@ class bsdTableDB : txn.commit() txn = None - if self.__tablecolumns.has_key(table): + if table in self.__tablecolumns: del self.__tablecolumns[table] except db.DBError, dberror: if txn: txn.abort() - if sys.version_info[0] < 3 : - raise TableDBError, dberror[1] - else : - raise TableDBError, dberror.args[1] + raise TableDBError(dberror.args[1]) diff --git a/Lib/bsddb/dbutils.py b/Lib/bsddb/dbutils.py index 8d2e7eff520..02a686f5d9a 100644 --- a/Lib/bsddb/dbutils.py +++ b/Lib/bsddb/dbutils.py @@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kwargs): """ sleeptime = _deadlock_MinSleepTime max_retries = _kwargs.get('max_retries', -1) - if _kwargs.has_key('max_retries'): + if 'max_retries' in _kwargs: del _kwargs['max_retries'] while True: try: