Skip to content

Commit f585d0f

Browse files
author
Richard Jones
committed
Fixed some of the exceptions so they're the right type.
Removed the str()-ification of node ids so we don't mask oopsy errors any more.
1 parent 12fdd32 commit f585d0f

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

roundup/hyperdb.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: hyperdb.py,v 1.3 2001-07-27 05:17:14 richard Exp $
1+
# $Id: hyperdb.py,v 1.4 2001-07-27 06:25:35 richard Exp $
22

33
# standard python modules
44
import cPickle, re, string
@@ -116,17 +116,20 @@ def create(self, **propvalues):
116116
prop = self.properties[key]
117117

118118
if prop.isLinkType:
119-
value = str(value)
119+
if type(value) != type(''):
120+
raise ValueError, 'link value must be String'
121+
# value = str(value)
120122
link_class = self.properties[key].classname
123+
# if it isn't a number, it's a key
121124
if not num_re.match(value):
122125
try:
123126
value = self.db.classes[link_class].lookup(value)
124127
except:
125-
raise ValueError, 'new property "%s": %s not a %s'%(
128+
raise IndexError, 'new property "%s": %s not a %s'%(
126129
key, value, self.properties[key].classname)
127130
propvalues[key] = value
128131
if not self.db.hasnode(link_class, value):
129-
raise ValueError, '%s has no node %s'%(link_class, value)
132+
raise IndexError, '%s has no node %s'%(link_class, value)
130133

131134
# register the link with the newly linked node
132135
self.db.addjournal(link_class, value, 'link',
@@ -137,12 +140,15 @@ def create(self, **propvalues):
137140
raise TypeError, 'new property "%s" not a list of ids'%key
138141
link_class = self.properties[key].classname
139142
l = []
140-
for entry in map(str, value):
143+
for entry in value:
144+
if type(entry) != type(''):
145+
raise ValueError, 'link value must be String'
146+
# if it isn't a number, it's a key
141147
if not num_re.match(entry):
142148
try:
143149
entry = self.db.classes[link_class].lookup(entry)
144150
except:
145-
raise ValueError, 'new property "%s": %s not a %s'%(
151+
raise IndexError, 'new property "%s": %s not a %s'%(
146152
key, entry, self.properties[key].classname)
147153
l.append(entry)
148154
value = l
@@ -151,7 +157,7 @@ def create(self, **propvalues):
151157
# handle additions
152158
for id in value:
153159
if not self.db.hasnode(link_class, id):
154-
raise ValueError, '%s has no node %s'%(link_class, id)
160+
raise IndexError, '%s has no node %s'%(link_class, id)
155161
# register the link with the newly linked node
156162
self.db.addjournal(link_class, id, 'link',
157163
(self.classname, newid, key))
@@ -168,8 +174,8 @@ def create(self, **propvalues):
168174
if not hasattr(value, 'isInterval'):
169175
raise TypeError, 'new property "%s" not an Interval'% key
170176

171-
for key,prop in self.properties.items():
172-
if propvalues.has_key(str(key)):
177+
for key, prop in self.properties.items():
178+
if propvalues.has_key(key):
173179
continue
174180
if prop.isMultilinkType:
175181
propvalues[key] = []
@@ -188,7 +194,8 @@ def get(self, nodeid, propname):
188194
IndexError is raised. 'propname' must be the name of a property
189195
of this class or a KeyError is raised.
190196
"""
191-
d = self.db.getnode(self.classname, str(nodeid))
197+
# nodeid = str(nodeid)
198+
d = self.db.getnode(self.classname, nodeid)
192199
return d[propname]
193200

194201
# XXX not in spec
@@ -219,7 +226,7 @@ class or a KeyError is raised.
219226
return
220227
if self.db.journaltag is None:
221228
raise DatabaseError, 'Database open read-only'
222-
nodeid = str(nodeid)
229+
# nodeid = str(nodeid)
223230
node = self.db.getnode(self.classname, nodeid)
224231
if node.has_key(self.db.RETIRED_FLAG):
225232
raise IndexError
@@ -239,17 +246,20 @@ class or a KeyError is raised.
239246
prop = self.properties[key]
240247

241248
if prop.isLinkType:
242-
value = str(value)
249+
# value = str(value)
243250
link_class = self.properties[key].classname
251+
# if it isn't a number, it's a key
252+
if type(value) != type(''):
253+
raise ValueError, 'link value must be String'
244254
if not num_re.match(value):
245255
try:
246256
value = self.db.classes[link_class].lookup(value)
247257
except:
248-
raise ValueError, 'new property "%s": %s not a %s'%(
258+
raise IndexError, 'new property "%s": %s not a %s'%(
249259
key, value, self.properties[key].classname)
250260

251261
if not self.db.hasnode(link_class, value):
252-
raise ValueError, '%s has no node %s'%(link_class, value)
262+
raise IndexError, '%s has no node %s'%(link_class, value)
253263

254264
# register the unlink with the old linked node
255265
if node[key] is not None:
@@ -266,12 +276,15 @@ class or a KeyError is raised.
266276
raise TypeError, 'new property "%s" not a list of ids'%key
267277
link_class = self.properties[key].classname
268278
l = []
269-
for entry in map(str, value):
279+
for entry in value:
280+
# if it isn't a number, it's a key
281+
if type(entry) != type(''):
282+
raise ValueError, 'link value must be String'
270283
if not num_re.match(entry):
271284
try:
272285
entry = self.db.classes[link_class].lookup(entry)
273286
except:
274-
raise ValueError, 'new property "%s": %s not a %s'%(
287+
raise IndexError, 'new property "%s": %s not a %s'%(
275288
key, entry, self.properties[key].classname)
276289
l.append(entry)
277290
value = l
@@ -290,7 +303,7 @@ class or a KeyError is raised.
290303
# handle additions
291304
for id in value:
292305
if not self.db.hasnode(link_class, id):
293-
raise ValueError, '%s has no node %s'%(link_class, id)
306+
raise IndexError, '%s has no node %s'%(link_class, id)
294307
if id in l:
295308
continue
296309
# register the link with the newly linked node
@@ -324,7 +337,7 @@ def retire(self, nodeid):
324337
Retired nodes are not returned by the find(), list(), or lookup()
325338
methods, and other nodes may reuse the values of their key properties.
326339
"""
327-
nodeid = str(nodeid)
340+
# nodeid = str(nodeid)
328341
if self.db.journaltag is None:
329342
raise DatabaseError, 'Database open read-only'
330343
node = self.db.getnode(self.classname, nodeid)
@@ -395,7 +408,7 @@ def find(self, **propspec):
395408
"""
396409
propspec = propspec.items()
397410
for propname, nodeid in propspec:
398-
nodeid = str(nodeid)
411+
# nodeid = str(nodeid)
399412
# check the prop is OK
400413
prop = self.properties[propname]
401414
if not prop.isLinkType and not prop.isMultilinkType:
@@ -411,7 +424,7 @@ def find(self, **propspec):
411424
if node.has_key(self.db.RETIRED_FLAG):
412425
continue
413426
for propname, nodeid in propspec:
414-
nodeid = str(nodeid)
427+
# nodeid = str(nodeid)
415428
property = node[propname]
416429
if prop.isLinkType and nodeid == property:
417430
l.append(id)
@@ -740,6 +753,9 @@ def Choice(name, *options):
740753

741754
#
742755
# $Log: not supported by cvs2svn $
756+
# Revision 1.3 2001/07/27 05:17:14 richard
757+
# just some comments
758+
#
743759
# Revision 1.2 2001/07/22 12:09:32 richard
744760
# Final commit of Grande Splite
745761
#

0 commit comments

Comments
 (0)