diff roundup/hyperdb.py @ 4063:625915ce35b8

Uniformly use """...""" instead of '''...''' for comments.
author Stefan Seefeld <stefan@seefeld.name>
date Fri, 20 Feb 2009 16:03:03 +0000
parents 7ad0918ee8bd
children eddb82d0964c
line wrap: on
line diff
--- a/roundup/hyperdb.py	Fri Feb 20 12:45:57 2009 +0000
+++ b/roundup/hyperdb.py	Fri Feb 20 16:03:03 2009 +0000
@@ -15,7 +15,6 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: hyperdb.py,v 1.132 2008-08-18 06:21:53 richard Exp $
 
 """Hyperdatabase implementation, especially field types.
 """
@@ -137,8 +136,8 @@
     """An object designating a Pointer property that links or multilinks
     to a node in a specified class."""
     def __init__(self, classname, do_journal='yes', required=False):
-        ''' Default is to journal link and unlink events
-        '''
+        """ Default is to journal link and unlink events
+        """
         super(_Pointer, self).__init__(required)
         self.classname = classname
         self.do_journal = do_journal == 'yes'
@@ -273,15 +272,15 @@
 class DesignatorError(ValueError):
     pass
 def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')):
-    ''' Take a foo123 and return ('foo', 123)
-    '''
+    """ Take a foo123 and return ('foo', 123)
+    """
     m = dre.match(designator)
     if m is None:
         raise DesignatorError, _('"%s" not a node designator')%designator
     return m.group(1), m.group(2)
 
 class Proptree(object):
-    ''' Simple tree data structure for optimizing searching of
+    """ Simple tree data structure for optimizing searching of
     properties. Each node in the tree represents a roundup Class
     Property that has to be navigated for finding the given search
     or sort properties. The sort_type attribute is used for
@@ -293,7 +292,7 @@
     The Proptree is also used for transitively searching attributes for
     backends that do not support transitive search (e.g. anydbm). The
     _val attribute with set_val is used for this.
-    '''
+    """
 
     def __init__(self, db, cls, name, props, parent = None):
         self.db = db
@@ -565,11 +564,11 @@
 # the base Database class
 #
 class DatabaseError(ValueError):
-    '''Error to be raised when there is some problem in the database code
-    '''
+    """Error to be raised when there is some problem in the database code
+    """
     pass
 class Database:
-    '''A database for storing records containing flexible data types.
+    """A database for storing records containing flexible data types.
 
 This class defines a hyperdatabase storage layer, which the Classes use to
 store their data.
@@ -592,7 +591,7 @@
 
 All methods except __repr__ must be implemented by a concrete backend Database.
 
-'''
+"""
 
     # flag to set on retired entries
     RETIRED_FLAG = '__hyperdb_retired'
@@ -634,8 +633,8 @@
         raise NotImplementedError
 
     def addclass(self, cl):
-        '''Add a Class to the hyperdatabase.
-        '''
+        """Add a Class to the hyperdatabase.
+        """
         raise NotImplementedError
 
     def getclasses(self):
@@ -650,14 +649,14 @@
         raise NotImplementedError
 
     def clear(self):
-        '''Delete all database contents.
-        '''
+        """Delete all database contents.
+        """
         raise NotImplementedError
 
     def getclassdb(self, classname, mode='r'):
-        '''Obtain a connection to the class db that will be used for
+        """Obtain a connection to the class db that will be used for
            multiple actions.
-        '''
+        """
         raise NotImplementedError
 
     def addnode(self, classname, nodeid, node):
@@ -666,73 +665,73 @@
         raise NotImplementedError
 
     def serialise(self, classname, node):
-        '''Copy the node contents, converting non-marshallable data into
+        """Copy the node contents, converting non-marshallable data into
            marshallable data.
-        '''
+        """
         return node
 
     def setnode(self, classname, nodeid, node):
-        '''Change the specified node.
-        '''
+        """Change the specified node.
+        """
         raise NotImplementedError
 
     def unserialise(self, classname, node):
-        '''Decode the marshalled node data
-        '''
+        """Decode the marshalled node data
+        """
         return node
 
     def getnode(self, classname, nodeid):
-        '''Get a node from the database.
+        """Get a node from the database.
 
         'cache' exists for backwards compatibility, and is not used.
-        '''
+        """
         raise NotImplementedError
 
     def hasnode(self, classname, nodeid):
-        '''Determine if the database has a given node.
-        '''
+        """Determine if the database has a given node.
+        """
         raise NotImplementedError
 
     def countnodes(self, classname):
-        '''Count the number of nodes that exist for a particular Class.
-        '''
+        """Count the number of nodes that exist for a particular Class.
+        """
         raise NotImplementedError
 
     def storefile(self, classname, nodeid, property, content):
-        '''Store the content of the file in the database.
+        """Store the content of the file in the database.
 
            The property may be None, in which case the filename does not
            indicate which property is being saved.
-        '''
+        """
         raise NotImplementedError
 
     def getfile(self, classname, nodeid, property):
-        '''Get the content of the file in the database.
-        '''
+        """Get the content of the file in the database.
+        """
         raise NotImplementedError
 
     def addjournal(self, classname, nodeid, action, params):
-        ''' Journal the Action
+        """ Journal the Action
         'action' may be:
 
             'create' or 'set' -- 'params' is a dictionary of property values
             'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
             'retire' -- 'params' is None
-        '''
+        """
         raise NotImplementedError
 
     def getjournal(self, classname, nodeid):
-        ''' get the journal for id
-        '''
+        """ get the journal for id
+        """
         raise NotImplementedError
 
     def pack(self, pack_before):
-        ''' pack the database
-        '''
+        """ pack the database
+        """
         raise NotImplementedError
 
     def commit(self):
-        ''' Commit the current transactions.
+        """ Commit the current transactions.
 
         Save all data changed since the database was opened or since the
         last commit() or rollback().
@@ -742,15 +741,15 @@
         database. We don't care if there's a concurrency issue there.
 
         The only backend this seems to affect is postgres.
-        '''
+        """
         raise NotImplementedError
 
     def rollback(self):
-        ''' Reverse all actions from the current transaction.
+        """ Reverse all actions from the current transaction.
 
         Undo all the changes made since the database was opened or the last
         commit() or rollback() was performed.
-        '''
+        """
         raise NotImplementedError
 
     def close(self):
@@ -798,8 +797,8 @@
         self.reactors = dict([(a, PrioList()) for a in actions])
 
     def __repr__(self):
-        '''Slightly more useful representation
-        '''
+        """Slightly more useful representation
+        """
         return '<hyperdb.Class "%s">'%self.classname
 
     # Editing nodes:
@@ -837,18 +836,18 @@
 
     # not in spec
     def getnode(self, nodeid):
-        ''' Return a convenience wrapper for the node.
+        """ Return a convenience wrapper for the node.
 
         'nodeid' must be the id of an existing node of this class or an
         IndexError is raised.
 
         'cache' exists for backwards compatibility, and is not used.
-        '''
+        """
         return Node(self, nodeid)
 
     def getnodeids(self, retired=None):
-        '''Retrieve all the ids of the nodes for a particular Class.
-        '''
+        """Retrieve all the ids of the nodes for a particular Class.
+        """
         raise NotImplementedError
 
     def set(self, nodeid, **propvalues):
@@ -883,15 +882,15 @@
         raise NotImplementedError
 
     def restore(self, nodeid):
-        '''Restpre a retired node.
+        """Restpre a retired node.
 
         Make node available for all operations like it was before retirement.
-        '''
+        """
         raise NotImplementedError
 
     def is_retired(self, nodeid):
-        '''Return true if the node is rerired
-        '''
+        """Return true if the node is rerired
+        """
         raise NotImplementedError
 
     def destroy(self, nodeid):
@@ -932,8 +931,8 @@
 
     # Locating nodes:
     def hasnode(self, nodeid):
-        '''Determine if the given nodeid actually exists
-        '''
+        """Determine if the given nodeid actually exists
+        """
         raise NotImplementedError
 
     def setkey(self, propname):
@@ -1230,11 +1229,11 @@
 
 
 class HyperdbValueError(ValueError):
-    ''' Error converting a raw value into a Hyperdb value '''
+    """ Error converting a raw value into a Hyperdb value """
     pass
 
 def convertLinkValue(db, propname, prop, value, idre=re.compile('^\d+$')):
-    ''' Convert the link value (may be id or key value) to an id value. '''
+    """ Convert the link value (may be id or key value) to an id value. """
     linkcl = db.classes[prop.classname]
     if not idre.match(value):
         if linkcl.getkey():
@@ -1259,14 +1258,14 @@
     return text.replace('\r', '\n')
 
 def rawToHyperdb(db, klass, itemid, propname, value, **kw):
-    ''' Convert the raw (user-input) value to a hyperdb-storable value. The
+    """ Convert the raw (user-input) value to a hyperdb-storable value. The
         value is for the "propname" property on itemid (may be None for a
         new item) of "klass" in "db".
 
         The value is usually a string, but in the case of multilink inputs
         it may be either a list of strings or a string with comma-separated
         values.
-    '''
+    """
     properties = klass.getprops()
 
     # ensure it's a valid property name
@@ -1288,21 +1287,21 @@
     return value
 
 class FileClass:
-    ''' A class that requires the "content" property and stores it on
+    """ A class that requires the "content" property and stores it on
         disk.
-    '''
+    """
     default_mime_type = 'text/plain'
 
     def __init__(self, db, classname, **properties):
-        '''The newly-created class automatically includes the "content"
+        """The newly-created class automatically includes the "content"
         property.
-        '''
+        """
         if not properties.has_key('content'):
             properties['content'] = String(indexme='yes')
 
     def export_propnames(self):
-        ''' Don't export the "content" property
-        '''
+        """ Don't export the "content" property
+        """
         propnames = self.getprops().keys()
         propnames.remove('content')
         propnames.sort()
@@ -1313,8 +1312,8 @@
         return os.path.join(dirname, self.classname+'-files', subdir_filename)
 
     def export_files(self, dirname, nodeid):
-        ''' Export the "content" property as a file, not csv column
-        '''
+        """ Export the "content" property as a file, not csv column
+        """
         source = self.db.filename(self.classname, nodeid)
 
         dest = self.exportFilename(dirname, nodeid)
@@ -1322,8 +1321,8 @@
         shutil.copyfile(source, dest)
 
     def import_files(self, dirname, nodeid):
-        ''' Import the "content" property as a file
-        '''
+        """ Import the "content" property as a file
+        """
         source = self.exportFilename(dirname, nodeid)
 
         dest = self.db.filename(self.classname, nodeid, create=1)
@@ -1341,8 +1340,8 @@
                 self.get(nodeid, 'content'), mime_type)
 
 class Node:
-    ''' A convenience wrapper for the given node
-    '''
+    """ A convenience wrapper for the given node
+    """
     def __init__(self, cl, nodeid, cache=1):
         self.__dict__['cl'] = cl
         self.__dict__['nodeid'] = nodeid
@@ -1392,8 +1391,8 @@
 
 
 def Choice(name, db, *options):
-    '''Quick helper to create a simple class with choices
-    '''
+    """Quick helper to create a simple class with choices
+    """
     cl = Class(db, name, name=String(), order=String())
     for i in range(len(options)):
         cl.create(name=options[i], order=i)

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