From: richard Date: Tue, 9 Oct 2001 23:58:10 +0000 (+0000) Subject: Moved the data stringification up into the hyperdb.Class class' get, set X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7ef36b5a488d7b08043740b1e48420151ac815c9;p=roundup.git Moved the data stringification up into the hyperdb.Class class' get, set and create methods. This means that the data is also stringified for the journal call, and removes duplication of code from the backends. The backend code now only sees strings. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@283 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index a7345cd..0dc2f1d 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.9 2001-10-09 07:25:59 richard Exp $ +#$Id: back_anydbm.py,v 1.10 2001-10-09 23:58:10 richard Exp $ import anydbm, os, marshal from roundup import hyperdb, date, password @@ -96,17 +96,6 @@ class Database(hyperdb.Database): ''' add the specified node to its class's db ''' db = self.getclassdb(classname, 'c') - - # convert the instance data to builtin types - properties = self.classes[classname].properties - for key in properties.keys(): - if isinstance(properties[key], hyperdb.Date): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Interval): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Password): - node[key] = str(node[key]) - # now save the marshalled data db[nodeid] = marshal.dumps(node) db.close() @@ -119,20 +108,6 @@ class Database(hyperdb.Database): if not db.has_key(nodeid): raise IndexError, nodeid res = marshal.loads(db[nodeid]) - - # convert the marshalled data to instances - properties = self.classes[classname].properties - for key in properties.keys(): - if key == self.RETIRED_FLAG: continue - if isinstance(properties[key], hyperdb.Date): - res[key] = date.Date(res[key]) - elif isinstance(properties[key], hyperdb.Interval): - res[key] = date.Interval(res[key]) - elif isinstance(properties[key], hyperdb.Password): - p = password.Password() - p.unpack(res[key]) - res[key] = p - if not cldb: db.close() return res @@ -226,6 +201,10 @@ class Database(hyperdb.Database): # #$Log: not supported by cvs2svn $ +#Revision 1.9 2001/10/09 07:25:59 richard +#Added the Password property type. See "pydoc roundup.password" for +#implementation details. Have updated some of the documentation too. +# #Revision 1.8 2001/09/29 13:27:00 richard #CGI interfaces now spit up a top-level index of all the instances they can #serve. diff --git a/roundup/backends/back_bsddb.py b/roundup/backends/back_bsddb.py index 3923fbd..cc4e924 100644 --- a/roundup/backends/back_bsddb.py +++ b/roundup/backends/back_bsddb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb.py,v 1.10 2001-10-09 07:25:59 richard Exp $ +#$Id: back_bsddb.py,v 1.11 2001-10-09 23:58:10 richard Exp $ import bsddb, os, marshal from roundup import hyperdb, date, password @@ -95,18 +95,6 @@ class Database(hyperdb.Database): ''' add the specified node to its class's db ''' db = self.getclassdb(classname, 'c') - - # convert the instance data to builtin types - properties = self.classes[classname].properties - for key in properties.keys(): - if isinstance(properties[key], hyperdb.Date): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Interval): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Password): - node[key] = str(node[key]) - - # now save the marshalled data db[nodeid] = marshal.dumps(node) db.close() setnode = addnode @@ -118,19 +106,6 @@ class Database(hyperdb.Database): if not db.has_key(nodeid): raise IndexError, nodeid res = marshal.loads(db[nodeid]) - - # convert the marshalled data to instances - properties = self.classes[classname].properties - for key in properties.keys(): - if isinstance(properties[key], hyperdb.Date): - res[key] = date.Date(res[key]) - elif isinstance(properties[key], hyperdb.Interval): - res[key] = date.Interval(res[key]) - elif isinstance(properties[key], hyperdb.Password): - p = password.Password() - p.unpack(res[key]) - res[key] = p - if not cldb: db.close() return res @@ -225,6 +200,10 @@ class Database(hyperdb.Database): # #$Log: not supported by cvs2svn $ +#Revision 1.10 2001/10/09 07:25:59 richard +#Added the Password property type. See "pydoc roundup.password" for +#implementation details. Have updated some of the documentation too. +# #Revision 1.9 2001/08/12 06:32:36 richard #using isinstance(blah, Foo) now instead of isFooType # diff --git a/roundup/backends/back_bsddb3.py b/roundup/backends/back_bsddb3.py index 1fd0eaa..e710e08 100644 --- a/roundup/backends/back_bsddb3.py +++ b/roundup/backends/back_bsddb3.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb3.py,v 1.8 2001-10-09 07:25:59 richard Exp $ +#$Id: back_bsddb3.py,v 1.9 2001-10-09 23:58:10 richard Exp $ import bsddb3, os, marshal from roundup import hyperdb, date, password @@ -95,17 +95,6 @@ class Database(hyperdb.Database): ''' add the specified node to its class's db ''' db = self.getclassdb(classname, 'c') - - # convert the instance data to builtin types - properties = self.classes[classname].properties - for key in properties.keys(): - if isinstance(properties[key], hyperdb.Date): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Interval): - node[key] = node[key].get_tuple() - elif isinstance(properties[key], hyperdb.Password): - node[key] = str(node[key]) - # now save the marshalled data db[nodeid] = marshal.dumps(node) db.close() @@ -118,19 +107,6 @@ class Database(hyperdb.Database): if not db.has_key(nodeid): raise IndexError, nodeid res = marshal.loads(db[nodeid]) - - # convert the marshalled data to instances - properties = self.classes[classname].properties - for key in properties.keys(): - if isinstance(properties[key], hyperdb.Date): - res[key] = date.Date(res[key]) - elif isinstance(properties[key], hyperdb.Interval): - res[key] = date.Interval(res[key]) - elif isinstance(properties[key], hyperdb.Password): - p = password.Password() - p.unpack(res[key]) - res[key] = p - if not cldb: db.close() return res @@ -225,6 +201,10 @@ class Database(hyperdb.Database): # #$Log: not supported by cvs2svn $ +#Revision 1.8 2001/10/09 07:25:59 richard +#Added the Password property type. See "pydoc roundup.password" for +#implementation details. Have updated some of the documentation too. +# #Revision 1.7 2001/08/12 06:32:36 richard #using isinstance(blah, Foo) now instead of isFooType # diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index 4a96b7b..50132c9 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: hyperdb.py,v 1.22 2001-10-09 07:25:59 richard Exp $ +# $Id: hyperdb.py,v 1.23 2001-10-09 23:58:10 richard Exp $ # standard python modules import cPickle, re, string @@ -206,6 +206,7 @@ class Class: if not isinstance(value, date.Interval): raise TypeError, 'new property "%s" not an Interval'%key + # make sure there's data where there needs to be for key, prop in self.properties.items(): if propvalues.has_key(key): continue @@ -216,6 +217,15 @@ class Class: else: propvalues[key] = None + # convert all data to strings + for key, prop in self.properties.items(): + if isinstance(prop, Date): + propvalues[key] = propvalues[key].get_tuple() + elif isinstance(prop, Interval): + propvalues[key] = propvalues[key].get_tuple() + elif isinstance(prop, Password): + propvalues[key] = str(propvalues[key]) + # done self.db.addnode(self.classname, newid, propvalues) self.db.addjournal(self.classname, newid, 'create', propvalues) @@ -229,6 +239,18 @@ class Class: of this class or a KeyError is raised. """ d = self.db.getnode(self.classname, nodeid) + + # convert the marshalled data to instances + for key, prop in self.properties.items(): + if isinstance(prop, Date): + d[key] = date.Date(d[key]) + elif isinstance(prop, Interval): + d[key] = date.Interval(d[key]) + elif isinstance(prop, Password): + p = password.Password() + p.unpack(d[key]) + d[key] = p + if propname == 'id': return nodeid if not d.has_key(propname) and default is not _marker: @@ -359,14 +381,17 @@ class Class: elif isinstance(prop, Password): if not isinstance(value, password.Password): raise TypeError, 'new property "%s" not a Password'% key + propvalues[key] = value = str(value) elif isinstance(prop, Date): if not isinstance(value, date.Date): raise TypeError, 'new property "%s" not a Date'% key + propvalues[key] = value = value.get_tuple() elif isinstance(prop, Interval): if not isinstance(value, date.Interval): raise TypeError, 'new property "%s" not an Interval'% key + propvalues[key] = value = value.get_tuple() node[key] = value @@ -814,6 +839,10 @@ def Choice(name, *options): # # $Log: not supported by cvs2svn $ +# Revision 1.22 2001/10/09 07:25:59 richard +# Added the Password property type. See "pydoc roundup.password" for +# implementation details. Have updated some of the documentation too. +# # Revision 1.21 2001/10/05 02:23:24 richard # . roundup-admin create now prompts for property info if none is supplied # on the command-line. diff --git a/roundup/password.py b/roundup/password.py index cc76c31..335a7a8 100644 --- a/roundup/password.py +++ b/roundup/password.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: password.py,v 1.1 2001-10-09 07:25:59 richard Exp $ +# $Id: password.py,v 1.2 2001-10-09 23:58:10 richard Exp $ import sha, re @@ -75,7 +75,7 @@ class Password: self.password = m.group(2) else: # currently plaintext - encrypt - self.password = encodePassword(plaintext, self.default_scheme) + self.password = encodePassword(encrypted, self.default_scheme) self.scheme = self.default_scheme def setPassword(self, plaintext): @@ -106,6 +106,10 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.1 2001/10/09 07:25:59 richard +# Added the Password property type. See "pydoc roundup.password" for +# implementation details. Have updated some of the documentation too. +# # # # vim: set filetype=python ts=4 sw=4 et si