Package data :: Module prototype
[hide private]
[frames] | no frames]

Source Code for Module data.prototype

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2007-2008 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Module docstring. 
24  """Module containing the Prototype base class for the molecule-residue-spin containers.""" 
25   
26   
27  # Python module imports. 
28  from copy import deepcopy 
29  from re import search 
30   
31   
32 -class Prototype(object):
33 """Base class implementing the prototype design pattern.""" 34
35 - def __deepcopy__(self, memo):
36 """Replacement deepcopy method.""" 37 38 # Make a new object. 39 new_obj = self.__class__.__new__(self.__class__) 40 41 # Loop over all objects in self and make deepcopies of them. 42 for name in dir(self): 43 # Skip all names begining with '_'. 44 if search('^_', name): 45 continue 46 47 # Skip the class methods. 48 if name in list(self.__class__.__dict__.keys()): 49 continue 50 51 # Get the object. 52 value = getattr(self, name) 53 54 # Replace the object with a deepcopy of it. 55 setattr(new_obj, name, deepcopy(value, memo)) 56 57 # Return the new object. 58 return new_obj
59 60
61 - def __clone__(self):
62 """Prototype method which returns a deepcopy of the object.""" 63 64 # Make a new object. 65 return deepcopy(self)
66