Code

Added 'Users may only edit their issues' customisation example.
[roundup.git] / roundup / hyperdb.py
index 245b917d4105ee06f69a5b484540b268e3511445..c8ca0a57ff593596bf02f5b1e125f3e93e8ab15f 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: hyperdb.py,v 1.91 2003-11-11 00:35:13 richard Exp $
+# $Id: hyperdb.py,v 1.95 2003-11-16 22:56:46 jlgijsbers Exp $
 
 """
 Hyperdatabase implementation, especially field types.
@@ -163,8 +163,7 @@ transaction.
 Implementation
 --------------
 
-All methods except __repr__ and getnode must be implemented by a
-concrete backend Class.
+All methods except __repr__ must be implemented by a concrete backend Database.
 
 '''
 
@@ -231,8 +230,8 @@ concrete backend Class.
         raise NotImplementedError
 
     def addnode(self, classname, nodeid, node):
-        '''Add the specified node to its class's db.
-        '''
+        """Add the specified node to its class's db.
+        """
         raise NotImplementedError
 
     def serialise(self, classname, node):
@@ -374,6 +373,7 @@ class Class:
         """
         raise NotImplementedError
 
+    # not in spec
     def getnode(self, nodeid, cache=1):
         ''' Return a convenience wrapper for the node.
 
@@ -572,6 +572,16 @@ class Class:
         '''
         raise NotImplementedError
 
+    def safeget(self, nodeid, propname, default=None):
+        """Safely get the value of a property on an existing node of this class.
+
+        Return 'default' if the node doesn't exist.
+        """
+        try:
+            return self.get(nodeid, propname)
+        except IndexError:
+            return default            
+
 class HyperdbValueError(ValueError):
     ''' Error converting a raw value into a Hyperdb value '''
     pass
@@ -592,12 +602,12 @@ def convertLinkValue(db, propname, prop, value, idre=re.compile('\d+')):
     return value
 
 def fixNewlines(text):
-    ''' Homogenise line endings.
+    """ Homogenise line endings.
 
         Different web clients send different line ending values, but
         other systems (eg. email) don't necessarily handle those line
         endings. Our solution is to convert all line endings to LF.
-    '''
+    """
     text = text.replace('\r\n', '\n')
     return text.replace('\r', '\n')