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

Source Code for Module data_store.prototype

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2007-2003 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program 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 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Module containing the Prototype base class for the molecule-residue-spin containers.""" 
24   
25   
26  # Python module imports. 
27  from copy import deepcopy 
28  from re import search 
29   
30   
31 -class Prototype(object):
32 """Base class implementing the prototype design pattern.""" 33
34 - def __deepcopy__(self, memo):
35 """Replacement deepcopy method.""" 36 37 # Make a new object. 38 new_obj = self.__class__.__new__(self.__class__) 39 40 # Loop over all objects in self and make deepcopies of them. 41 for name in dir(self): 42 # Skip all names begining with '__'. 43 if search('^__', name): 44 continue 45 46 # Skip the class methods. 47 if name in list(self.__class__.__dict__.keys()): 48 continue 49 50 # Get the object. 51 value = getattr(self, name) 52 53 # Replace the object with a deepcopy of it. 54 setattr(new_obj, name, deepcopy(value, memo)) 55 56 # Return the new object. 57 return new_obj
58 59
60 - def __clone__(self):
61 """Prototype method which returns a deepcopy of the object.""" 62 63 # Make a new object. 64 return deepcopy(self)
65