comparison roundup/hyperdb.py @ 1780:d2801a2b0a77

Initial implementation (half-baked) at new Tracker instance. Cleaned up caching API / comments in backends. Fixes to docs.
author Richard Jones <richard@users.sourceforge.net>
date Thu, 04 Sep 2003 00:47:01 +0000
parents 63aa7be52d2c
children 91a4619b1a14
comparison
equal deleted inserted replaced
1777:fbe08359511a 1780:d2801a2b0a77
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.87 2003-03-17 22:03:03 kedder Exp $ 18 # $Id: hyperdb.py,v 1.88 2003-09-04 00:47:01 richard Exp $
19 19
20 """ 20 """
21 Hyperdatabase implementation, especially field types. 21 Hyperdatabase implementation, especially field types.
22 """ 22 """
23 23
243 ''' 243 '''
244 return node 244 return node
245 245
246 def getnode(self, classname, nodeid, db=None, cache=1): 246 def getnode(self, classname, nodeid, db=None, cache=1):
247 '''Get a node from the database. 247 '''Get a node from the database.
248
249 'cache' exists for backwards compatibility, and is not used.
248 ''' 250 '''
249 raise NotImplementedError 251 raise NotImplementedError
250 252
251 def hasnode(self, classname, nodeid, db=None): 253 def hasnode(self, classname, nodeid, db=None):
252 '''Determine if the database has a given node. 254 '''Determine if the database has a given node.
363 365
364 'nodeid' must be the id of an existing node of this class or an 366 'nodeid' must be the id of an existing node of this class or an
365 IndexError is raised. 'propname' must be the name of a property 367 IndexError is raised. 'propname' must be the name of a property
366 of this class or a KeyError is raised. 368 of this class or a KeyError is raised.
367 369
368 'cache' indicates whether the transaction cache should be queried 370 'cache' exists for backwards compatibility, and is not used.
369 for the node. If the node has been modified and you need to
370 determine what its values prior to modification are, you need to
371 set cache=0.
372 """ 371 """
373 raise NotImplementedError 372 raise NotImplementedError
374 373
375 def getnode(self, nodeid, cache=1): 374 def getnode(self, nodeid, cache=1):
376 ''' Return a convenience wrapper for the node. 375 ''' Return a convenience wrapper for the node.
377 376
378 'nodeid' must be the id of an existing node of this class or an 377 'nodeid' must be the id of an existing node of this class or an
379 IndexError is raised. 378 IndexError is raised.
380 379
381 'cache' indicates whether the transaction cache should be queried 380 'cache' exists for backwards compatibility, and is not used.
382 for the node. If the node has been modified and you need to 381 '''
383 determine what its values prior to modification are, you need to 382 return Node(self, nodeid)
384 set cache=0.
385 '''
386 return Node(self, nodeid, cache=cache)
387 383
388 def set(self, nodeid, **propvalues): 384 def set(self, nodeid, **propvalues):
389 """Modify a property on an existing node of this class. 385 """Modify a property on an existing node of this class.
390 386
391 'nodeid' must be the id of an existing node of this class or an 387 'nodeid' must be the id of an existing node of this class or an
578 ''' A convenience wrapper for the given node 574 ''' A convenience wrapper for the given node
579 ''' 575 '''
580 def __init__(self, cl, nodeid, cache=1): 576 def __init__(self, cl, nodeid, cache=1):
581 self.__dict__['cl'] = cl 577 self.__dict__['cl'] = cl
582 self.__dict__['nodeid'] = nodeid 578 self.__dict__['nodeid'] = nodeid
583 self.__dict__['cache'] = cache
584 def keys(self, protected=1): 579 def keys(self, protected=1):
585 return self.cl.getprops(protected=protected).keys() 580 return self.cl.getprops(protected=protected).keys()
586 def values(self, protected=1): 581 def values(self, protected=1):
587 l = [] 582 l = []
588 for name in self.cl.getprops(protected=protected).keys(): 583 for name in self.cl.getprops(protected=protected).keys():
589 l.append(self.cl.get(self.nodeid, name, cache=self.cache)) 584 l.append(self.cl.get(self.nodeid, name))
590 return l 585 return l
591 def items(self, protected=1): 586 def items(self, protected=1):
592 l = [] 587 l = []
593 for name in self.cl.getprops(protected=protected).keys(): 588 for name in self.cl.getprops(protected=protected).keys():
594 l.append((name, self.cl.get(self.nodeid, name, cache=self.cache))) 589 l.append((name, self.cl.get(self.nodeid, name)))
595 return l 590 return l
596 def has_key(self, name): 591 def has_key(self, name):
597 return self.cl.getprops().has_key(name) 592 return self.cl.getprops().has_key(name)
598 def get(self, name, default=None): 593 def get(self, name, default=None):
599 if self.has_key(name): 594 if self.has_key(name):
602 return default 597 return default
603 def __getattr__(self, name): 598 def __getattr__(self, name):
604 if self.__dict__.has_key(name): 599 if self.__dict__.has_key(name):
605 return self.__dict__[name] 600 return self.__dict__[name]
606 try: 601 try:
607 return self.cl.get(self.nodeid, name, cache=self.cache) 602 return self.cl.get(self.nodeid, name)
608 except KeyError, value: 603 except KeyError, value:
609 # we trap this but re-raise it as AttributeError - all other 604 # we trap this but re-raise it as AttributeError - all other
610 # exceptions should pass through untrapped 605 # exceptions should pass through untrapped
611 pass 606 pass
612 # nope, no such attribute 607 # nope, no such attribute
613 raise AttributeError, str(value) 608 raise AttributeError, str(value)
614 def __getitem__(self, name): 609 def __getitem__(self, name):
615 return self.cl.get(self.nodeid, name, cache=self.cache) 610 return self.cl.get(self.nodeid, name)
616 def __setattr__(self, name, value): 611 def __setattr__(self, name, value):
617 try: 612 try:
618 return self.cl.set(self.nodeid, **{name: value}) 613 return self.cl.set(self.nodeid, **{name: value})
619 except KeyError, value: 614 except KeyError, value:
620 raise AttributeError, str(value) 615 raise AttributeError, str(value)

Roundup Issue Tracker: http://roundup-tracker.org/