Author: bugman Date: Tue Oct 2 14:25:52 2012 New Revision: 17665 URL: http://svn.gna.org/viewcvs/relax?rev=17665&view=rev Log: Better support for both Python 2 and 3 in the relax data store. The 2to3 script was used on all of the files in the data package. Modified: trunk/data/align_tensor.py trunk/data/data_classes.py trunk/data/diff_tensor.py trunk/data/relax_xml.py Modified: trunk/data/align_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/data/align_tensor.py?rev=17665&r1=17664&r2=17665&view=diff ============================================================================== --- trunk/data/align_tensor.py (original) +++ trunk/data/align_tensor.py Tue Oct 2 14:25:52 2012 @@ -26,6 +26,7 @@ from numpy.linalg import det, eig, eigvals # relax module imports. +from compat import py_version from data.data_classes import Element from data.relax_xml import fill_object_contents, xml_to_object from float import nan @@ -998,7 +999,7 @@ tensor_list_element.setAttribute('desc', 'Alignment tensor list') # Add all simple python objects within the PipeContainer to the pipe element. - fill_object_contents(doc, tensor_list_element, object=self, blacklist=list(self.__class__.__dict__.keys() + list.__dict__.keys())) + fill_object_contents(doc, tensor_list_element, object=self, blacklist=list(list(self.__class__.__dict__.keys()) + list(list.__dict__.keys()))) # Loop over the tensors. for i in range(len(self)): @@ -1128,14 +1129,26 @@ target_obj.append_untouchable_item(fn(*deps)) - def __update_sim_set(self, param_name, index): + def __update_sim_set(self, param_name, slice_obj): """Update the Monte Carlo simulation data lists when a simulation value is set. @param param_name: The MC sim parameter name which is being set. @type param_name: str - @param index: The index of the Monte Carlo simulation which was set. - @type index: int + @param slice_obj: For Python 2, the index of the Monte Carlo simulation which was set. Or for Python 3, a slice object. + @type slice_obj: int or slice object """ + + # Python 3 support. + if py_version == 3: + if slice_obj.start != slice_obj.stop: + raise RelaxError("The slice object %s cannot be handled." % slice_obj) + + # The index of the object. + index = slice_obj.start + + # Python 2. + else: + index = slice_obj # Loop over the targets. for target, update_if_set, depends in dependency_generator(): @@ -1181,7 +1194,7 @@ target_obj = getattr(self, target+'_sim') # Calculate and set the value. - target_obj.set_untouchable_item(index, fn(*deps)) + target_obj.set_untouchable_item(slice_obj, fn(*deps)) def __update_object(self, param_name, target, update_if_set, depends, category): @@ -1304,14 +1317,14 @@ self.align_element = align_element - def __setitem__(self, index, value): + def __setitem__(self, slice_obj, value): """Set the value.""" # Set the value. - list.__setitem__(self, index, value) + list.__setitem__(self, slice_obj, value) # Then update the other lists. - self.align_element._AlignTensorData__update_sim_set(self.param_name, index) + self.align_element._AlignTensorData__update_sim_set(self.param_name, slice_obj) def append(self, value): @@ -1331,8 +1344,9 @@ self[len(self):len(self)] = [value] - def set_untouchable_item(self, index, value): + def set_untouchable_item(self, slice_obj, value): """Set the value for an untouchable MC data structure.""" # Set the value. - list.__setitem__(self, index, value) + print(slice_obj) + list.__setitem__(self, slice_obj, value) Modified: trunk/data/data_classes.py URL: http://svn.gna.org/viewcvs/relax/trunk/data/data_classes.py?rev=17665&r1=17664&r2=17665&view=diff ============================================================================== --- trunk/data/data_classes.py (original) +++ trunk/data/data_classes.py Tue Oct 2 14:25:52 2012 @@ -137,7 +137,7 @@ cont_element.setAttribute('desc', self.desc) # Blacklisted objects. - blacklist = ['name', 'desc', 'blacklist'] + list(Element.__dict__.keys() + self.__class__.__dict__.keys() + object.__dict__.keys()) + blacklist = ['name', 'desc', 'blacklist'] + list(list(Element.__dict__.keys()) + list(self.__class__.__dict__.keys()) + list(object.__dict__.keys())) # Store and blacklist the objects which have to_xml() methods. to_xml_list = [] @@ -225,7 +225,7 @@ list_element.setAttribute('desc', self.list_desc) # Blacklisted objects. - blacklist = ['list_name', 'list_desc', 'element_name', 'element_desc', 'blacklist'] + list(self.__dict__.keys() + RelaxListType.__dict__.keys() + self.__class__.__dict__.keys() + list.__dict__.keys() + list.__dict__.keys()) + blacklist = ['list_name', 'list_desc', 'element_name', 'element_desc', 'blacklist'] + list(list(self.__dict__.keys()) + list(RelaxListType.__dict__.keys()) + list(self.__class__.__dict__.keys()) + list(list.__dict__.keys()) + list(list.__dict__.keys())) # Add all simple python objects within the list to the list element. fill_object_contents(doc, list_element, object=self, blacklist=blacklist) Modified: trunk/data/diff_tensor.py URL: http://svn.gna.org/viewcvs/relax/trunk/data/diff_tensor.py?rev=17665&r1=17664&r2=17665&view=diff ============================================================================== --- trunk/data/diff_tensor.py (original) +++ trunk/data/diff_tensor.py Tue Oct 2 14:25:52 2012 @@ -26,6 +26,7 @@ from numpy import array, float64, dot, identity, transpose, zeros # relax module imports. +from compat import py_version from data.data_classes import Element from data.relax_xml import fill_object_contents, xml_to_object from maths_fns.coord_transform import spherical_to_cartesian @@ -734,14 +735,26 @@ target_obj.append_untouchable_item(fn(*deps)) - def __update_sim_set(self, param_name, index): + def __update_sim_set(self, param_name, slice_obj): """Update the Monte Carlo simulation data lists when a simulation value is set. @param param_name: The MC sim parameter name which is being set. @type param_name: str - @param index: The index of the Monte Carlo simulation which was set. - @type index: int + @param slice_obj: For Python 2, the index of the Monte Carlo simulation which was set. Or for Python 3, a slice object. + @type slice_obj: int or slice object """ + + # Python 3 support. + if py_version == 3: + if slice_obj.start != slice_obj.stop: + raise RelaxError("The slice object %s cannot be handled." % slice_obj) + + # The index of the object. + index = slice_obj.start + + # Python 2. + else: + index = slice_obj # Loop over the targets. for target, update_if_set, depends in dependency_generator(self.type): @@ -794,7 +807,7 @@ # Calculate and set the value. if not skip: - target_obj.set_untouchable_item(index, fn(*deps)) + target_obj.set_untouchable_item(slice_obj, fn(*deps)) def __update_object(self, param_name, target, update_if_set, depends, category): @@ -1033,14 +1046,14 @@ self.append(None) - def __setitem__(self, index, value): + def __setitem__(self, slice_obj, value): """Set the value.""" # Set the value. - list.__setitem__(self, index, value) + list.__setitem__(self, slice_obj, value) # Then update the other lists. - self.diff_element._DiffTensorData__update_sim_set(self.param_name, index) + self.diff_element._DiffTensorData__update_sim_set(self.param_name, slice_obj) def append(self, value): @@ -1060,8 +1073,9 @@ self[len(self):len(self)] = [value] - def set_untouchable_item(self, index, value): + def set_untouchable_item(self, slice_obj, value): """Set the value for an untouchable MC data structure.""" # Set the value. - list.__setitem__(self, index, value) + print(slice_obj) + list.__setitem__(self, slice_obj, value) Modified: trunk/data/relax_xml.py URL: http://svn.gna.org/viewcvs/relax/trunk/data/relax_xml.py?rev=17665&r1=17664&r2=17665&view=diff ============================================================================== --- trunk/data/relax_xml.py (original) +++ trunk/data/relax_xml.py Tue Oct 2 14:25:52 2012 @@ -170,7 +170,7 @@ # The converted dict. ieee_obj = {} conv = False - for key in value.keys(): + for key in list(value.keys()): if arg_check.check_float(value[key]): ieee_obj[key] = floatAsByteArray(value[key]) conv = True