|
1 | | -# $Id: hyperdb.py,v 1.4 2001-07-27 06:25:35 richard Exp $ |
| 1 | +# $Id: hyperdb.py,v 1.5 2001-07-29 04:05:37 richard Exp $ |
2 | 2 |
|
3 | 3 | # standard python modules |
4 | 4 | import cPickle, re, string |
@@ -98,8 +98,13 @@ def create(self, **propvalues): |
98 | 98 | If an id in a link or multilink property does not refer to a valid |
99 | 99 | node, an IndexError is raised. |
100 | 100 | """ |
| 101 | + if propvalues.has_key('id'): |
| 102 | + raise KeyError, '"id" is reserved' |
| 103 | + |
101 | 104 | if self.db.journaltag is None: |
102 | 105 | raise DatabaseError, 'Database open read-only' |
| 106 | + |
| 107 | + # new node's id |
103 | 108 | newid = str(self.count() + 1) |
104 | 109 |
|
105 | 110 | # validate propvalues |
@@ -194,6 +199,8 @@ def get(self, nodeid, propname): |
194 | 199 | IndexError is raised. 'propname' must be the name of a property |
195 | 200 | of this class or a KeyError is raised. |
196 | 201 | """ |
| 202 | + if propname == 'id': |
| 203 | + return nodeid |
197 | 204 | # nodeid = str(nodeid) |
198 | 205 | d = self.db.getnode(self.classname, nodeid) |
199 | 206 | return d[propname] |
@@ -224,8 +231,13 @@ class or a KeyError is raised. |
224 | 231 | """ |
225 | 232 | if not propvalues: |
226 | 233 | return |
| 234 | + |
| 235 | + if propvalues.has_key('id'): |
| 236 | + raise KeyError, '"id" is reserved' |
| 237 | + |
227 | 238 | if self.db.journaltag is None: |
228 | 239 | raise DatabaseError, 'Database open read-only' |
| 240 | + |
229 | 241 | # nodeid = str(nodeid) |
230 | 242 | node = self.db.getnode(self.classname, nodeid) |
231 | 243 | if node.has_key(self.db.RETIRED_FLAG): |
@@ -696,7 +708,9 @@ def count(self): |
696 | 708 |
|
697 | 709 | def getprops(self): |
698 | 710 | """Return a dictionary mapping property names to property objects.""" |
699 | | - return self.properties |
| 711 | + d = self.properties.copy() |
| 712 | + d['id'] = String() |
| 713 | + return d |
700 | 714 |
|
701 | 715 | def addprop(self, **properties): |
702 | 716 | """Add properties to this class. |
@@ -753,6 +767,11 @@ def Choice(name, *options): |
753 | 767 |
|
754 | 768 | # |
755 | 769 | # $Log: not supported by cvs2svn $ |
| 770 | +# Revision 1.4 2001/07/27 06:25:35 richard |
| 771 | +# Fixed some of the exceptions so they're the right type. |
| 772 | +# Removed the str()-ification of node ids so we don't mask oopsy errors any |
| 773 | +# more. |
| 774 | +# |
756 | 775 | # Revision 1.3 2001/07/27 05:17:14 richard |
757 | 776 | # just some comments |
758 | 777 | # |
|
0 commit comments