Author: bugman Date: Tue Mar 13 08:49:52 2007 New Revision: 3171 URL: http://svn.gna.org/viewcvs/relax?rev=3171&view=rev Log: Bug fix for the prototype copying. These changes cause the 'test_copy' and 'test_copy_current' unit tests of 'test_pipe.py' to pass. The prototype '__copy__()' method has been renamed to '__clone__()' as '__copy__()' is reserved as a replacement method for the 'copy' method of the 'copy' module. As the 'deepcopy' method was not copying all of the objects of the pipe container correctly, the '__deepcopy__() replacement method has been added to the prototype base class. All subclassing of 'ListType' and 'DictType' have been replaced by 'list' and 'dict'. Modified: 1.3/data/__init__.py 1.3/data/mol_res_spin.py 1.3/data/prototype.py 1.3/generic_fns/pipes.py Modified: 1.3/data/__init__.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/__init__.py?rev=3171&r1=3170&r2=3171&view=diff ============================================================================== --- 1.3/data/__init__.py (original) +++ 1.3/data/__init__.py Tue Mar 13 08:49:52 2007 @@ -22,7 +22,6 @@ # Python module imports. from re import match -from types import DictType # relax module imports. from pipe_container import PipeContainer @@ -35,7 +34,7 @@ 'main' ] -class Data(DictType): +class Data(dict): """The relax data storage object.""" # Singleton initialisation, the reference to the single instance of this class. @@ -55,7 +54,7 @@ # Create a new instance if none exists. if self.__instance is None: - self.__instance = DictType.__new__(self, *args, **kargs) + self.__instance = dict.__new__(self, *args, **kargs) # Return the class instance. return self.__instance @@ -85,7 +84,7 @@ text = text + "\n" text = text + "Objects:\n" for name in dir(self): - if match("^_", name) or name in DictType.__dict__: + if match("^_", name) or name in dict.__dict__: continue text = text + " %s: %s\n" % (name, `getattr(self, name)`) @@ -94,10 +93,10 @@ text = text + "Methods:\n" text = text + " __reset__, Reset the relax data storage object back to its initial state\n" - # DictType methods. + # dict methods. text = text + "\n" text = text + "Inherited dictionary methods:\n" - for name in dir(DictType): + for name in dir(dict): if match("^_", name): continue text = text + " %s\n" % name Modified: 1.3/data/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/mol_res_spin.py?rev=3171&r1=3170&r2=3171&view=diff ============================================================================== --- 1.3/data/mol_res_spin.py (original) +++ 1.3/data/mol_res_spin.py Tue Mar 13 08:49:52 2007 @@ -23,7 +23,6 @@ # Python module imports. from copy import deepcopy from re import match -from types import DictType, ListType # relax module imports. from prototype import Prototype @@ -76,7 +75,7 @@ return text -class SpinList(ListType): +class SpinList(list): """List type data container for spin system specific data.""" def __init__(self): @@ -157,7 +156,7 @@ return text -class ResidueList(ListType): +class ResidueList(list): """List type data container for residue specific data.""" def __init__(self): @@ -237,7 +236,7 @@ return text -class MoleculeList(ListType): +class MoleculeList(list): """List type data container for the molecule specific data.""" def __init__(self): Modified: 1.3/data/prototype.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/prototype.py?rev=3171&r1=3170&r2=3171&view=diff ============================================================================== --- 1.3/data/prototype.py (original) +++ 1.3/data/prototype.py Tue Mar 13 08:49:52 2007 @@ -22,15 +22,39 @@ # Python module imports. from copy import deepcopy +from re import search """The molecule-residue-spin containers.""" -class Prototype: +class Prototype(object): """Base class implementing the prototype design pattern.""" - def __copy__(self): + def __deepcopy__(self, memo): + """Replacement deepcopy method.""" + + # Make a new object. + new_obj = self.__class__.__new__(self.__class__) + + # Loop over all objects in self and make deepcopies of them. + for name in dir(self): + # Skip all names begining with '__'. + if search('^__', name): + continue + + # Get the object. + value = getattr(self, name) + + # Replace the object with a deepcopy of it. + setattr(new_obj, name, deepcopy(value, memo)) + + # Return the new object. + return new_obj + + + def __clone__(self): """Prototype method which returns a deepcopy of the object.""" + # Make a new object. return deepcopy(self) Modified: 1.3/generic_fns/pipes.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pipes.py?rev=3171&r1=3170&r2=3171&view=diff ============================================================================== --- 1.3/generic_fns/pipes.py (original) +++ 1.3/generic_fns/pipes.py Tue Mar 13 08:49:52 2007 @@ -55,7 +55,7 @@ pipe_from = relax_data_store.current_pipe # Copy the data. - relax_data_store[pipe_to] = relax_data_store[pipe_from].__copy__() + relax_data_store[pipe_to] = relax_data_store[pipe_from].__clone__() def create(pipe_name=None, pipe_type=None):