Skip to content

Commit 630b663

Browse files
author
Richard Jones
committed
Did some old TODOs
1 parent 7cdecd5 commit 630b663

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

roundup/backends/back_anydbm.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.45 2002-07-14 04:03:14 richard Exp $
18+
#$Id: back_anydbm.py,v 1.46 2002-07-14 06:06:34 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -143,16 +143,10 @@ def getclassdb(self, classname, mode='r'):
143143
print >>hyperdb.DEBUG, 'getclassdb', (self, classname, mode)
144144
return self._opendb('nodes.%s'%classname, mode)
145145

146-
def _opendb(self, name, mode):
147-
'''Low-level database opener that gets around anydbm/dbm
148-
eccentricities.
146+
def determine_db_type(self, path):
147+
''' determine which DB wrote the class file
149148
'''
150-
if __debug__:
151-
print >>hyperdb.DEBUG, '_opendb', (self, name, mode)
152-
153-
# determine which DB wrote the class file
154149
db_type = ''
155-
path = os.path.join(os.getcwd(), self.dir, name)
156150
if os.path.exists(path):
157151
db_type = whichdb.whichdb(path)
158152
if not db_type:
@@ -161,6 +155,18 @@ def _opendb(self, name, mode):
161155
# if the path ends in '.db', it's a dbm database, whether
162156
# anydbm says it's dbhash or not!
163157
db_type = 'dbm'
158+
return db_type
159+
160+
def _opendb(self, name, mode):
161+
'''Low-level database opener that gets around anydbm/dbm
162+
eccentricities.
163+
'''
164+
if __debug__:
165+
print >>hyperdb.DEBUG, '_opendb', (self, name, mode)
166+
167+
# figure the class db type
168+
path = os.path.join(os.getcwd(), self.dir, name)
169+
db_type = self.determine_db_type(path)
164170

165171
# new database? let anydbm pick the best dbm
166172
if not db_type:
@@ -428,19 +434,12 @@ def pack(self, pack_before):
428434

429435
classes = self.getclasses()
430436

431-
# TODO: factor this out to method - we're already doing it in
432-
# _opendb.
433-
db_type = ''
434-
path = os.path.join(os.getcwd(), self.dir, classes[0])
435-
if os.path.exists(path):
436-
db_type = whichdb.whichdb(path)
437-
if not db_type:
438-
raise hyperdb.DatabaseError, "Couldn't identify database type"
439-
elif os.path.exists(path+'.db'):
440-
db_type = 'dbm'
437+
# figure the class db type
441438

442439
for classname in classes:
443440
db_name = 'journals.%s'%classname
441+
path = os.path.join(os.getcwd(), self.dir, classname)
442+
db_type = self.determine_db_type(path)
444443
db = self._opendb(db_name, 'w')
445444

446445
for key in db.keys():
@@ -740,7 +739,6 @@ def create(self, **propvalues):
740739
if isinstance(prop, Multilink):
741740
propvalues[key] = []
742741
else:
743-
# TODO: None isn't right here, I think...
744742
propvalues[key] = None
745743

746744
# done
@@ -809,7 +807,6 @@ def get(self, nodeid, propname, default=_marker, cache=1):
809807
if isinstance(prop, Multilink):
810808
return []
811809
else:
812-
# TODO: None isn't right here, I think...
813810
return None
814811
else:
815812
return default
@@ -1059,9 +1056,12 @@ def setkey(self, propname):
10591056
10601057
'propname' must be the name of a String property of this class or
10611058
None, or a TypeError is raised. The values of the key property on
1062-
all existing nodes must be unique or a ValueError is raised.
1059+
all existing nodes must be unique or a ValueError is raised. If the
1060+
property doesn't exist, KeyError is raised.
10631061
"""
1064-
# TODO: validate that the property is a String!
1062+
prop = self.getprops()[propname]
1063+
if not isinstance(prop, String):
1064+
raise TypeError, 'key properties must be String'
10651065
self.key = propname
10661066

10671067
def getkey(self):
@@ -1615,6 +1615,10 @@ def __init__(self, db, classname, **properties):
16151615

16161616
#
16171617
#$Log: not supported by cvs2svn $
1618+
#Revision 1.45 2002/07/14 04:03:14 richard
1619+
#Implemented a switch to disable journalling for a Class. CGI session
1620+
#database now uses it.
1621+
#
16181622
#Revision 1.44 2002/07/14 02:05:53 richard
16191623
#. all storage-specific code (ie. backend) is now implemented by the backends
16201624
#

test/test_db.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.29 2002-07-14 04:03:15 richard Exp $
18+
# $Id: test_db.py,v 1.30 2002-07-14 06:06:34 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

@@ -200,6 +200,14 @@ def testExceptions(self):
200200
ar(IndexError, self.db.issue.create, title='foo', status='1',
201201
nosy=['10'])
202202

203+
#
204+
# key property
205+
#
206+
# key must be a String
207+
ar(TypeError, self.db.user.setkey, 'password')
208+
# key must exist
209+
ar(KeyError, self.db.user.setkey, 'fubar')
210+
203211
#
204212
# class get
205213
#
@@ -524,6 +532,10 @@ def suite():
524532

525533
#
526534
# $Log: not supported by cvs2svn $
535+
# Revision 1.29 2002/07/14 04:03:15 richard
536+
# Implemented a switch to disable journalling for a Class. CGI session
537+
# database now uses it.
538+
#
527539
# Revision 1.28 2002/07/14 02:16:29 richard
528540
# Fixes for the metakit backend (removed the cut-n-paste IssueClass, removed
529541
# a special case for it in testing)

0 commit comments

Comments
 (0)