commit d617d4ec0e442177c64b6a5578ad049798383d57 Author: Isis Lovecruft isis@torproject.org Date: Mon Apr 21 17:05:38 2014 +0000
Remove unused Storage.SqliteDict class. --- lib/bridgedb/Storage.py | 77 ----------------------------------------------- lib/bridgedb/Tests.py | 49 ++---------------------------- 2 files changed, 2 insertions(+), 124 deletions(-)
diff --git a/lib/bridgedb/Storage.py b/lib/bridgedb/Storage.py index 72c0af2..ab0bf74 100644 --- a/lib/bridgedb/Storage.py +++ b/lib/bridgedb/Storage.py @@ -31,80 +31,6 @@ def timeToStr(t): def strToTime(t): return calendar.timegm(time.strptime(t, "%Y-%m-%d %H:%M"))
-class SqliteDict: - """ - A SqliteDict wraps a SQLite table and makes it look like a - Python dictionary. In addition to the single key and value - columns, there can be a number of "fixed" columns, such that - the dictionary only contains elements of the table where the - fixed columns are set appropriately. - """ - def __init__(self, conn, cursor, table, fixedcolnames, fixedcolvalues, - keycol, valcol): - assert len(fixedcolnames) == len(fixedcolvalues) - self._conn = conn - self._cursor = cursor - keys = ", ".join(fixedcolnames+(keycol,valcol)) - vals = "".join("%s, "%_escapeValue(v) for v in fixedcolvalues) - constraint = "WHERE %s = ?"%keycol - if fixedcolnames: - constraint += "".join( - " AND %s = %s"%(c,_escapeValue(v)) - for c,v in zip(fixedcolnames, fixedcolvalues)) - - self._getStmt = "SELECT %s FROM %s %s"%(valcol,table,constraint) - self._delStmt = "DELETE FROM %s %s"%(table,constraint) - self._setStmt = "INSERT OR REPLACE INTO %s (%s) VALUES (%s?, ?)"%( - table, keys, vals) - - constraint = " AND ".join("%s = %s"%(c,_escapeValue(v)) - for c,v in zip(fixedcolnames, fixedcolvalues)) - if constraint: - whereClause = " WHERE %s"%constraint - else: - whereClause = "" - - self._keysStmt = "SELECT %s FROM %s%s"%(keycol,table,whereClause) - - def __setitem__(self, k, v): - self._cursor.execute(self._setStmt, (k,v)) - def __delitem__(self, k): - self._cursor.execute(self._delStmt, (k,)) - if self._cursor.rowcount == 0: - raise KeyError(k) - def __getitem__(self, k): - self._cursor.execute(self._getStmt, (k,)) - val = self._cursor.fetchone() - if val == None: - raise KeyError(k) - else: - return val[0] - def has_key(self, k): - self._cursor.execute(self._getStmt, (k,)) - return self._cursor.rowcount != 0 - def get(self, k, v=None): - self._cursor.execute(self._getStmt, (k,)) - val = self._cursor.fetchone() - if val == None: - return v - else: - return val[0] - def setdefault(self, k, v): - try: - r = self[k] - except KeyError: - r = self[k] = v - return r - def keys(self): - self._cursor.execute(self._keysStmt) - return [ key for (key,) in self._cursor.fetchall() ] - - def commit(self): - self._conn.commit() - def rollback(self): - self._conn.rollback() - - # The old DB system was just a key->value mapping DB, with special key # prefixes to indicate which database they fell into. # @@ -120,9 +46,6 @@ class SqliteDict: # of persistence any more.
# Here is the SQL schema. - - - SCHEMA2_SCRIPT = """ CREATE TABLE Config ( key PRIMARY KEY NOT NULL, diff --git a/lib/bridgedb/Tests.py b/lib/bridgedb/Tests.py index 4147549..6fcdbc6 100644 --- a/lib/bridgedb/Tests.py +++ b/lib/bridgedb/Tests.py @@ -436,51 +436,6 @@ class IPBridgeDistTests(unittest.TestCase): filterBridgesByNotBlockedIn("us")]) assert len(b) > 0
-class DictStorageTests(unittest.TestCase): - def setUp(self): - self.fd, self.fname = tempfile.mkstemp() - self.conn = sqlite3.Connection(self.fname) - - def tearDown(self): - self.conn.close() - os.close(self.fd) - os.unlink(self.fname) - - def testSimpleDict(self): - self.conn.execute("CREATE TABLE A ( X PRIMARY KEY, Y )") - d = bridgedb.Storage.SqliteDict(self.conn, self.conn.cursor(), - "A", (), (), "X", "Y") - - self.basictests(d) - - def testComplexDict(self): - self.conn.execute("CREATE TABLE B ( X, Y, Z, " - "CONSTRAINT B_PK PRIMARY KEY (X,Y) )") - d = bridgedb.Storage.SqliteDict(self.conn, self.conn.cursor(), - "B", ("X",), ("x1",), "Y", "Z") - d2 = bridgedb.Storage.SqliteDict(self.conn, self.conn.cursor(), - "B", ("X",), ("x2",), "Y", "Z") - self.basictests(d) - self.basictests(d2) - - def basictests(self, d): - d["hello"] = "goodbye" - d["hola"] = "adios" - self.assertEquals(d["hola"], "adios") - d["hola"] = "hasta luego" - self.assertEquals(d["hola"], "hasta luego") - self.assertEquals(sorted(d.keys()), [u"hello", u"hola"]) - self.assertRaises(KeyError, d.__getitem__, "buongiorno") - self.assertEquals(d.get("buongiorno", "ciao"), "ciao") - self.conn.commit() - d["buongiorno"] = "ciao" - del d['hola'] - self.assertRaises(KeyError, d.__getitem__, "hola") - self.conn.rollback() - self.assertEquals(d["hola"], "hasta luego") - self.assertEquals(d.setdefault("hola","bye"), "hasta luego") - self.assertEquals(d.setdefault("yo","bye"), "bye") - self.assertEquals(d['yo'], "bye")
class SQLStorageTests(unittest.TestCase): def setUp(self): @@ -806,8 +761,8 @@ def testSuite(): suite = unittest.TestSuite() loader = unittest.TestLoader()
- for klass in [ IPBridgeDistTests, DictStorageTests, SQLStorageTests, - EmailBridgeDistTests, ParseDescFileTests, BridgeStabilityTests ]: + for klass in [IPBridgeDistTests, SQLStorageTests, EmailBridgeDistTests, + ParseDescFileTests, BridgeStabilityTests]: suite.addTest(loader.loadTestsFromTestCase(klass))
for module in [ bridgedb.Bridges,
tor-commits@lists.torproject.org