Commit 507ea2ae authored by Ezio Melotti's avatar Ezio Melotti

Merged revisions 77912 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77912 | ezio.melotti | 2010-02-02 17:57:45 +0200 (Tue, 02 Feb 2010) | 1 line

  Fix idioms and a couple of py3k warnings. Patch by Florent Xicluna.
........
parent 8f1e0f2d
...@@ -152,7 +152,7 @@ class DBShelf(DictMixin): ...@@ -152,7 +152,7 @@ class DBShelf(DictMixin):
def keys(self, txn=None): def keys(self, txn=None):
if txn != None: if txn is not None:
return self.db.keys(txn) return self.db.keys(txn)
else: else:
return self.db.keys() return self.db.keys()
...@@ -176,7 +176,7 @@ class DBShelf(DictMixin): ...@@ -176,7 +176,7 @@ class DBShelf(DictMixin):
def items(self, txn=None): def items(self, txn=None):
if txn != None: if txn is not None:
items = self.db.items(txn) items = self.db.items(txn)
else: else:
items = self.db.items() items = self.db.items()
...@@ -187,7 +187,7 @@ class DBShelf(DictMixin): ...@@ -187,7 +187,7 @@ class DBShelf(DictMixin):
return newitems return newitems
def values(self, txn=None): def values(self, txn=None):
if txn != None: if txn is not None:
values = self.db.values(txn) values = self.db.values(txn)
else: else:
values = self.db.values() values = self.db.values()
......
...@@ -179,14 +179,14 @@ class bsdTableDB : ...@@ -179,14 +179,14 @@ class bsdTableDB :
def set_range(self, search) : def set_range(self, search) :
v = self._dbcursor.set_range(bytes(search, "iso8859-1")) v = self._dbcursor.set_range(bytes(search, "iso8859-1"))
if v != None : if v is not None :
v = (v[0].decode("iso8859-1"), v = (v[0].decode("iso8859-1"),
v[1].decode("iso8859-1")) v[1].decode("iso8859-1"))
return v return v
def __next__(self) : def __next__(self) :
v = getattr(self._dbcursor, "next")() v = getattr(self._dbcursor, "next")()
if v != None : if v is not None :
v = (v[0].decode("iso8859-1"), v = (v[0].decode("iso8859-1"),
v[1].decode("iso8859-1")) v[1].decode("iso8859-1"))
return v return v
...@@ -204,7 +204,7 @@ class bsdTableDB : ...@@ -204,7 +204,7 @@ class bsdTableDB :
def put(self, key, value, flags=0, txn=None) : def put(self, key, value, flags=0, txn=None) :
key = bytes(key, "iso8859-1") key = bytes(key, "iso8859-1")
if value != None : if value is not None :
value = bytes(value, "iso8859-1") value = bytes(value, "iso8859-1")
return self._db.put(key, value, flags=flags, txn=txn) return self._db.put(key, value, flags=flags, txn=txn)
...@@ -215,7 +215,7 @@ class bsdTableDB : ...@@ -215,7 +215,7 @@ class bsdTableDB :
def get(self, key, txn=None, flags=0) : def get(self, key, txn=None, flags=0) :
key = bytes(key, "iso8859-1") key = bytes(key, "iso8859-1")
v = self._db.get(key, txn=txn, flags=flags) v = self._db.get(key, txn=txn, flags=flags)
if v != None : if v is not None :
v = v.decode("iso8859-1") v = v.decode("iso8859-1")
return v return v
...@@ -540,7 +540,7 @@ class bsdTableDB : ...@@ -540,7 +540,7 @@ class bsdTableDB :
# error # error
dataitem = None dataitem = None
dataitem = mappings[column](dataitem) dataitem = mappings[column](dataitem)
if dataitem <> None: if dataitem is not None:
self.db.put( self.db.put(
_data_key(table, column, rowid), _data_key(table, column, rowid),
dataitem, txn=txn) dataitem, txn=txn)
......
...@@ -23,7 +23,7 @@ if sys.version_info[0] >= 3 : ...@@ -23,7 +23,7 @@ if sys.version_info[0] >= 3 :
return getattr(self._dbcursor, v) return getattr(self._dbcursor, v)
def _fix(self, v) : def _fix(self, v) :
if v == None : return None if v is None : return None
key, value = v key, value = v
if isinstance(key, bytes) : if isinstance(key, bytes) :
key = key.decode(charset) key = key.decode(charset)
...@@ -90,7 +90,7 @@ if sys.version_info[0] >= 3 : ...@@ -90,7 +90,7 @@ if sys.version_info[0] >= 3 :
def pget(self, key=None, data=None, flags=0) : def pget(self, key=None, data=None, flags=0) :
# Incorrect because key can be a bare number, # Incorrect because key can be a bare number,
# but enough to pass testsuite # but enough to pass testsuite
if isinstance(key, int) and (data==None) and (flags==0) : if isinstance(key, int) and (data is None) and (flags == 0) :
flags = key flags = key
key = None key = None
if isinstance(key, str) : if isinstance(key, str) :
...@@ -101,7 +101,7 @@ if sys.version_info[0] >= 3 : ...@@ -101,7 +101,7 @@ if sys.version_info[0] >= 3 :
if isinstance(data, str) : if isinstance(data, str) :
data = bytes(data, charset) data = bytes(data, charset)
v=self._dbcursor.pget(key=key, data=data, flags=flags) v=self._dbcursor.pget(key=key, data=data, flags=flags)
if v != None : if v is not None :
v1, v2, v3 = v v1, v2, v3 = v
if isinstance(v1, bytes) : if isinstance(v1, bytes) :
v1 = v1.decode(charset) v1 = v1.decode(charset)
...@@ -114,7 +114,7 @@ if sys.version_info[0] >= 3 : ...@@ -114,7 +114,7 @@ if sys.version_info[0] >= 3 :
def join_item(self) : def join_item(self) :
v = self._dbcursor.join_item() v = self._dbcursor.join_item()
if v != None : if v is not None :
v = v.decode(charset) v = v.decode(charset)
return v return v
...@@ -134,7 +134,7 @@ if sys.version_info[0] >= 3 : ...@@ -134,7 +134,7 @@ if sys.version_info[0] >= 3 :
args =(k, d, f) args =(k, d, f)
v = self._dbcursor.get(*args, **kwargs) v = self._dbcursor.get(*args, **kwargs)
if v != None : if v is not None :
k, v = v k, v = v
if isinstance(k, bytes) : if isinstance(k, bytes) :
k = k.decode(charset) k = k.decode(charset)
...@@ -176,7 +176,7 @@ if sys.version_info[0] >= 3 : ...@@ -176,7 +176,7 @@ if sys.version_info[0] >= 3 :
if isinstance(k, str) : if isinstance(k, str) :
k = bytes(k, charset) k = bytes(k, charset)
v = self._db[k] v = self._db[k]
if v != None : if v is not None :
v = v.decode(charset) v = v.decode(charset)
return v return v
...@@ -230,7 +230,7 @@ if sys.version_info[0] >= 3 : ...@@ -230,7 +230,7 @@ if sys.version_info[0] >= 3 :
else : else :
v=self._db.get(key, txn=txn, flags=flags, v=self._db.get(key, txn=txn, flags=flags,
dlen=dlen, doff=doff) dlen=dlen, doff=doff)
if (v != None) and isinstance(v, bytes) : if (v is not None) and isinstance(v, bytes) :
v = v.decode(charset) v = v.decode(charset)
return v return v
...@@ -238,7 +238,7 @@ if sys.version_info[0] >= 3 : ...@@ -238,7 +238,7 @@ if sys.version_info[0] >= 3 :
if isinstance(key, str) : if isinstance(key, str) :
key = bytes(key, charset) key = bytes(key, charset)
v=self._db.pget(key, txn=txn) v=self._db.pget(key, txn=txn)
if v != None : if v is not None :
v1, v2 = v v1, v2 = v
if isinstance(v1, bytes) : if isinstance(v1, bytes) :
v1 = v1.decode(charset) v1 = v1.decode(charset)
...@@ -252,7 +252,7 @@ if sys.version_info[0] >= 3 : ...@@ -252,7 +252,7 @@ if sys.version_info[0] >= 3 :
if isinstance(value, str) : if isinstance(value, str) :
value = bytes(value, charset) value = bytes(value, charset)
v=self._db.get_both(key, value, txn=txn, flags=flags) v=self._db.get_both(key, value, txn=txn, flags=flags)
if v != None : if v is not None :
v = v.decode(charset) v = v.decode(charset)
return v return v
......
...@@ -342,7 +342,7 @@ class BasicTestCase(unittest.TestCase): ...@@ -342,7 +342,7 @@ class BasicTestCase(unittest.TestCase):
else: else:
if set_raises_error: if set_raises_error:
self.fail("expected exception") self.fail("expected exception")
if n != None: if n is not None:
self.fail("expected None: %r" % (n,)) self.fail("expected None: %r" % (n,))
rec = c.get_both('0404', self.makeData('0404')) rec = c.get_both('0404', self.makeData('0404'))
...@@ -356,7 +356,7 @@ class BasicTestCase(unittest.TestCase): ...@@ -356,7 +356,7 @@ class BasicTestCase(unittest.TestCase):
else: else:
if get_raises_error: if get_raises_error:
self.fail("expected exception") self.fail("expected exception")
if n != None: if n is not None:
self.fail("expected None: %r" % (n,)) self.fail("expected None: %r" % (n,))
if self.d.get_type() == db.DB_BTREE: if self.d.get_type() == db.DB_BTREE:
......
...@@ -239,12 +239,7 @@ class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase): ...@@ -239,12 +239,7 @@ class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase):
self.startTest () self.startTest ()
self.createDB (my_compare) self.createDB (my_compare)
try: self.assertRaises (RuntimeError, self.db.set_bt_compare, my_compare)
self.db.set_bt_compare (my_compare)
self.assert_(0, "this set should fail")
except RuntimeError, msg:
pass
def test_suite (): def test_suite ():
res = unittest.TestSuite () res = unittest.TestSuite ()
......
...@@ -341,7 +341,7 @@ class TableDBTestCase(unittest.TestCase): ...@@ -341,7 +341,7 @@ class TableDBTestCase(unittest.TestCase):
self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'}) self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'})
def set_type(type): def set_type(type):
if type == None: if type is None:
return 'MP3' return 'MP3'
return type return type
......
...@@ -38,8 +38,8 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -38,8 +38,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
for x in letters: for x in letters:
recno = d.append(x * 60) recno = d.append(x * 60)
self.assertEqual(type(recno), type(0)) self.assertIsInstance(recno, int)
self.assert_(recno >= 1) self.assertGreaterEqual(recno, 1)
if verbose: if verbose:
print recno, print recno,
...@@ -54,7 +54,7 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -54,7 +54,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
if verbose: if verbose:
print data print data
self.assertEqual(type(data), type("")) self.assertIsInstance(data, str)
self.assertEqual(data, d.get(recno)) self.assertEqual(data, d.get(recno))
try: try:
...@@ -91,21 +91,21 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -91,21 +91,21 @@ class SimpleRecnoTestCase(unittest.TestCase):
keys = d.keys() keys = d.keys()
if verbose: if verbose:
print keys print keys
self.assertEqual(type(keys), type([])) self.assertIsInstance(keys, list)
self.assertEqual(type(keys[0]), type(123)) self.assertIsInstance(keys[0], int)
self.assertEqual(len(keys), len(d)) self.assertEqual(len(keys), len(d))
items = d.items() items = d.items()
if verbose: if verbose:
pprint(items) pprint(items)
self.assertEqual(type(items), type([])) self.assertIsInstance(items, list)
self.assertEqual(type(items[0]), type(())) self.assertIsInstance(items[0], tuple)
self.assertEqual(len(items[0]), 2) self.assertEqual(len(items[0]), 2)
self.assertEqual(type(items[0][0]), type(123)) self.assertIsInstance(items[0][0], int)
self.assertEqual(type(items[0][1]), type("")) self.assertIsInstance(items[0][1], str)
self.assertEqual(len(items), len(d)) self.assertEqual(len(items), len(d))
self.assert_(d.has_key(25)) self.assertTrue(d.has_key(25))
del d[25] del d[25]
self.assertFalse(d.has_key(25)) self.assertFalse(d.has_key(25))
...@@ -177,7 +177,7 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -177,7 +177,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
if get_returns_none: if get_returns_none:
self.fail("unexpected DBKeyEmptyError exception") self.fail("unexpected DBKeyEmptyError exception")
else: else:
self.assertEqual(val[0], db.DB_KEYEMPTY) self.assertEqual(val.args[0], db.DB_KEYEMPTY)
if verbose: print val if verbose: print val
else: else:
if not get_returns_none: if not get_returns_none:
......
...@@ -186,11 +186,11 @@ class DBReplicationManager(unittest.TestCase): ...@@ -186,11 +186,11 @@ class DBReplicationManager(unittest.TestCase):
import time import time
timeout=time.time()+10 timeout=time.time()+10
v=None v=None
while (time.time()<timeout) and (v==None) : while (time.time()<timeout) and (v is None) :
txn=self.dbenvClient.txn_begin() txn=self.dbenvClient.txn_begin()
v=self.dbClient.get("ABC", txn=txn) v=self.dbClient.get("ABC", txn=txn)
txn.commit() txn.commit()
if v==None : if v is None :
time.sleep(0.02) time.sleep(0.02)
# If startup did not happen before the timeout above, then this test # If startup did not happen before the timeout above, then this test
# sometimes fails. This happens randomly, which causes buildbot # sometimes fails. This happens randomly, which causes buildbot
...@@ -207,11 +207,11 @@ class DBReplicationManager(unittest.TestCase): ...@@ -207,11 +207,11 @@ class DBReplicationManager(unittest.TestCase):
self.dbMaster.delete("ABC", txn=txn) self.dbMaster.delete("ABC", txn=txn)
txn.commit() txn.commit()
timeout=time.time()+10 timeout=time.time()+10
while (time.time()<timeout) and (v!=None) : while (time.time()<timeout) and (v is not None) :
txn=self.dbenvClient.txn_begin() txn=self.dbenvClient.txn_begin()
v=self.dbClient.get("ABC", txn=txn) v=self.dbClient.get("ABC", txn=txn)
txn.commit() txn.commit()
if v==None : if v is None :
time.sleep(0.02) time.sleep(0.02)
self.assertTrue(time.time()<timeout) self.assertTrue(time.time()<timeout)
self.assertEquals(None, v) self.assertEquals(None, v)
...@@ -311,7 +311,7 @@ class DBBaseReplication(DBReplicationManager): ...@@ -311,7 +311,7 @@ class DBBaseReplication(DBReplicationManager):
def thread_do(env, q, envid, election_status, must_be_master) : def thread_do(env, q, envid, election_status, must_be_master) :
while True : while True :
v=q.get() v=q.get()
if v == None : return if v is None : return
env.rep_process_message(v[0], v[1], envid) env.rep_process_message(v[0], v[1], envid)
self.thread_do = thread_do self.thread_do = thread_do
...@@ -364,11 +364,11 @@ class DBBaseReplication(DBReplicationManager): ...@@ -364,11 +364,11 @@ class DBBaseReplication(DBReplicationManager):
import time import time
timeout=time.time()+10 timeout=time.time()+10
v=None v=None
while (time.time()<timeout) and (v==None) : while (time.time()<timeout) and (v is None) :
txn=self.dbenvClient.txn_begin() txn=self.dbenvClient.txn_begin()
v=self.dbClient.get("ABC", txn=txn) v=self.dbClient.get("ABC", txn=txn)
txn.commit() txn.commit()
if v==None : if v is None :
time.sleep(0.02) time.sleep(0.02)
self.assertTrue(time.time()<timeout) self.assertTrue(time.time()<timeout)
self.assertEquals("123", v) self.assertEquals("123", v)
...@@ -377,11 +377,11 @@ class DBBaseReplication(DBReplicationManager): ...@@ -377,11 +377,11 @@ class DBBaseReplication(DBReplicationManager):
self.dbMaster.delete("ABC", txn=txn) self.dbMaster.delete("ABC", txn=txn)
txn.commit() txn.commit()
timeout=time.time()+10 timeout=time.time()+10
while (time.time()<timeout) and (v!=None) : while (time.time()<timeout) and (v is not None) :
txn=self.dbenvClient.txn_begin() txn=self.dbenvClient.txn_begin()
v=self.dbClient.get("ABC", txn=txn) v=self.dbClient.get("ABC", txn=txn)
txn.commit() txn.commit()
if v==None : if v is None :
time.sleep(0.02) time.sleep(0.02)
self.assertTrue(time.time()<timeout) self.assertTrue(time.time()<timeout)
self.assertEquals(None, v) self.assertEquals(None, v)
...@@ -404,7 +404,7 @@ class DBBaseReplication(DBReplicationManager): ...@@ -404,7 +404,7 @@ class DBBaseReplication(DBReplicationManager):
def thread_do(env, q, envid, election_status, must_be_master) : def thread_do(env, q, envid, election_status, must_be_master) :
while True : while True :
v=q.get() v=q.get()
if v == None : return if v is None : return
r = env.rep_process_message(v[0],v[1],envid) r = env.rep_process_message(v[0],v[1],envid)
if must_be_master and self.confirmed_master : if must_be_master and self.confirmed_master :
self.dbenvMaster.rep_start(flags = db.DB_REP_MASTER) self.dbenvMaster.rep_start(flags = db.DB_REP_MASTER)
......
...@@ -424,7 +424,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -424,7 +424,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
readers.pop().start() readers.pop().start()
except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val: except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val:
if verbose: if verbose:
print "%s: Aborting transaction (%s)" % (name, val[1]) print "%s: Aborting transaction (%s)" % (name, val.args[1])
txn.abort() txn.abort()
if verbose: if verbose:
...@@ -455,7 +455,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -455,7 +455,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
finished = True finished = True
except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val: except (db.DBLockDeadlockError, db.DBLockNotGrantedError), val:
if verbose: if verbose:
print "%s: Aborting transaction (%s)" % (name, val[1]) print "%s: Aborting transaction (%s)" % (name, val.args[1])
c.close() c.close()
txn.abort() txn.abort()
......
...@@ -7,8 +7,7 @@ import sys ...@@ -7,8 +7,7 @@ import sys
import tempfile import tempfile
import time import time
import unittest import unittest
from test.test_support import (requires, verbose, run_unittest, unlink, rmtree, from test.test_support import requires, run_unittest, import_module
import_module)
# Skip test if _bsddb module was not built. # Skip test if _bsddb module was not built.
import_module('_bsddb') import_module('_bsddb')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment