summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-08-23 07:32:27 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-08-23 07:32:27 (GMT)
commit361ed15383845bffc017b6a14acfb9da8f63ef73 (patch)
tree808d7729ad334a8b32e31fca6acd1edf010d7398 /Lib
parente5a8dc684ce67578f1bac94c1a76fea659d4ace7 (diff)
downloadcpython-361ed15383845bffc017b6a14acfb9da8f63ef73.zip
cpython-361ed15383845bffc017b6a14acfb9da8f63ef73.tar.gz
cpython-361ed15383845bffc017b6a14acfb9da8f63ef73.tar.bz2
Require strict bytes objects for all bsddb.db input values.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bsddb/test/test_dbtables.py106
-rw-r--r--Lib/bsddb/test/test_lock.py4
-rw-r--r--Lib/bsddb/test/test_queue.py24
-rw-r--r--Lib/bsddb/test/test_recno.py14
4 files changed, 74 insertions, 74 deletions
diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py
index b03971b..4b3370f 100644
--- a/Lib/bsddb/test/test_dbtables.py
+++ b/Lib/bsddb/test/test_dbtables.py
@@ -88,9 +88,9 @@ class TableDBTestCase(unittest.TestCase):
col1 = 'but can it fly?'
col2 = 'Species'
testinfo = [
- {col0: pickle.dumps(8, 1), col1: 'no', col2: 'Penguin'},
- {col0: pickle.dumps(-1, 1), col1: 'no', col2: 'Turkey'},
- {col0: pickle.dumps(9, 1), col1: 'yes', col2: 'SR-71A Blackbird'}
+ {col0: pickle.dumps(8, 1), col1: b'no', col2: b'Penguin'},
+ {col0: pickle.dumps(-1, 1), col1: b'no', col2: b'Turkey'},
+ {col0: pickle.dumps(9, 1), col1: b'yes', col2: b'SR-71A Blackbird'}
]
try:
@@ -150,22 +150,22 @@ class TableDBTestCase(unittest.TestCase):
pass
self.tdb.Insert(tabname,
- {'a': '42',
- 'b': "bad",
- 'c': "meep",
- 'e': 'Fuzzy wuzzy was a bear'})
+ {'a': b'42',
+ 'b': b'bad',
+ 'c': b'meep',
+ 'e': b'Fuzzy wuzzy was a bear'})
self.tdb.Insert(tabname,
- {'a': '581750',
- 'b': "good",
- 'd': "bla",
- 'c': "black",
- 'e': 'fuzzy was here'})
+ {'a': b'581750',
+ 'b': b'good',
+ 'd': b'bla',
+ 'c': b'black',
+ 'e': b'fuzzy was here'})
self.tdb.Insert(tabname,
- {'a': '800000',
- 'b': "good",
- 'd': "bla",
- 'c': "black",
- 'e': 'Fuzzy wuzzy is a bear'})
+ {'a': b'800000',
+ 'b': b'good',
+ 'd': b'bla',
+ 'c': b'black',
+ 'e': b'Fuzzy wuzzy is a bear'})
if verbose:
self.tdb._db_print()
@@ -202,19 +202,19 @@ class TableDBTestCase(unittest.TestCase):
try:
self.tdb.Insert(tabname,
- {'a': "",
+ {'a': b"",
'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1),
- 'f': "Zero"})
+ 'f': b"Zero"})
self.fail("exception not raised")
except dbtables.TableDBError:
pass
- self.tdb.Insert(tabname, {'a': "A", 'b': "B", 'c': "C", 'd': "D",
- 'e': "E"})
- self.tdb.Insert(tabname, {'a': "-A", 'b': "-B", 'c': "-C", 'd': "-D",
- 'e': "-E"})
- self.tdb.Insert(tabname, {'a': "A-", 'b': "B-", 'c': "C-", 'd': "D-",
- 'e': "E-"})
+ self.tdb.Insert(tabname, {'a': b"A", 'b': b"B", 'c': b"C",
+ 'd': b"D", 'e': b"E"})
+ self.tdb.Insert(tabname, {'a': b"-A", 'b': b"-B", 'c': b"-C",
+ 'd': b"-D", 'e': b"-E"})
+ self.tdb.Insert(tabname, {'a': b"A-", 'b': b"B-", 'c': b"C-",
+ 'd': b"D-", 'e': b"E-"})
if verbose:
self.tdb._db_print()
@@ -239,9 +239,9 @@ class TableDBTestCase(unittest.TestCase):
tabname, ['name', 'taste', 'filling', 'alcohol content', 'price'])
try:
self.tdb.Insert(tabname,
- {'taste': 'crap',
- 'filling': 'no',
- 'is it Guinness?': 'no'})
+ {'taste': b'crap',
+ 'filling': b'no',
+ 'is it Guinness?': b'no'})
self.fail("Insert should've failed due to bad column name")
except:
pass
@@ -249,11 +249,11 @@ class TableDBTestCase(unittest.TestCase):
['name', 'taste', 'is it Guinness?'])
# these should both succeed as the table should contain the union of both sets of columns.
- self.tdb.Insert(tabname, {'taste': 'crap', 'filling': 'no',
- 'is it Guinness?': 'no'})
- self.tdb.Insert(tabname, {'taste': 'great', 'filling': 'yes',
- 'is it Guinness?': 'yes',
- 'name': 'Guinness'})
+ self.tdb.Insert(tabname, {'taste': b'crap', 'filling': b'no',
+ 'is it Guinness?': b'no'})
+ self.tdb.Insert(tabname, {'taste': b'great', 'filling': b'yes',
+ 'is it Guinness?': b'yes',
+ 'name': b'Guinness'})
def test_CondObjs(self):
@@ -261,17 +261,17 @@ class TableDBTestCase(unittest.TestCase):
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e', 'p'])
- self.tdb.Insert(tabname, {'a': "the letter A",
- 'b': "the letter B",
- 'c': "is for cookie"})
- self.tdb.Insert(tabname, {'a': "is for aardvark",
- 'e': "the letter E",
- 'c': "is for cookie",
- 'd': "is for dog"})
- self.tdb.Insert(tabname, {'a': "the letter A",
- 'e': "the letter E",
- 'c': "is for cookie",
- 'p': "is for Python"})
+ self.tdb.Insert(tabname, {'a': b"the letter A",
+ 'b': b"the letter B",
+ 'c': b"is for cookie"})
+ self.tdb.Insert(tabname, {'a': b"is for aardvark",
+ 'e': b"the letter E",
+ 'c': b"is for cookie",
+ 'd': b"is for dog"})
+ self.tdb.Insert(tabname, {'a': b"the letter A",
+ 'e': b"the letter E",
+ 'c': b"is for cookie",
+ 'p': b"is for Python"})
values = self.tdb.Select(
tabname, ['p', 'e'],
@@ -309,8 +309,8 @@ class TableDBTestCase(unittest.TestCase):
# fail if it encountered any rows that did not have values in
# every column.
# Hunted and Squashed by <Donwulff> (Jukka Santala - donwulff@nic.fi)
- self.tdb.Insert(tabname, {'x': 'X1', 'y':'Y1'})
- self.tdb.Insert(tabname, {'x': 'X2', 'y':'Y2', 'z': 'Z2'})
+ self.tdb.Insert(tabname, {'x': b'X1', 'y':b'Y1'})
+ self.tdb.Insert(tabname, {'x': b'X2', 'y':b'Y2', 'z': b'Z2'})
self.tdb.Delete(tabname, conditions={'x': dbtables.PrefixCond('X')})
values = self.tdb.Select(tabname, ['y'],
@@ -321,18 +321,18 @@ class TableDBTestCase(unittest.TestCase):
tabname = "test_Modify"
self.tdb.CreateTable(tabname, ['Name', 'Type', 'Access'])
- self.tdb.Insert(tabname, {'Name': 'Index to MP3 files.doc',
- 'Type': 'Word', 'Access': '8'})
- self.tdb.Insert(tabname, {'Name': 'Nifty.MP3', 'Access': '1'})
- self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'})
+ self.tdb.Insert(tabname, {'Name': b'Index to MP3 files.doc',
+ 'Type': b'Word', 'Access': b'8'})
+ self.tdb.Insert(tabname, {'Name': b'Nifty.MP3', 'Access': b'1'})
+ self.tdb.Insert(tabname, {'Type': b'Unknown', 'Access': b'0'})
def set_type(type):
if type == None:
- return 'MP3'
+ return b'MP3'
return type
def increment_access(count):
- return str(int(count)+1)
+ return bytes(str(int(count)+1))
def remove_value(value):
return None
@@ -350,7 +350,7 @@ class TableDBTestCase(unittest.TestCase):
try:
self.tdb.Modify(tabname,
conditions={'Name': dbtables.LikeCond('%')},
- mappings={'Access': 'What is your quest?'})
+ mappings={'Access': b'What is your quest?'})
except TypeError:
# success, the string value in mappings isn't callable
pass
diff --git a/Lib/bsddb/test/test_lock.py b/Lib/bsddb/test/test_lock.py
index 9b5a71f..063ffbd 100644
--- a/Lib/bsddb/test/test_lock.py
+++ b/Lib/bsddb/test/test_lock.py
@@ -55,7 +55,7 @@ class LockingTestCase(unittest.TestCase):
anID = self.env.lock_id()
if verbose:
print("locker ID: %s" % anID)
- lock = self.env.lock_get(anID, "some locked thing", db.DB_LOCK_WRITE)
+ lock = self.env.lock_get(anID, b"some locked thing", db.DB_LOCK_WRITE)
if verbose:
print("Aquired lock: %s" % lock)
time.sleep(1)
@@ -115,7 +115,7 @@ class LockingTestCase(unittest.TestCase):
if verbose:
print("%s: locker ID: %s" % (name, anID))
- lock = self.env.lock_get(anID, "some locked thing", lockType)
+ lock = self.env.lock_get(anID, b"some locked thing", lockType)
if verbose:
print("%s: Aquired %s lock: %s" % (name, lt, lock))
diff --git a/Lib/bsddb/test/test_queue.py b/Lib/bsddb/test/test_queue.py
index e20737e..2cf5a8c 100644
--- a/Lib/bsddb/test/test_queue.py
+++ b/Lib/bsddb/test/test_queue.py
@@ -47,14 +47,14 @@ class SimpleQueueTestCase(unittest.TestCase):
pprint(d.stat())
for x in letters:
- d.append(x * 40)
+ d.append(bytes(x) * 40)
assert len(d) == 52
- d.put(100, "some more data")
- d.put(101, "and some more ")
- d.put(75, "out of order")
- d.put(1, "replacement data")
+ d.put(100, b"some more data")
+ d.put(101, b"and some more ")
+ d.put(75, b"out of order")
+ d.put(1, b"replacement data")
assert len(d) == 55
@@ -71,7 +71,7 @@ class SimpleQueueTestCase(unittest.TestCase):
print("after open" + '-' * 30)
pprint(d.stat())
- d.append("one more")
+ d.append(b"one more")
c = d.cursor()
if verbose:
@@ -119,14 +119,14 @@ class SimpleQueueTestCase(unittest.TestCase):
pprint(d.stat())
for x in letters:
- d.append(x * 40)
+ d.append(bytes(x) * 40)
assert len(d) == 52
- d.put(100, "some more data")
- d.put(101, "and some more ")
- d.put(75, "out of order")
- d.put(1, "replacement data")
+ d.put(100, b"some more data")
+ d.put(101, b"and some more ")
+ d.put(75, b"out of order")
+ d.put(1, b"replacement data")
assert len(d) == 55
@@ -144,7 +144,7 @@ class SimpleQueueTestCase(unittest.TestCase):
print("after open" + '-' * 30)
pprint(d.stat())
- d.append("one more")
+ d.append(b"one more")
if verbose:
print("after append" + '-' * 30)
diff --git a/Lib/bsddb/test/test_recno.py b/Lib/bsddb/test/test_recno.py
index 3da5006..25482d5 100644
--- a/Lib/bsddb/test/test_recno.py
+++ b/Lib/bsddb/test/test_recno.py
@@ -41,7 +41,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
d.open(self.filename, db.DB_RECNO, db.DB_CREATE)
for x in letters:
- recno = d.append(x * 60)
+ recno = d.append(bytes(x) * 60)
assert type(recno) == type(0)
assert recno >= 1
if verbose:
@@ -219,7 +219,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
data = "The quick brown fox jumped over the lazy dog".split()
for datum in data:
- d.append(datum)
+ d.append(bytes(datum))
d.sync()
d.close()
@@ -238,8 +238,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
d.set_re_source(source)
d.open(self.filename, db.DB_RECNO)
- d[3] = 'reddish-brown'
- d[8] = 'comatose'
+ d[3] = b'reddish-brown'
+ d[8] = b'comatose'
d.sync()
d.close()
@@ -261,12 +261,12 @@ class SimpleRecnoTestCase(unittest.TestCase):
d.open(self.filename, db.DB_RECNO, db.DB_CREATE)
for x in letters:
- d.append(x * 35) # These will be padded
+ d.append(bytes(x) * 35) # These will be padded
- d.append('.' * 40) # this one will be exact
+ d.append(b'.' * 40) # this one will be exact
try: # this one will fail
- d.append('bad' * 20)
+ d.append(b'bad' * 20)
except db.DBInvalidArgError as val:
assert val.args[0] == db.EINVAL
if verbose: print(val)