Skip to content

Commit dbed319

Browse files
committed
Remove key_in() from roundup.anypy.dbm_
The key_in() function was just a shim to use the best available option out of 'd.has_key(key)' and 'key in d'. The 'd.has_key(key)' flavour has been deprecated in favour of 'key in d' which based on testing has been available since at least python v2.5 which is the oldest being supported.
1 parent 7935eb0 commit dbed319

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

roundup/anypy/dbm_.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
# package containing the various implementations. The "wichdb" module's
33
# whichdb() function was moved to the new "dbm" module.
44

5-
import sys
6-
if sys.version_info[:2] < (2, 6):
7-
def key_in(db, key):
8-
return db.has_key(key)
9-
else:
10-
def key_in(db, key):
11-
return key in db
12-
135
try:
146
# old school first because <3 had a "dbm" module too...
157
import anydbm

roundup/backends/back_anydbm.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import os, marshal, re, weakref, string, copy, time, shutil, logging
2626

27-
from roundup.anypy.dbm_ import anydbm, whichdb, key_in
27+
from roundup.anypy.dbm_ import anydbm, whichdb
2828

2929
from roundup import hyperdb, date, password, roundupdb, security, support
3030
from roundup.backends import locking
@@ -332,7 +332,7 @@ def newid(self, classname):
332332
"""
333333
# open the ids DB - create if if doesn't exist
334334
db = self.opendb('_ids', 'c')
335-
if key_in(db, classname):
335+
if classname in db:
336336
newid = db[classname] = str(int(db[classname]) + 1)
337337
else:
338338
# the count() bit is transitional - older dbs won't start at 1
@@ -409,7 +409,7 @@ def getnode(self, classname, nodeid, db=None, cache=1):
409409
# get from the database and save in the cache
410410
if db is None:
411411
db = self.getclassdb(classname)
412-
if not key_in(db, nodeid):
412+
if nodeid not in db:
413413
raise IndexError("no such %s %s"%(classname, nodeid))
414414

415415
# check the uncommitted, destroyed nodes
@@ -521,7 +521,7 @@ def hasnode(self, classname, nodeid, db=None):
521521
# not in the cache - check the database
522522
if db is None:
523523
db = self.getclassdb(classname)
524-
return key_in(db, nodeid)
524+
return nodeid in db
525525

526526
def countnodes(self, classname, db=None):
527527
count = 0
@@ -783,7 +783,7 @@ def doSaveJournal(self, classname, nodeid, action, params, creator,
783783
db = self.getCachedJournalDB(classname)
784784

785785
# now insert the journal entry
786-
if key_in(db, nodeid):
786+
if nodeid in db:
787787
# append to existing
788788
s = db[nodeid]
789789
l = marshal.loads(s)
@@ -808,12 +808,12 @@ def doSetJournal(self, classname, nodeid, journal):
808808
def doDestroyNode(self, classname, nodeid):
809809
# delete from the class database
810810
db = self.getCachedClassDB(classname)
811-
if key_in(db, nodeid):
811+
if nodeid in db:
812812
del db[nodeid]
813813

814814
# delete from the database
815815
db = self.getCachedJournalDB(classname)
816-
if key_in(db, nodeid):
816+
if nodeid in db:
817817
del db[nodeid]
818818

819819
def rollback(self):
@@ -1624,7 +1624,7 @@ def getnodeids(self, db=None, retired=None):
16241624
# remove the uncommitted, destroyed nodes
16251625
if self.classname in self.db.destroyednodes:
16261626
for nodeid in self.db.destroyednodes[self.classname]:
1627-
if key_in(db, nodeid):
1627+
if nodeid in db:
16281628
res.remove(nodeid)
16291629

16301630
# check retired flag

roundup/backends/sessions_dbm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from cgi import escape
1212
from roundup import hyperdb
1313
from roundup.i18n import _
14-
from roundup.anypy.dbm_ import anydbm, whichdb, key_in
14+
from roundup.anypy.dbm_ import anydbm, whichdb
15+
1516

1617
class BasicDatabase:
1718
''' Provide a nice encapsulation of an anydbm store.
@@ -28,7 +29,7 @@ def __init__(self, db):
2829
def exists(self, infoid):
2930
db = self.opendb('c')
3031
try:
31-
return key_in(db, infoid)
32+
return infoid in db
3233
finally:
3334
db.close()
3435

@@ -57,10 +58,11 @@ def cache_db_type(self, path):
5758
self.__class__._db_type = db_type
5859

5960
_marker = []
61+
6062
def get(self, infoid, value, default=_marker):
6163
db = self.opendb('c')
6264
try:
63-
if key_in(db, infoid):
65+
if infoid in db:
6466
values = marshal.loads(db[infoid])
6567
else:
6668
if default != self._marker:
@@ -85,7 +87,7 @@ def getall(self, infoid):
8587
def set(self, infoid, **newvalues):
8688
db = self.opendb('c')
8789
try:
88-
if key_in(db, infoid):
90+
if infoid in db:
8991
values = marshal.loads(db[infoid])
9092
else:
9193
values = {'__timestamp': time.time()}
@@ -104,7 +106,7 @@ def list(self):
104106
def destroy(self, infoid):
105107
db = self.opendb('c')
106108
try:
107-
if key_in(db, infoid):
109+
if infoid in db:
108110
del db[infoid]
109111
finally:
110112
db.close()

0 commit comments

Comments
 (0)