diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2007-10-18 07:56:54 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2007-10-18 07:56:54 (GMT) |
commit | afed3a4552e0df61477c322f60b10d3ae59edf1c (patch) | |
tree | d1ecd46b98122ba4a6b788986106efd98386078a /Lib/bsddb | |
parent | d97110dd1bdc9a82a9191627c638cffa8118bc80 (diff) | |
download | cpython-afed3a4552e0df61477c322f60b10d3ae59edf1c.zip cpython-afed3a4552e0df61477c322f60b10d3ae59edf1c.tar.gz cpython-afed3a4552e0df61477c322f60b10d3ae59edf1c.tar.bz2 |
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
Diffstat (limited to 'Lib/bsddb')
-rw-r--r-- | Lib/bsddb/dbtables.py | 26 | ||||
-rw-r--r-- | Lib/bsddb/test/test_dbtables.py | 11 |
2 files changed, 18 insertions, 19 deletions
diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py index b83247a..daf6a9e 100644 --- a/Lib/bsddb/dbtables.py +++ b/Lib/bsddb/dbtables.py @@ -20,8 +20,9 @@ _cvsid = '$Id$' import re import sys import copy -import xdrlib import random +import struct +import base64 from types import ListType, StringType import cPickle as pickle @@ -255,7 +256,7 @@ class bsdTableDB : flags=DB_RMW)) tablelist.append(table) # delete 1st, in case we opened with DB_DUP - self.db.delete(_table_names_key, txn) + self.db.delete(_table_names_key, txn=txn) self.db.put(_table_names_key, pickle.dumps(tablelist, 1), txn=txn) txn.commit() @@ -329,7 +330,7 @@ class bsdTableDB : # store the table's new extended column list if newcolumnlist != oldcolumnlist : # delete the old one first since we opened with DB_DUP - self.db.delete(columnlist_key, txn) + self.db.delete(columnlist_key, txn=txn) self.db.put(columnlist_key, pickle.dumps(newcolumnlist, 1), txn=txn) @@ -362,10 +363,9 @@ class bsdTableDB : # Generate a random 64-bit row ID string # (note: this code has <64 bits of randomness # but it's plenty for our database id needs!) - p = xdrlib.Packer() - p.pack_int(int(random.random()*2147483647)) - p.pack_int(int(random.random()*2147483647)) - newid = p.get_buffer() + newid = struct.pack('ll', + random.randint(0, 2147483647), + random.randint(0, 2147483647)) # Guarantee uniqueness by adding this key to the database try: @@ -444,10 +444,10 @@ class bsdTableDB : try: dataitem = self.db.get( _data_key(table, column, rowid), - txn) + txn=txn) self.db.delete( _data_key(table, column, rowid), - txn) + txn=txn) except DBNotFoundError: # XXXXXXX row key somehow didn't exist, assume no # error @@ -490,13 +490,13 @@ class bsdTableDB : # delete the data key try: self.db.delete(_data_key(table, column, rowid), - txn) + txn=txn) except DBNotFoundError: # XXXXXXX column may not exist, assume no error pass try: - self.db.delete(_rowid_key(table, rowid), txn) + self.db.delete(_rowid_key(table, rowid), txn=txn) except DBNotFoundError: # XXXXXXX row key somehow didn't exist, assume no error pass @@ -652,7 +652,7 @@ class bsdTableDB : txn = self.env.txn_begin() # delete the column list - self.db.delete(_columns_key(table), txn) + self.db.delete(_columns_key(table), txn=txn) cur = self.db.cursor(txn) @@ -691,7 +691,7 @@ class bsdTableDB : # hmm, it wasn't there, oh well, that's what we want. pass # delete 1st, incase we opened with DB_DUP - self.db.delete(_table_names_key, txn) + self.db.delete(_table_names_key, txn=txn) self.db.put(_table_names_key, pickle.dumps(tablelist, 1), txn=txn) txn.commit() diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py index 959565c..3a401e3 100644 --- a/Lib/bsddb/test/test_dbtables.py +++ b/Lib/bsddb/test/test_dbtables.py @@ -21,6 +21,8 @@ # $Id$ import sys, os, re +import tempfile +import shutil try: import cPickle pickle = cPickle @@ -47,8 +49,8 @@ class TableDBTestCase(unittest.TestCase): db_name = 'test-table.db' def setUp(self): - homeDir = os.path.join(tempfile.gettempdir(), 'db_home') - self.homeDir = homeDir + homeDir = tempfile.mkdtemp() + self.testHomeDir = homeDir try: os.mkdir(homeDir) except os.error: pass self.tdb = dbtables.bsdTableDB( @@ -56,10 +58,7 @@ class TableDBTestCase(unittest.TestCase): def tearDown(self): self.tdb.close() - import glob - files = glob.glob(os.path.join(self.homeDir, '*')) - for file in files: - os.remove(file) + shutil.rmtree(self.testHomeDir) def test01(self): tabname = "test01" |