Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 704:54333751e98d search_indexing-0-4-2-branch
Brought search_indexing-branch up to date with latest changes in HEAD.
| author | Roche Compaan <rochecompaan@users.sourceforge.net> |
|---|---|
| date | Thu, 02 May 2002 13:09:11 +0000 |
| parents | 250d0d517f64 |
| children |
comparison
equal
deleted
inserted
replaced
| 703:8d2cb0d09da4 | 704:54333751e98d |
|---|---|
| 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.59.2.2 2002-04-20 13:23:33 rochecompaan Exp $ | 18 # $Id: hyperdb.py,v 1.59.2.3 2002-05-02 13:09:08 rochecompaan Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Hyperdatabase implementation, especially field types. | 21 Hyperdatabase implementation, especially field types. |
| 22 """ | 22 """ |
| 23 | 23 |
| 169 def addnode(self, classname, nodeid, node): | 169 def addnode(self, classname, nodeid, node): |
| 170 '''Add the specified node to its class's db. | 170 '''Add the specified node to its class's db. |
| 171 ''' | 171 ''' |
| 172 raise NotImplementedError | 172 raise NotImplementedError |
| 173 | 173 |
| 174 def serialise(self, classname, node): | |
| 175 '''Copy the node contents, converting non-marshallable data into | |
| 176 marshallable data. | |
| 177 ''' | |
| 178 if DEBUG: print 'serialise', classname, node | |
| 179 properties = self.getclass(classname).getprops() | |
| 180 d = {} | |
| 181 for k, v in node.items(): | |
| 182 # if the property doesn't exist, or is the "retired" flag then | |
| 183 # it won't be in the properties dict | |
| 184 if not properties.has_key(k): | |
| 185 d[k] = v | |
| 186 continue | |
| 187 | |
| 188 # get the property spec | |
| 189 prop = properties[k] | |
| 190 | |
| 191 if isinstance(prop, Password): | |
| 192 d[k] = str(v) | |
| 193 elif isinstance(prop, Date) and v is not None: | |
| 194 d[k] = v.get_tuple() | |
| 195 elif isinstance(prop, Interval) and v is not None: | |
| 196 d[k] = v.get_tuple() | |
| 197 else: | |
| 198 d[k] = v | |
| 199 return d | |
| 200 | |
| 174 def setnode(self, classname, nodeid, node): | 201 def setnode(self, classname, nodeid, node): |
| 175 '''Change the specified node. | 202 '''Change the specified node. |
| 176 ''' | 203 ''' |
| 177 raise NotImplementedError | 204 raise NotImplementedError |
| 205 | |
| 206 def unserialise(self, classname, node): | |
| 207 '''Decode the marshalled node data | |
| 208 ''' | |
| 209 if DEBUG: print 'unserialise', classname, node | |
| 210 properties = self.getclass(classname).getprops() | |
| 211 d = {} | |
| 212 for k, v in node.items(): | |
| 213 # if the property doesn't exist, or is the "retired" flag then | |
| 214 # it won't be in the properties dict | |
| 215 if not properties.has_key(k): | |
| 216 d[k] = v | |
| 217 continue | |
| 218 | |
| 219 # get the property spec | |
| 220 prop = properties[k] | |
| 221 | |
| 222 if isinstance(prop, Date) and v is not None: | |
| 223 d[k] = date.Date(v) | |
| 224 elif isinstance(prop, Interval) and v is not None: | |
| 225 d[k] = date.Interval(v) | |
| 226 elif isinstance(prop, Password): | |
| 227 p = password.Password() | |
| 228 p.unpack(v) | |
| 229 d[k] = p | |
| 230 else: | |
| 231 d[k] = v | |
| 232 return d | |
| 178 | 233 |
| 179 def getnode(self, classname, nodeid, db=None, cache=1): | 234 def getnode(self, classname, nodeid, db=None, cache=1): |
| 180 '''Get a node from the database. | 235 '''Get a node from the database. |
| 181 ''' | 236 ''' |
| 182 raise NotImplementedError | 237 raise NotImplementedError |
| 296 | 351 |
| 297 if self.db.journaltag is None: | 352 if self.db.journaltag is None: |
| 298 raise DatabaseError, 'Database open read-only' | 353 raise DatabaseError, 'Database open read-only' |
| 299 | 354 |
| 300 # new node's id | 355 # new node's id |
| 301 newid = str(self.count() + 1) | 356 newid = self.db.newid(self.classname) |
| 302 | 357 |
| 303 # validate propvalues | 358 # validate propvalues |
| 304 num_re = re.compile('^\d+$') | 359 num_re = re.compile('^\d+$') |
| 305 for key, value in propvalues.items(): | 360 for key, value in propvalues.items(): |
| 306 if key == self.key: | 361 if key == self.key: |
| 394 propvalues[key] = [] | 449 propvalues[key] = [] |
| 395 else: | 450 else: |
| 396 # TODO: None isn't right here, I think... | 451 # TODO: None isn't right here, I think... |
| 397 propvalues[key] = None | 452 propvalues[key] = None |
| 398 | 453 |
| 399 # convert all data to strings | |
| 400 for key, prop in self.properties.items(): | |
| 401 if isinstance(prop, Date): | |
| 402 if propvalues[key] is not None: | |
| 403 propvalues[key] = propvalues[key].get_tuple() | |
| 404 elif isinstance(prop, Interval): | |
| 405 if propvalues[key] is not None: | |
| 406 propvalues[key] = propvalues[key].get_tuple() | |
| 407 elif isinstance(prop, Password): | |
| 408 propvalues[key] = str(propvalues[key]) | |
| 409 | |
| 410 # done | 454 # done |
| 411 self.db.addnode(self.classname, newid, propvalues) | 455 self.db.addnode(self.classname, newid, propvalues) |
| 412 self.db.addjournal(self.classname, newid, 'create', propvalues) | 456 self.db.addjournal(self.classname, newid, 'create', propvalues) |
| 413 return newid | 457 return newid |
| 414 | 458 |
| 440 else: | 484 else: |
| 441 # TODO: None isn't right here, I think... | 485 # TODO: None isn't right here, I think... |
| 442 return None | 486 return None |
| 443 else: | 487 else: |
| 444 return default | 488 return default |
| 445 | |
| 446 # possibly convert the marshalled data to instances | |
| 447 if isinstance(prop, Date): | |
| 448 if d[propname] is None: | |
| 449 return None | |
| 450 return date.Date(d[propname]) | |
| 451 elif isinstance(prop, Interval): | |
| 452 if d[propname] is None: | |
| 453 return None | |
| 454 return date.Interval(d[propname]) | |
| 455 elif isinstance(prop, Password): | |
| 456 p = password.Password() | |
| 457 p.unpack(d[propname]) | |
| 458 return p | |
| 459 | 489 |
| 460 return d[propname] | 490 return d[propname] |
| 461 | 491 |
| 462 # XXX not in spec | 492 # XXX not in spec |
| 463 def getnode(self, nodeid, cache=1): | 493 def getnode(self, nodeid, cache=1): |
| 603 raise TypeError, 'new property "%s" not a string'%key | 633 raise TypeError, 'new property "%s" not a string'%key |
| 604 | 634 |
| 605 elif isinstance(prop, Password): | 635 elif isinstance(prop, Password): |
| 606 if not isinstance(value, password.Password): | 636 if not isinstance(value, password.Password): |
| 607 raise TypeError, 'new property "%s" not a Password'% key | 637 raise TypeError, 'new property "%s" not a Password'% key |
| 608 propvalues[key] = value = str(value) | 638 propvalues[key] = value |
| 609 | 639 |
| 610 elif value is not None and isinstance(prop, Date): | 640 elif value is not None and isinstance(prop, Date): |
| 611 if not isinstance(value, date.Date): | 641 if not isinstance(value, date.Date): |
| 612 raise TypeError, 'new property "%s" not a Date'% key | 642 raise TypeError, 'new property "%s" not a Date'% key |
| 613 propvalues[key] = value = value.get_tuple() | 643 propvalues[key] = value |
| 614 | 644 |
| 615 elif value is not None and isinstance(prop, Interval): | 645 elif value is not None and isinstance(prop, Interval): |
| 616 if not isinstance(value, date.Interval): | 646 if not isinstance(value, date.Interval): |
| 617 raise TypeError, 'new property "%s" not an Interval'% key | 647 raise TypeError, 'new property "%s" not an Interval'% key |
| 618 propvalues[key] = value = value.get_tuple() | 648 propvalues[key] = value |
| 619 | 649 |
| 620 node[key] = value | 650 node[key] = value |
| 621 | 651 |
| 622 # nothing to do? | 652 # nothing to do? |
| 623 if not propvalues: | 653 if not propvalues: |
| 1106 cl.create(name=options[i], order=i) | 1136 cl.create(name=options[i], order=i) |
| 1107 return hyperdb.Link(name) | 1137 return hyperdb.Link(name) |
| 1108 | 1138 |
| 1109 # | 1139 # |
| 1110 # $Log: not supported by cvs2svn $ | 1140 # $Log: not supported by cvs2svn $ |
| 1141 # Revision 1.63 2002/04/15 23:25:15 richard | |
| 1142 # . node ids are now generated from a lockable store - no more race conditions | |
| 1143 # | |
| 1144 # We're using the portalocker code by Jonathan Feinberg that was contributed | |
| 1145 # to the ASPN Python cookbook. This gives us locking across Unix and Windows. | |
| 1146 # | |
| 1147 # Revision 1.62 2002/04/03 07:05:50 richard | |
| 1148 # d'oh! killed retirement of nodes :( | |
| 1149 # all better now... | |
| 1150 # | |
| 1151 # Revision 1.61 2002/04/03 06:11:51 richard | |
| 1152 # Fix for old databases that contain properties that don't exist any more. | |
| 1153 # | |
| 1154 # Revision 1.60 2002/04/03 05:54:31 richard | |
| 1155 # Fixed serialisation problem by moving the serialisation step out of the | |
| 1156 # hyperdb.Class (get, set) into the hyperdb.Database. | |
| 1157 # | |
| 1158 # Also fixed htmltemplate after the showid changes I made yesterday. | |
| 1159 # | |
| 1160 # Unit tests for all of the above written. | |
| 1161 # | |
| 1162 # Revision 1.59.2.2 2002/04/20 13:23:33 rochecompaan | |
| 1163 # We now have a separate search page for nodes. Search links for | |
| 1164 # different classes can be customized in instance_config similar to | |
| 1165 # index links. | |
| 1166 # | |
| 1111 # Revision 1.59.2.1 2002/04/19 19:54:42 rochecompaan | 1167 # Revision 1.59.2.1 2002/04/19 19:54:42 rochecompaan |
| 1112 # cgi_client.py | 1168 # cgi_client.py |
| 1113 # removed search link for the time being | 1169 # removed search link for the time being |
| 1114 # moved rendering of matches to htmltemplate | 1170 # moved rendering of matches to htmltemplate |
| 1115 # hyperdb.py | 1171 # hyperdb.py |
