|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: hyperdb.py,v 1.47 2002-01-14 02:20:15 richard Exp $ |
| 18 | +# $Id: hyperdb.py,v 1.48 2002-01-14 06:32:34 richard Exp $ |
19 | 19 |
|
20 | 20 | __doc__ = """ |
21 | 21 | Hyperdatabase implementation, especially field types. |
@@ -364,6 +364,7 @@ def create(self, **propvalues): |
364 | 364 | if isinstance(prop, Multilink): |
365 | 365 | propvalues[key] = [] |
366 | 366 | else: |
| 367 | + # TODO: None isn't right here, I think... |
367 | 368 | propvalues[key] = None |
368 | 369 |
|
369 | 370 | # convert all data to strings |
@@ -395,13 +396,21 @@ def get(self, nodeid, propname, default=_marker, cache=1): |
395 | 396 | if propname == 'id': |
396 | 397 | return nodeid |
397 | 398 |
|
| 399 | + # get the property (raises KeyErorr if invalid) |
| 400 | + prop = self.properties[propname] |
| 401 | + |
398 | 402 | # get the node's dict |
399 | 403 | d = self.db.getnode(self.classname, nodeid, cache=cache) |
400 | | - if not d.has_key(propname) and default is not _marker: |
401 | | - return default |
402 | 404 |
|
403 | | - # get the value |
404 | | - prop = self.properties[propname] |
| 405 | + if not d.has_key(propname): |
| 406 | + if default is _marker: |
| 407 | + if isinstance(prop, Multilink): |
| 408 | + return [] |
| 409 | + else: |
| 410 | + # TODO: None isn't right here, I think... |
| 411 | + return None |
| 412 | + else: |
| 413 | + return default |
405 | 414 |
|
406 | 415 | # possibly convert the marshalled data to instances |
407 | 416 | if isinstance(prop, Date): |
@@ -519,8 +528,11 @@ class or a KeyError is raised. |
519 | 528 | value = l |
520 | 529 | propvalues[key] = value |
521 | 530 |
|
522 | | - #handle removals |
523 | | - l = node[key] |
| 531 | + # handle removals |
| 532 | + if node.has_key(key): |
| 533 | + l = node[key] |
| 534 | + else: |
| 535 | + l = [] |
524 | 536 | for id in l[:]: |
525 | 537 | if id in value: |
526 | 538 | continue |
@@ -1029,6 +1041,15 @@ def Choice(name, *options): |
1029 | 1041 |
|
1030 | 1042 | # |
1031 | 1043 | # $Log: not supported by cvs2svn $ |
| 1044 | +# Revision 1.47 2002/01/14 02:20:15 richard |
| 1045 | +# . changed all config accesses so they access either the instance or the |
| 1046 | +# config attriubute on the db. This means that all config is obtained from |
| 1047 | +# instance_config instead of the mish-mash of classes. This will make |
| 1048 | +# switching to a ConfigParser setup easier too, I hope. |
| 1049 | +# |
| 1050 | +# At a minimum, this makes migration a _little_ easier (a lot easier in the |
| 1051 | +# 0.5.0 switch, I hope!) |
| 1052 | +# |
1032 | 1053 | # Revision 1.46 2002/01/07 10:42:23 richard |
1033 | 1054 | # oops |
1034 | 1055 | # |
|
0 commit comments