svn commit: samba r14897 - in
branches/SAMBA_4_0/source/scripting/swig: .
tpot at samba.org
tpot at samba.org
Mon Apr 3 22:04:34 GMT 2006
Author: tpot
Date: 2006-04-03 22:04:33 +0000 (Mon, 03 Apr 2006)
New Revision: 14897
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14897
Log:
Do more error checking of tdb function returns and raise IOError or
KeyError exceptions as appropriate.
Add a close() function to the wrapper as we can't rely on the
Python garbage collector destroying the object and closing the tdb file
at any particular time.
Modified:
branches/SAMBA_4_0/source/scripting/swig/Tdb.py
Changeset:
Modified: branches/SAMBA_4_0/source/scripting/swig/Tdb.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/Tdb.py 2006-04-03 19:14:12 UTC (rev 14896)
+++ branches/SAMBA_4_0/source/scripting/swig/Tdb.py 2006-04-03 22:04:33 UTC (rev 14897)
@@ -39,25 +39,33 @@
def __init__(self, name, hash_size = 0, flags = tdb.TDB_DEFAULT,
open_flags = os.O_RDWR | os.O_CREAT, mode = 0600):
self.tdb = tdb.open(name, hash_size, flags, open_flags, mode)
-
+ if self.tdb is None:
+ raise IOError, tdb.errorstr(self.tdb)
+
def __del__(self):
- if hasattr(self, 'tdb'):
- tdb.close(self.tdb)
+ self.close()
+ def close(self):
+ if hasattr(self, 'tdb') and self.tdb is not None:
+ if tdb.close(self.tdb) == -1:
+ raise IOError, tdb.errorstr(self.tdb)
+ self.tdb = None
+
# Random access to keys, values
def __getitem__(self, key):
result = tdb.fetch(self.tdb, key)
if result is None:
- raise KeyError, key
+ raise KeyError, '%s: %s' % (key, tdb.errorstr(self.tdb))
return result
def __setitem__(self, key, item):
- tdb.store(self.tdb, key, item)
+ if tdb.store(self.tdb, key, item) == -1:
+ raise IOError, tdb.errorstr(self.tdb)
def __delitem__(self, key):
if not tdb.exists(self.tdb, key):
- raise KeyError, key
+ raise KeyError, '%s: %s' % (key, tdb.errorstr(self.tdb))
tdb.delete(self.tdb, key)
def has_key(self, key):
More information about the samba-cvs
mailing list