[Python-3000-checkins] r58535 - python/branches/py3k/Lib/bsddb/dbtables.py

gregory.p.smith python-3000-checkins at python.org
Thu Oct 18 18:55:12 CEST 2007


Author: gregory.p.smith
Date: Thu Oct 18 18:55:12 2007
New Revision: 58535

Modified:
   python/branches/py3k/Lib/bsddb/dbtables.py
Log:
Merge 58532, 58533, 58534: bsddb.dbtables bug fixes - don't allow null bytes
in random rowid strings, pass txn using a keyword where possible.


Modified: python/branches/py3k/Lib/bsddb/dbtables.py
==============================================================================
--- python/branches/py3k/Lib/bsddb/dbtables.py	(original)
+++ python/branches/py3k/Lib/bsddb/dbtables.py	Thu Oct 18 18:55:12 2007
@@ -20,7 +20,7 @@
 import re
 import sys
 import copy
-import xdrlib
+import struct
 import random
 import pickle
 
@@ -255,7 +255,7 @@
                                                  flags=DB_RMW))
             tablelist.append(table)
             # delete 1st, in case we opened with DB_DUP
-            self.db.delete(_E(_table_names_key), txn)
+            self.db.delete(_E(_table_names_key), txn=txn)
             self.db.put(_E(_table_names_key), pickle.dumps(tablelist, 1), txn=txn)
 
             txn.commit()
@@ -330,7 +330,7 @@
                 # 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)
@@ -364,10 +364,11 @@
             # 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()
+            # We must ensure that no null bytes are in the id value.
+            blist = []
+            for x in range(_rowid_str_len):
+                blist.append(random.randint(1,255))
+            newid = bytes(blist)
 
             # Guarantee uniqueness by adding this key to the database
             try:
@@ -451,10 +452,10 @@
                         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
@@ -497,13 +498,13 @@
                         try:
                             self.db.delete(_data_key(table, column,
                                                      rowid.encode("latin-1")),
-                                           txn)
+                                           txn=txn)
                         except DBNotFoundError:
                             # XXXXXXX column may not exist, assume no error
                             pass
 
                     try:
-                        self.db.delete(_rowid_key(table, rowid.encode("latin-1")), txn)
+                        self.db.delete(_rowid_key(table, rowid.encode("latin-1")), txn=txn)
                     except DBNotFoundError:
                         # XXXXXXX row key somehow didn't exist, assume no error
                         pass
@@ -659,7 +660,7 @@
             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)
 
@@ -698,7 +699,7 @@
                 # hmm, it wasn't there, oh well, that's what we want.
                 pass
             # delete 1st, incase we opened with DB_DUP
-            self.db.delete(_E(_table_names_key), txn)
+            self.db.delete(_E(_table_names_key), txn=txn)
             self.db.put(_E(_table_names_key), pickle.dumps(tablelist, 1), txn=txn)
 
             txn.commit()


More information about the Python-3000-checkins mailing list