Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 275:1cc866cec608
Moved the data stringification up into the hyperdb.Class class's...
...get, set and create methods. This means that the data is also
stringified for the journal call, and removes duplication of code from
the backends. The backend code now only sees strings.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 09 Oct 2001 23:58:10 +0000 |
| parents | a4241ddd22d7 |
| children | a5dabf2430c5 |
comparison
equal
deleted
inserted
replaced
| 274:79226fbb7741 | 275:1cc866cec608 |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: hyperdb.py,v 1.22 2001-10-09 07:25:59 richard Exp $ | 18 # $Id: hyperdb.py,v 1.23 2001-10-09 23:58:10 richard Exp $ |
| 19 | 19 |
| 20 # standard python modules | 20 # standard python modules |
| 21 import cPickle, re, string | 21 import cPickle, re, string |
| 22 | 22 |
| 23 # roundup modules | 23 # roundup modules |
| 204 | 204 |
| 205 elif isinstance(prop, Interval): | 205 elif isinstance(prop, Interval): |
| 206 if not isinstance(value, date.Interval): | 206 if not isinstance(value, date.Interval): |
| 207 raise TypeError, 'new property "%s" not an Interval'%key | 207 raise TypeError, 'new property "%s" not an Interval'%key |
| 208 | 208 |
| 209 # make sure there's data where there needs to be | |
| 209 for key, prop in self.properties.items(): | 210 for key, prop in self.properties.items(): |
| 210 if propvalues.has_key(key): | 211 if propvalues.has_key(key): |
| 211 continue | 212 continue |
| 212 if key == self.key: | 213 if key == self.key: |
| 213 raise ValueError, 'key property "%s" is required'%key | 214 raise ValueError, 'key property "%s" is required'%key |
| 214 if isinstance(prop, Multilink): | 215 if isinstance(prop, Multilink): |
| 215 propvalues[key] = [] | 216 propvalues[key] = [] |
| 216 else: | 217 else: |
| 217 propvalues[key] = None | 218 propvalues[key] = None |
| 218 | 219 |
| 220 # convert all data to strings | |
| 221 for key, prop in self.properties.items(): | |
| 222 if isinstance(prop, Date): | |
| 223 propvalues[key] = propvalues[key].get_tuple() | |
| 224 elif isinstance(prop, Interval): | |
| 225 propvalues[key] = propvalues[key].get_tuple() | |
| 226 elif isinstance(prop, Password): | |
| 227 propvalues[key] = str(propvalues[key]) | |
| 228 | |
| 219 # done | 229 # done |
| 220 self.db.addnode(self.classname, newid, propvalues) | 230 self.db.addnode(self.classname, newid, propvalues) |
| 221 self.db.addjournal(self.classname, newid, 'create', propvalues) | 231 self.db.addjournal(self.classname, newid, 'create', propvalues) |
| 222 return newid | 232 return newid |
| 223 | 233 |
| 227 'nodeid' must be the id of an existing node of this class or an | 237 'nodeid' must be the id of an existing node of this class or an |
| 228 IndexError is raised. 'propname' must be the name of a property | 238 IndexError is raised. 'propname' must be the name of a property |
| 229 of this class or a KeyError is raised. | 239 of this class or a KeyError is raised. |
| 230 """ | 240 """ |
| 231 d = self.db.getnode(self.classname, nodeid) | 241 d = self.db.getnode(self.classname, nodeid) |
| 242 | |
| 243 # convert the marshalled data to instances | |
| 244 for key, prop in self.properties.items(): | |
| 245 if isinstance(prop, Date): | |
| 246 d[key] = date.Date(d[key]) | |
| 247 elif isinstance(prop, Interval): | |
| 248 d[key] = date.Interval(d[key]) | |
| 249 elif isinstance(prop, Password): | |
| 250 p = password.Password() | |
| 251 p.unpack(d[key]) | |
| 252 d[key] = p | |
| 253 | |
| 232 if propname == 'id': | 254 if propname == 'id': |
| 233 return nodeid | 255 return nodeid |
| 234 if not d.has_key(propname) and default is not _marker: | 256 if not d.has_key(propname) and default is not _marker: |
| 235 return default | 257 return default |
| 236 return d[propname] | 258 return d[propname] |
| 357 raise TypeError, 'new property "%s" not a string'%key | 379 raise TypeError, 'new property "%s" not a string'%key |
| 358 | 380 |
| 359 elif isinstance(prop, Password): | 381 elif isinstance(prop, Password): |
| 360 if not isinstance(value, password.Password): | 382 if not isinstance(value, password.Password): |
| 361 raise TypeError, 'new property "%s" not a Password'% key | 383 raise TypeError, 'new property "%s" not a Password'% key |
| 384 propvalues[key] = value = str(value) | |
| 362 | 385 |
| 363 elif isinstance(prop, Date): | 386 elif isinstance(prop, Date): |
| 364 if not isinstance(value, date.Date): | 387 if not isinstance(value, date.Date): |
| 365 raise TypeError, 'new property "%s" not a Date'% key | 388 raise TypeError, 'new property "%s" not a Date'% key |
| 389 propvalues[key] = value = value.get_tuple() | |
| 366 | 390 |
| 367 elif isinstance(prop, Interval): | 391 elif isinstance(prop, Interval): |
| 368 if not isinstance(value, date.Interval): | 392 if not isinstance(value, date.Interval): |
| 369 raise TypeError, 'new property "%s" not an Interval'% key | 393 raise TypeError, 'new property "%s" not an Interval'% key |
| 394 propvalues[key] = value = value.get_tuple() | |
| 370 | 395 |
| 371 node[key] = value | 396 node[key] = value |
| 372 | 397 |
| 373 self.db.setnode(self.classname, nodeid, node) | 398 self.db.setnode(self.classname, nodeid, node) |
| 374 self.db.addjournal(self.classname, nodeid, 'set', propvalues) | 399 self.db.addjournal(self.classname, nodeid, 'set', propvalues) |
| 812 cl.create(name=option[i], order=i) | 837 cl.create(name=option[i], order=i) |
| 813 return hyperdb.Link(name) | 838 return hyperdb.Link(name) |
| 814 | 839 |
| 815 # | 840 # |
| 816 # $Log: not supported by cvs2svn $ | 841 # $Log: not supported by cvs2svn $ |
| 842 # Revision 1.22 2001/10/09 07:25:59 richard | |
| 843 # Added the Password property type. See "pydoc roundup.password" for | |
| 844 # implementation details. Have updated some of the documentation too. | |
| 845 # | |
| 817 # Revision 1.21 2001/10/05 02:23:24 richard | 846 # Revision 1.21 2001/10/05 02:23:24 richard |
| 818 # . roundup-admin create now prompts for property info if none is supplied | 847 # . roundup-admin create now prompts for property info if none is supplied |
| 819 # on the command-line. | 848 # on the command-line. |
| 820 # . hyperdb Class getprops() method may now return only the mutable | 849 # . hyperdb Class getprops() method may now return only the mutable |
| 821 # properties. | 850 # properties. |
